修改主窗口关闭后进程残留的问题

main
lensfrex 4 years ago
parent f7576885fd
commit 9306f3275f
No known key found for this signature in database
GPG Key ID: E10FF75B77E1924D
  1. 3
      .gitignore
  2. 21
      Dogename/src/main/java/me/lensferno/dogename/Main.java
  3. 2
      Dogename/src/main/java/me/lensferno/dogename/controllers/MainInterfaceController.java

3
.gitignore vendored

@ -6,4 +6,5 @@ target
target target
log log
logs logs
.idea .idea
process

@ -12,6 +12,8 @@ import me.lensferno.dogename.sayings.Hitokoto;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.Random; import java.util.Random;
public class Main extends Application { public class Main extends Application {
@ -22,6 +24,20 @@ public class Main extends Application {
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
try {
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
new File("process").mkdirs();
File tempFile = new File("process" + File.separator + pid);
tempFile.createNewFile();
tempFile.deleteOnExit();
}catch (Exception e){
e.printStackTrace();
}
FXMLLoader fxmlLoader; FXMLLoader fxmlLoader;
Parent parent; Parent parent;
@ -51,7 +67,10 @@ public class Main extends Application {
mainInterfaceController.setImg(DataReleaser.getMainPicStream()); mainInterfaceController.setImg(DataReleaser.getMainPicStream());
primaryStage.setOnCloseRequest(event -> configLoader.writeAllConfigToFile(configLoader.getMainConfigLocation(),configLoader.getVoiceConfigLocation())); primaryStage.setOnCloseRequest(event -> {
configLoader.writeAllConfigToFile(configLoader.getMainConfigLocation(), configLoader.getVoiceConfigLocation());
System.exit(0);
});
if (mainInterfaceController.getMainConfig().isShowSaying()) { if (mainInterfaceController.getMainConfig().isShowSaying()) {
if (new Random().nextBoolean()){ if (new Random().nextBoolean()){

@ -183,7 +183,7 @@ public final class MainInterfaceController {
miniPaneController.setListeners(); miniPaneController.setListeners();
miniStage.show(); miniStage.show();
currentStage.close(); currentStage.hide();
} }

Loading…
Cancel
Save