diff --git a/pom.xml b/pom.xml index 3b68ce2..c5092ad 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,6 @@ org.jcnc.jnotepad/org.jcnc.jnotepad.LunchApp JNotepad - JNotepad JNotepad true true diff --git a/src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java b/src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java new file mode 100644 index 0000000..0794af8 --- /dev/null +++ b/src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java @@ -0,0 +1,30 @@ +package org.jcnc.jnotepad.app.util; + +import org.jcnc.jnotepad.LunchApp; +import org.jcnc.jnotepad.util.LogUtil; + +import java.io.IOException; + +/** + * @author luke + */ +public class ApplicationRestarter { + + public static void restart() { + try { + // 获取当前Java应用程序的命令 + String javaCommand = System.getProperty("java.home") + "/bin/java"; + String mainClass = LunchApp.class.getName(); + + // 构建新进程来重新启动应用程序 + ProcessBuilder builder = new ProcessBuilder(javaCommand, "-cp", System.getProperty("java.class.path"), mainClass); + builder.start(); + + // 关闭当前应用程序 + System.exit(0); + } catch (IOException e) { + LogUtil.getLogger("正在重启当前应用程序".getClass()); + + } + } +} diff --git a/src/main/java/org/jcnc/jnotepad/plugin/manager/PluginManager.java b/src/main/java/org/jcnc/jnotepad/plugin/manager/PluginManager.java index adc8e8e..6132a9f 100644 --- a/src/main/java/org/jcnc/jnotepad/plugin/manager/PluginManager.java +++ b/src/main/java/org/jcnc/jnotepad/plugin/manager/PluginManager.java @@ -1,6 +1,7 @@ package org.jcnc.jnotepad.plugin.manager; import org.jcnc.jnotepad.app.manager.ApplicationManager; +import org.jcnc.jnotepad.app.util.ApplicationRestarter; import org.jcnc.jnotepad.common.manager.ThreadPoolManager; import org.jcnc.jnotepad.controller.config.PluginConfigController; import org.jcnc.jnotepad.model.entity.PluginDescriptor; @@ -200,8 +201,8 @@ public class PluginManager { PopUpUtil.questionAlert("更改", "程序与插件更新", "请重启程序以应用插件中的更改!", appDialog -> { appDialog.close(); - // 执行关闭操作 - ApplicationManager.getInstance().stopApplication(); + // 执行重启操作 + ApplicationRestarter.restart(); }, null); } } diff --git a/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java b/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java index 3fbad92..700ecd7 100644 --- a/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java +++ b/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java @@ -4,8 +4,10 @@ import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; +import org.jcnc.jnotepad.app.util.ApplicationRestarter; import org.jcnc.jnotepad.util.LogUtil; import org.jcnc.jnotepad.util.PopUpUtil; import org.jcnc.jnotepad.util.UiUtil; @@ -22,12 +24,17 @@ public class DeveloperDebugStage extends Stage { primaryStage.setTitle("开发者调试页面"); primaryStage.getIcons().add(UiUtil.getAppIcon()); // 创建一个垂直布局 - VBox root = new VBox(); + VBox root = new VBox(10); + HBox alertBox = new HBox(5); + HBox toolBox = new HBox(5); + root.setPadding(new Insets(20)); root.setSpacing(10); // 添加一些调试功能按钮和标签 - Label titleLabel = new Label("开发者调试页面"); + Label alertLabel = new Label("提示框"); + Label toolLabel = new Label("工具"); + Button debugButton1 = new Button("错误提示框"); Button debugButton2 = new Button("信息提示框"); Button debugButton3 = new Button("警告提示框"); @@ -64,11 +71,20 @@ public class DeveloperDebugStage extends Stage { PopUpUtil.successAlert("成功", "成功", "这是一个示例成功提示框!", null, null); }); + Button debugButton6 = new Button("重启软件"); + debugButton6.setOnAction(event -> { + logger.debug("开发者调试: {}启动!", debugButton6.getText()); + // 执行重启操作 + ApplicationRestarter.restart(); + }); + + alertBox.getChildren().addAll(debugButton1, debugButton2, debugButton3, debugButton4, debugButton5); + toolBox.getChildren().addAll(debugButton6); // 将组件添加到布局中 - root.getChildren().addAll(titleLabel, debugButton1, debugButton2, debugButton3, debugButton4, debugButton5); + root.getChildren().addAll(alertLabel, alertBox, toolLabel, toolBox); // 创建场景 - Scene scene = new Scene(root, 400, 300); + Scene scene = new Scene(root, 800, 600); // 将场景添加到舞台 primaryStage.setScene(scene);