上传备份

master
王兵 1 month ago
parent 1f97b4ab5b
commit cbe61ddcc9

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

@ -24,6 +24,7 @@ import xyz.wbsite.jmacro.tool.PickLegend;
import xyz.wbsite.jmacro.tool.PickPoint; import xyz.wbsite.jmacro.tool.PickPoint;
import xyz.wbsite.jmacro.tool.PickRect; import xyz.wbsite.jmacro.tool.PickRect;
import xyz.wbsite.jmacro.util.DialogUtil; import xyz.wbsite.jmacro.util.DialogUtil;
import xyz.wbsite.jmacro.util.Logger;
import java.awt.*; import java.awt.*;
import java.net.URL; import java.net.URL;
@ -54,8 +55,6 @@ public class JMainController implements Initializable {
@FXML @FXML
private TextField times; private TextField times;
@FXML @FXML
private Button capture;
@FXML
private ImageView preview; private ImageView preview;
@FXML @FXML
private TextArea console; private TextArea console;
@ -65,14 +64,13 @@ public class JMainController implements Initializable {
private Semaphore semaphore = new Semaphore(1); private Semaphore semaphore = new Semaphore(1);
public static synchronized JMainController getInstance() { public static synchronized JMainController getInstance() {
return instance; return JMainController.instance;
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
this.instance = this; JMainController.instance = this;
// 控件初始化 // 控件初始化
int intervalValue = JProp.getInstance().getInt("interval", 60); int intervalValue = JProp.getInstance().getInt("interval", 60);
this.interval.setText(String.valueOf(intervalValue)); this.interval.setText(String.valueOf(intervalValue));
@ -169,9 +167,19 @@ public class JMainController implements Initializable {
*/ */
@FXML @FXML
public void onStart() { public void onStart() {
boolean start = JMainService.start(); synchronized (JMainController.class) {
this.start.setDisable(start); this.start.setDisable(true);
this.stop.setDisable(!start); 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 @FXML
public void onStop() { public void onStop() {
boolean stop = JMainService.stop(); synchronized (JMainController.class) {
this.start.setDisable(!stop); this.start.setDisable(false);
this.stop.setDisable(stop); this.stop.setDisable(true);
this.preview.setImage(null); 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() { public void createDaemon() {
Logger.info("初始化线程");
this.daemonThread = new DaemonThread(); this.daemonThread = new DaemonThread();
Logger.info("初始化守护线程");
this.daemonThread.setDaemon(true); this.daemonThread.setDaemon(true);
Logger.info("启动线程");
// 启动守护线程
this.run = true; this.run = true;
this.daemonThread.start(); this.daemonThread.start();
} }
@ -82,7 +81,7 @@ public class JMainService {
// 启动服务 // 启动服务
Logger.info("启动服务"); Logger.info("启动服务");
// 创建守护线程 // 创建线程
JMainService.getInstance().createDaemon(); JMainService.getInstance().createDaemon();
return true; return true;
} }
@ -100,7 +99,7 @@ public class JMainService {
} }
// 关闭守护线程 // 关闭守护线程
JMainService.getInstance().daemonThread.interrupt(); JMainService.getInstance().daemonThread.interrupt();
Logger.info("停止服务"); Logger.info("正在停止脚本");
return true; return true;
} }
@ -118,14 +117,15 @@ public class JMainService {
int intervalValue = JProp.getInstance().getInt("interval", 60); int intervalValue = JProp.getInstance().getInt("interval", 60);
int timesValue = JProp.getInstance().getInt("times", 3); int timesValue = JProp.getInstance().getInt("times", 3);
for (int i = 0; i < timesValue; i++) { int index = 0;
Logger.info("第{}/{}次正在执行", i + 1, timesValue); do {
Logger.info("第{}/{}次正在执行", index + 1, timesValue);
try { try {
macro.start(); macro.start();
if (i >= timesValue - 1) { if (index >= timesValue - 1) {
Logger.info("第{}/{}次执行结束", i + 1, timesValue); Logger.info("第{}/{}次执行结束", index, timesValue);
} else { } else {
Logger.info("第{}/{}次执行结束,休眠{}秒", i + 1, timesValue, intervalValue); Logger.info("第{}/{}次执行结束,休眠{}秒", index, timesValue, intervalValue);
ThreadUtil.sleep(intervalValue * 1000L); ThreadUtil.sleep(intervalValue * 1000L);
} }
} catch (Exception e) { } catch (Exception e) {
@ -135,7 +135,8 @@ public class JMainService {
Logger.info("异常中断"); Logger.info("异常中断");
} }
} }
} index++;
} while (index < timesValue && run);
JMainController.getInstance().onStop(); JMainController.getInstance().onStop();
Logger.info("执行结束,守护线程已退出"); Logger.info("执行结束,守护线程已退出");

@ -24,9 +24,9 @@
<HBox alignment="CENTER_LEFT" prefHeight="35.0" prefWidth="200.0"> <HBox alignment="CENTER_LEFT" prefHeight="35.0" prefWidth="200.0">
<children> <children>
<Button fx:id="start" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStart" <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" <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> <HBox.margin>
<Insets left="10.0"/> <Insets left="10.0"/>
</HBox.margin> </HBox.margin>
@ -128,18 +128,18 @@
<AnchorPane layoutX="262.0" layoutY="14.0" prefHeight="250.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" <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"> AnchorPane.leftAnchor="204.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <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"> AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding> <padding>
<Insets left="10.0" right="10.0"/> <Insets left="10.0" right="10.0"/>
</padding> </padding>
</Label> </Label>
<Separator layoutX="-3.0" layoutY="39.0" opacity="0.5" prefWidth="200.0" AnchorPane.leftAnchor="1.0" <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" <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;" 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" wrapText="true" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="45.0"> AnchorPane.topAnchor="35.0">
</TextArea> </TextArea>
</children> </children>

Loading…
Cancel
Save

Powered by TurnKey Linux.