上传备份

master
王兵 1 month ago
parent 1f97b4ab5b
commit cbe61ddcc9

@ -49,8 +49,8 @@ public class JMainApplication extends Application {
stage.show();
JMainApplication.primaryStage = stage;
JIntellitype.getInstance().registerHotKey(F1_SHORTCUT, 0, KeyEvent.VK_F1);
JIntellitype.getInstance().registerHotKey(F2_SHORTCUT, 0, KeyEvent.VK_F2);
JIntellitype.getInstance().registerHotKey(F1_SHORTCUT, JIntellitype.MOD_CONTROL, KeyEvent.VK_F1);
JIntellitype.getInstance().registerHotKey(F2_SHORTCUT, JIntellitype.MOD_CONTROL, KeyEvent.VK_F2);
JIntellitype.getInstance().addHotKeyListener(identifier -> {
switch (identifier) {
case F1_SHORTCUT:

@ -24,6 +24,7 @@ import xyz.wbsite.jmacro.tool.PickLegend;
import xyz.wbsite.jmacro.tool.PickPoint;
import xyz.wbsite.jmacro.tool.PickRect;
import xyz.wbsite.jmacro.util.DialogUtil;
import xyz.wbsite.jmacro.util.Logger;
import java.awt.*;
import java.net.URL;
@ -54,8 +55,6 @@ public class JMainController implements Initializable {
@FXML
private TextField times;
@FXML
private Button capture;
@FXML
private ImageView preview;
@FXML
private TextArea console;
@ -65,14 +64,13 @@ public class JMainController implements Initializable {
private Semaphore semaphore = new Semaphore(1);
public static synchronized JMainController getInstance() {
return instance;
return JMainController.instance;
}
@Override
public void initialize(URL location, ResourceBundle resources) {
this.instance = this;
JMainController.instance = this;
// 控件初始化
int intervalValue = JProp.getInstance().getInt("interval", 60);
this.interval.setText(String.valueOf(intervalValue));
@ -169,9 +167,19 @@ public class JMainController implements Initializable {
*/
@FXML
public void onStart() {
boolean start = JMainService.start();
this.start.setDisable(start);
this.stop.setDisable(!start);
synchronized (JMainController.class) {
this.start.setDisable(true);
this.stop.setDisable(false);
Logger.info("启动服务");
if (!JMainService.getInstance().run) {
boolean start = JMainService.start();
if (!start) {
Logger.error("服务启动失败");
return;
}
Logger.info("服务启动成功");
}
}
}
/**
@ -179,10 +187,20 @@ public class JMainController implements Initializable {
*/
@FXML
public void onStop() {
boolean stop = JMainService.stop();
this.start.setDisable(!stop);
this.stop.setDisable(stop);
this.preview.setImage(null);
synchronized (JMainController.class) {
this.start.setDisable(false);
this.stop.setDisable(true);
Logger.info("停止服务");
if (JMainService.getInstance().run) {
boolean stop = JMainService.stop();
if (!stop) {
Logger.error("服务停止失败");
return;
}
Logger.info("服务停止成功");
this.preview.setImage(null);
}
}
}
/**

@ -60,11 +60,10 @@ public class JMainService {
}
public void createDaemon() {
Logger.info("初始化线程");
this.daemonThread = new DaemonThread();
Logger.info("初始化守护线程");
this.daemonThread.setDaemon(true);
// 启动守护线程
Logger.info("启动线程");
this.run = true;
this.daemonThread.start();
}
@ -82,7 +81,7 @@ public class JMainService {
// 启动服务
Logger.info("启动服务");
// 创建守护线程
// 创建线程
JMainService.getInstance().createDaemon();
return true;
}
@ -100,7 +99,7 @@ public class JMainService {
}
// 关闭守护线程
JMainService.getInstance().daemonThread.interrupt();
Logger.info("停止服务");
Logger.info("正在停止脚本");
return true;
}
@ -118,14 +117,15 @@ public class JMainService {
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);
int index = 0;
do {
Logger.info("第{}/{}次正在执行", index + 1, timesValue);
try {
macro.start();
if (i >= timesValue - 1) {
Logger.info("第{}/{}次执行结束", i + 1, timesValue);
if (index >= timesValue - 1) {
Logger.info("第{}/{}次执行结束", index, timesValue);
} else {
Logger.info("第{}/{}次执行结束,休眠{}秒", i + 1, timesValue, intervalValue);
Logger.info("第{}/{}次执行结束,休眠{}秒", index, timesValue, intervalValue);
ThreadUtil.sleep(intervalValue * 1000L);
}
} catch (Exception e) {
@ -135,7 +135,8 @@ public class JMainService {
Logger.info("异常中断");
}
}
}
index++;
} while (index < timesValue && run);
JMainController.getInstance().onStop();
Logger.info("执行结束,守护线程已退出");

@ -24,9 +24,9 @@
<HBox alignment="CENTER_LEFT" prefHeight="35.0" prefWidth="200.0">
<children>
<Button fx:id="start" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStart"
prefHeight="30.0" prefWidth="100.0" text="开始F1"/>
prefHeight="30.0" prefWidth="100.0" text="开始(Ctrl+F1)"/>
<Button fx:id="stop" disable="true" focusTraversable="false" mnemonicParsing="false"
onMouseClicked="#onStop" prefHeight="30.0" prefWidth="100.0" text="停止F2">
onMouseClicked="#onStop" prefHeight="30.0" prefWidth="100.0" text="停止(Ctrl+F2)">
<HBox.margin>
<Insets left="10.0"/>
</HBox.margin>
@ -128,18 +128,18 @@
<AnchorPane layoutX="262.0" layoutY="14.0" prefHeight="250.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="204.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label layoutY="4.0" prefHeight="40.0" prefWidth="60.0" text="日志输出" AnchorPane.leftAnchor="0.0"
<Label layoutY="4.0" prefHeight="30.0" prefWidth="60.0" text="控制台" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding>
<Insets left="10.0" right="10.0"/>
</padding>
</Label>
<Separator layoutX="-3.0" layoutY="39.0" opacity="0.5" prefWidth="200.0" AnchorPane.leftAnchor="1.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0"/>
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0"/>
<TextArea fx:id="console" editable="false" layoutX="1.0" layoutY="41.0" prefHeight="270.0"
style="-fx-background-color: transparent; -fx-focus-color: no; -fx-control-inner-background: transparent;-fx-text-fill: #444444;"
wrapText="true" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="45.0">
AnchorPane.topAnchor="35.0">
</TextArea>
</children>

Loading…
Cancel
Save

Powered by TurnKey Linux.