上传备份

master
王兵 1 week ago
parent 2557236c37
commit 9b0d41fb4d

@ -9,6 +9,7 @@ import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
@ -84,6 +85,32 @@ public class JMainController implements Initializable {
public void initialize(URL location, ResourceBundle resources) {
JMainController.instance = this;
// 控件初始化
String mode = JProp.getInstance().getString("mode", "loop");
ObservableList<Toggle> toggles = runMode.getToggles();
for (Toggle tog : toggles) {
RadioButton radioButton = (RadioButton) tog;
if (radioButton.getUserData().equals(mode)) {
radioButton.setSelected(true);
}
}
Toggle selectedToggle = runMode.getSelectedToggle();
if (selectedToggle != null) {
String initialMode = ((RadioButton) selectedToggle).getUserData().toString();
// 同步设置组件显示状态(与监听器逻辑保持一致)
if ("loop".equals(initialMode)) {
modeLoop.setVisible(true);
modeLoop.setManaged(true);
modeTiming.setVisible(false);
modeTiming.setManaged(false);
} else if ("timing".equals(initialMode)) {
modeLoop.setVisible(false);
modeLoop.setManaged(false);
modeTiming.setVisible(true);
modeTiming.setManaged(true);
}
}
runMode.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
@Override
public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {

@ -3,8 +3,6 @@ package xyz.wbsite.jmacro;
import xyz.wbsite.jmacro.util.Logger;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -39,8 +37,6 @@ public class JScheduler {
*/
private final Queue<ScheduledFuture<?>> tasksHolder = new ConcurrentLinkedQueue<>();
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
/**
*
*
@ -82,20 +78,44 @@ public class JScheduler {
* <p>
* "08:30:00"
*
* @param task
* @param time
* @param task
* @param timeArray
*/
public void schedule(Runnable task, List<String> time) {
if (time.isEmpty()) {
public void schedule(Runnable task, List<String> timeArray) {
if (timeArray.isEmpty()) {
return;
}
// 转换为数字集合(秒级精度)
ConcurrentSkipListSet<Integer> timeSet = new ConcurrentSkipListSet<>();
Runnable trigger = () -> {
for (String string : time) {
for (String time : timeArray) {
// time 格式兼容处理
String trimmedTime = time.trim();
String[] timeParts = trimmedTime.split(":");
// 验证格式是否合法必须是2或3部分
if (timeParts.length < 2 || timeParts.length > 3) {
Logger.error("无效时间格式: " + time + "需符合HH:mm:ss、H:mm:ss、HH:mm、H:mm或H:m格式");
continue;
}
// 解析时、分、秒秒默认为0
int hours = Integer.parseInt(timeParts[0]);
int minutes = Integer.parseInt(timeParts[1]);
int seconds = (timeParts.length == 3) ? Integer.parseInt(timeParts[2]) : 0;
// 验证时间数值范围
if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59) {
Logger.error("时间数值超出范围: " + time + ",时(0-23)、分(0-59)、秒(0-59)");
continue;
}
// 格式化为标准HH:mm:ss自动补零
String format = String.format("%02d:%02d:%02d", hours, minutes, seconds);
int nowSeconds = LocalTime.now().toSecondOfDay();
int secondOfDay = LocalTime.parse(string, TIME_FORMATTER).toSecondOfDay();
int secondOfDay = LocalTime.parse(format).toSecondOfDay();
if (secondOfDay < nowSeconds) {
continue;
}
@ -148,29 +168,6 @@ public class JScheduler {
executor.shutdown();
}
/**
*
*
* @param timePoints
* @return
*/
private List<LocalTime> parseTimePoints(String timePoints) {
List<LocalTime> result = new ArrayList<>();
if (timePoints == null || timePoints.trim().isEmpty()) {
return result;
}
String[] parts = timePoints.split(",");
for (String part : parts) {
try {
result.add(LocalTime.parse(part.trim(), TIME_FORMATTER));
} catch (Exception e) {
System.err.println("无效的时间格式: " + part.trim());
}
}
return result;
}
/**
*
*/

@ -36,7 +36,8 @@
<Insets top="10.0"/>
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT">
<HBox alignment="CENTER_LEFT" prefHeight="25.0" prefWidth="200.0">
<children>
<Label contentDisplay="CENTER" prefHeight="25.0" text="执行模式"/>
@ -54,6 +55,10 @@
</HBox.margin>
</RadioButton>
</children>
<VBox.margin>
<Insets top="3.0" bottom="3.0"/>
</VBox.margin>
</HBox>
<HBox fx:id="modeLoop" alignment="CENTER_LEFT" prefHeight="25.0" prefWidth="200.0">
@ -73,6 +78,10 @@
</TextField>
<Label text="次"/>
</children>
<VBox.margin>
<Insets top="3.0" bottom="3.0"/>
</VBox.margin>
</HBox>
<HBox fx:id="modeTiming" visible="false" managed="false" alignment="CENTER_LEFT" prefHeight="25.0"
@ -87,6 +96,10 @@
</TextField>
<Label text="执行"/>
</children>
<VBox.margin>
<Insets top="3.0" bottom="3.0"/>
</VBox.margin>
</HBox>
<Label contentDisplay="CENTER" prefHeight="25.0" text="辅助工具"/>

Loading…
Cancel
Save

Powered by TurnKey Linux.