diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index ed31708..0000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,109 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/smartfox_info.xml b/.idea/smartfox_info.xml
deleted file mode 100644
index 1c2584f..0000000
--- a/.idea/smartfox_info.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/starter-jmacro.iml b/.idea/starter-jmacro.iml
deleted file mode 100644
index 78b2cc5..0000000
--- a/.idea/starter-jmacro.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index 2b63946..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/java/xyz/wbsite/jmacro/JMacro.java b/src/main/java/xyz/wbsite/jmacro/JMacro.java
index 9f54b38..84aaa74 100644
--- a/src/main/java/xyz/wbsite/jmacro/JMacro.java
+++ b/src/main/java/xyz/wbsite/jmacro/JMacro.java
@@ -115,6 +115,7 @@ public abstract class JMacro {
}
this.run = true;
this.task();
+ this.stop();
}
/**
diff --git a/src/main/java/xyz/wbsite/jmacro/JMainController.java b/src/main/java/xyz/wbsite/jmacro/JMainController.java
index 3a93297..6b335db 100644
--- a/src/main/java/xyz/wbsite/jmacro/JMainController.java
+++ b/src/main/java/xyz/wbsite/jmacro/JMainController.java
@@ -1,6 +1,7 @@
package xyz.wbsite.jmacro;
import cn.hutool.core.collection.BoundedPriorityQueue;
+import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;
import javafx.animation.KeyFrame;
@@ -11,6 +12,7 @@ import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
+import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
@@ -36,6 +38,10 @@ import java.util.concurrent.Semaphore;
* @since 1.8
*/
public class JMainController implements Initializable {
+ /**
+ * 单例对象
+ */
+ private static JMainController instance;
@FXML
private Button start;
@@ -44,6 +50,10 @@ public class JMainController implements Initializable {
@FXML
private ImageView set;
@FXML
+ private TextField interval;
+ @FXML
+ private TextField times;
+ @FXML
private Button capture;
@FXML
private ImageView preview;
@@ -55,10 +65,35 @@ public class JMainController implements Initializable {
private Semaphore semaphore = new Semaphore(1);
+
+ public static synchronized JMainController getInstance() {
+ return instance;
+ }
+
@Override
public void initialize(URL location, ResourceBundle resources) {
+ this.instance = this;
// 控件初始化
- installTip(set, "扩展配置");
+ int intervalValue = JProp.getInstance().getInt("interval", 60);
+ this.interval.setText(String.valueOf(intervalValue));
+ // 只允许输入数字
+ this.interval.textProperty().addListener((observable, oldValue, newValue) -> {
+ if (!newValue.matches("\\d*")) {
+ this.interval.setText(newValue.replaceAll("\\D", ""));
+ }
+ JProp.getInstance().setInt("interval", Convert.toInt(this.times.getText()));
+ });
+ int timesValue = JProp.getInstance().getInt("times", 3);
+ this.times.setText(String.valueOf(timesValue));
+ this.times.textProperty().addListener((observable, oldValue, newValue) -> {
+ if (!newValue.matches("\\d*")) {
+ this.times.setText(newValue.replaceAll("\\D", ""));
+ }
+ JProp.getInstance().setInt("times", Convert.toInt(this.times.getText()));
+ });
+ installTip(this.set, "扩展配置");
+ installTip(this.interval, "两次脚本执行的间隔时间(秒)");
+ installTip(this.times, "脚本执行的总次数,0代表无限循环");
}
/**
diff --git a/src/main/java/xyz/wbsite/jmacro/JMainService.java b/src/main/java/xyz/wbsite/jmacro/JMainService.java
index 0383699..6fa1e52 100644
--- a/src/main/java/xyz/wbsite/jmacro/JMainService.java
+++ b/src/main/java/xyz/wbsite/jmacro/JMainService.java
@@ -115,20 +115,30 @@ public class JMainService {
Logger.info("脚本未设置");
return;
}
- while (run && !Thread.currentThread().isInterrupted()) {
+
+ int intervalValue = JProp.getInstance().getInt("interval", 60);
+ int timesValue = JProp.getInstance().getInt("times", 3);
+ for (int i = 0; i < timesValue; i++) {
+ Logger.info("第{}/{}次正在执行", i + 1, timesValue);
try {
- ThreadUtil.sleep(1000);
macro.start();
+ if (i >= timesValue - 1) {
+ Logger.info("第{}/{}次执行结束", i + 1, timesValue);
+ } else {
+ Logger.info("第{}/{}次执行结束,休眠{}秒", i + 1, timesValue, intervalValue);
+ ThreadUtil.sleep(intervalValue * 1000L);
+ }
} catch (Exception e) {
- if ((e instanceof InterruptedException) || e.getMessage().contains(InterruptedException.class.getSimpleName())) {
+ if (e.getMessage().contains(InterruptedException.class.getSimpleName())) {
// 服务停止
} else {
- e.printStackTrace();
Logger.info("异常中断");
}
}
}
- Logger.info("服务停止,守护线程已退出");
+
+ JMainController.getInstance().onStop();
+ Logger.info("执行结束,守护线程已退出");
}
}
}
diff --git a/src/main/java/xyz/wbsite/jtask/TaskImpl.java b/src/main/java/xyz/wbsite/jtask/TaskImpl.java
index d376b67..ff38e7d 100644
--- a/src/main/java/xyz/wbsite/jtask/TaskImpl.java
+++ b/src/main/java/xyz/wbsite/jtask/TaskImpl.java
@@ -41,7 +41,7 @@ public class TaskImpl extends JMacro {
Logger.info("双击我的电脑");
mouseLeftDoubleClick(launch);
Logger.info("等待程序启动中,请稍等...");
- delay(5 * 1000);
+ delay(3 * 1000);
ViewRect windows = findLegend("我的电脑窗口", 0.9);
if (windows == null) {
@@ -52,8 +52,8 @@ public class TaskImpl extends JMacro {
Logger.info("移动鼠标");
mouseMove(windows.getCenter().offsetX(100), true);
- Logger.info("等待3秒后自动关闭");
- delay(3 * 1000);
+ Logger.info("等待1秒后自动关闭");
+ delay(1000);
mouseLeftClick(windows.getCenter().offsetX(100));
Logger.info("结束任务");
diff --git a/src/main/resources/main.fxml b/src/main/resources/main.fxml
index e1e312f..7064499 100644
--- a/src/main/resources/main.fxml
+++ b/src/main/resources/main.fxml
@@ -59,14 +59,14 @@
-
+
-
+