|
|
|
@ -7,15 +7,21 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import javafx.animation.KeyFrame;
|
|
|
|
|
import javafx.animation.Timeline;
|
|
|
|
|
import javafx.application.Platform;
|
|
|
|
|
import javafx.beans.value.ChangeListener;
|
|
|
|
|
import javafx.beans.value.ObservableValue;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
|
import javafx.scene.Node;
|
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
|
import javafx.scene.control.RadioButton;
|
|
|
|
|
import javafx.scene.control.TextArea;
|
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
|
import javafx.scene.control.Toggle;
|
|
|
|
|
import javafx.scene.control.ToggleGroup;
|
|
|
|
|
import javafx.scene.control.Tooltip;
|
|
|
|
|
import javafx.scene.image.Image;
|
|
|
|
|
import javafx.scene.image.ImageView;
|
|
|
|
|
import javafx.scene.layout.HBox;
|
|
|
|
|
import javafx.util.Duration;
|
|
|
|
|
import org.sikuli.script.Region;
|
|
|
|
|
import xyz.wbsite.jmacro.base.Legend;
|
|
|
|
@ -49,12 +55,18 @@ public class JMainController implements Initializable {
|
|
|
|
|
@FXML
|
|
|
|
|
private Button stop;
|
|
|
|
|
@FXML
|
|
|
|
|
private ImageView set;
|
|
|
|
|
private ToggleGroup runMode;
|
|
|
|
|
@FXML
|
|
|
|
|
private HBox modeLoop;
|
|
|
|
|
@FXML
|
|
|
|
|
private HBox modeTiming;
|
|
|
|
|
@FXML
|
|
|
|
|
private TextField interval;
|
|
|
|
|
@FXML
|
|
|
|
|
private TextField times;
|
|
|
|
|
@FXML
|
|
|
|
|
private TextField timing;
|
|
|
|
|
@FXML
|
|
|
|
|
private ImageView preview;
|
|
|
|
|
@FXML
|
|
|
|
|
private TextArea console;
|
|
|
|
@ -62,7 +74,7 @@ public class JMainController implements Initializable {
|
|
|
|
|
private final int MAX_LENGTH = 100;
|
|
|
|
|
private final BoundedPriorityQueue<String> logs = new BoundedPriorityQueue<>(MAX_LENGTH);
|
|
|
|
|
|
|
|
|
|
private Semaphore semaphore = new Semaphore(1);
|
|
|
|
|
private final Semaphore semaphore = new Semaphore(1);
|
|
|
|
|
|
|
|
|
|
public static synchronized JMainController getInstance() {
|
|
|
|
|
return JMainController.instance;
|
|
|
|
@ -71,6 +83,26 @@ public class JMainController implements Initializable {
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
|
|
|
JMainController.instance = this;
|
|
|
|
|
|
|
|
|
|
runMode.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
|
|
|
|
|
String mode = ((RadioButton) newValue).getUserData().toString();
|
|
|
|
|
if ("loop".equals(mode)) {
|
|
|
|
|
modeLoop.setVisible(true);
|
|
|
|
|
modeLoop.setManaged(true);
|
|
|
|
|
modeTiming.setVisible(false);
|
|
|
|
|
modeTiming.setManaged(false);
|
|
|
|
|
}
|
|
|
|
|
if ("timing".equals(mode)) {
|
|
|
|
|
modeLoop.setVisible(false);
|
|
|
|
|
modeLoop.setManaged(false);
|
|
|
|
|
modeTiming.setVisible(true);
|
|
|
|
|
modeTiming.setManaged(true);
|
|
|
|
|
}
|
|
|
|
|
JProp.getInstance().setString("mode", mode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 控件初始化
|
|
|
|
|
int intervalValue = JProp.getInstance().getInt("interval", 60);
|
|
|
|
|
this.interval.setText(String.valueOf(intervalValue));
|
|
|
|
@ -89,7 +121,60 @@ public class JMainController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
JProp.getInstance().setInt("times", Convert.toInt(this.times.getText()));
|
|
|
|
|
});
|
|
|
|
|
installTip(this.set, "扩展配置");
|
|
|
|
|
|
|
|
|
|
String timingValue = JProp.getInstance().getString("timing", "");
|
|
|
|
|
this.timing.setText(timingValue);
|
|
|
|
|
this.timing.textProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
|
boolean isValidFormat = true;
|
|
|
|
|
String errorMessage = "时间格式错误!支持的格式如:09:30:00,9:35:00,10:45,9:5,8:30";
|
|
|
|
|
|
|
|
|
|
// 空输入视为无效
|
|
|
|
|
if (StrUtil.isEmpty(newValue)) {
|
|
|
|
|
isValidFormat = false;
|
|
|
|
|
} else {
|
|
|
|
|
// 分割多个时间点并逐个验证
|
|
|
|
|
String[] timeParts = newValue.split(",");
|
|
|
|
|
for (String part : timeParts) {
|
|
|
|
|
String trimmedPart = part.trim();
|
|
|
|
|
// 单个时间点格式验证 (支持 HH:mm:ss、H:mm:ss、HH:mm、H:mm、H:m)
|
|
|
|
|
if (!trimmedPart.matches("^\\d{1,2}:\\d{1,2}(?::\\d{1,2})?$")) {
|
|
|
|
|
isValidFormat = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证时分秒数值范围
|
|
|
|
|
String[] hms = trimmedPart.split(":");
|
|
|
|
|
int hour = Convert.toInt(hms[0], -1);
|
|
|
|
|
int minute = Convert.toInt(hms[1], -1);
|
|
|
|
|
int second = 0; // 默认秒为0(当没有秒部分时)
|
|
|
|
|
|
|
|
|
|
// 处理带秒的格式
|
|
|
|
|
if (hms.length == 3) {
|
|
|
|
|
second = Convert.toInt(hms[2], -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证数值范围(小时0-23,分钟0-59,秒0-59)
|
|
|
|
|
if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
|
|
|
|
|
isValidFormat = false;
|
|
|
|
|
errorMessage = "时间数值错误!时(0-23)、分(0-59)、秒(0-59)";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置样式和提示
|
|
|
|
|
if (!isValidFormat) {
|
|
|
|
|
timing.setStyle("-fx-text-fill: #ff0000; -fx-border-color: #ff0000; -fx-border-width: 1px;");
|
|
|
|
|
Tooltip errorTooltip = new Tooltip(errorMessage);
|
|
|
|
|
errorTooltip.setStyle("-fx-background-color: #fff0f0; -fx-text-fill: #ff0000;");
|
|
|
|
|
Tooltip.install(timing, errorTooltip);
|
|
|
|
|
} else {
|
|
|
|
|
timing.setStyle("-fx-text-fill: #000000; -fx-border-color: transparent; -fx-border-width: 1px;");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存配置(修正原代码中的this.times.getText()错误)
|
|
|
|
|
JProp.getInstance().setString("timing", this.timing.getText());
|
|
|
|
|
});
|
|
|
|
|
installTip(this.interval, "两次脚本执行的间隔时间(秒)");
|
|
|
|
|
installTip(this.times, "脚本执行的总次数,0代表无限循环");
|
|
|
|
|
}
|
|
|
|
@ -170,6 +255,7 @@ public class JMainController implements Initializable {
|
|
|
|
|
synchronized (JMainController.class) {
|
|
|
|
|
this.start.setDisable(true);
|
|
|
|
|
this.stop.setDisable(false);
|
|
|
|
|
this.saveConfig();
|
|
|
|
|
Logger.info("启动服务");
|
|
|
|
|
if (!JMainService.getInstance().run) {
|
|
|
|
|
boolean start = JMainService.start();
|
|
|
|
@ -182,6 +268,17 @@ public class JMainController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存配置
|
|
|
|
|
*/
|
|
|
|
|
public void saveConfig() {
|
|
|
|
|
String string = this.runMode.selectedToggleProperty().getValue().getUserData().toString();
|
|
|
|
|
JProp.getInstance().setString("mode", string);
|
|
|
|
|
JProp.getInstance().setInt("times", Convert.toInt(this.times.getText()));
|
|
|
|
|
JProp.getInstance().setInt("interval", Convert.toInt(this.interval.getText()));
|
|
|
|
|
JProp.getInstance().setString("timing", this.timing.getText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 停止服务
|
|
|
|
|
*/
|
|
|
|
@ -199,6 +296,8 @@ public class JMainController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
Logger.info("服务停止成功");
|
|
|
|
|
this.preview.setImage(null);
|
|
|
|
|
} else {
|
|
|
|
|
Logger.info("服务未运行");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|