From 09f515025c944b73477f802f1f4ec4a32a7de855 Mon Sep 17 00:00:00 2001 From: octopus_yan Date: Sun, 17 Nov 2024 15:45:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8AList?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E6=9B=B4=E6=96=B0=E4=BC=9A=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E2=80=9C=E8=AF=A5=E6=96=87=E4=BB=B6=E6=AD=A3=E5=9C=A8?= =?UTF-8?q?=E8=A2=AB=E4=BD=BF=E7=94=A8=E2=80=9D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/octopusyan/alistgui/Application.java | 4 ++-- .../alistgui/manager/AListManager.java | 20 ++++++++++--------- .../alistgui/viewModel/AboutViewModule.java | 18 +++++++++++++++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/gui/src/main/java/cn/octopusyan/alistgui/Application.java b/gui/src/main/java/cn/octopusyan/alistgui/Application.java index 60e18a6..c1d8166 100644 --- a/gui/src/main/java/cn/octopusyan/alistgui/Application.java +++ b/gui/src/main/java/cn/octopusyan/alistgui/Application.java @@ -41,7 +41,7 @@ public class Application extends javafx.application.Application { long delay = 0L; // 更新重启检查 File upgradeFile = new File(Constants.DATA_DIR_PATH + File.separator + new Gui().getReleaseFile()); - logger.error("{}{}{}", Constants.DATA_DIR_PATH, File.separator, new Gui().getReleaseFile()); +// logger.error("{}{}{}", Constants.DATA_DIR_PATH, File.separator, new Gui().getReleaseFile()); if (upgradeFile.exists()) { logger.error("upgradeFile.exists"); FileUtil.del(upgradeFile); @@ -165,7 +165,7 @@ public class Application extends javafx.application.Application { instanceCheckLatch.countDown(); while (true) { - logger.error(STR."====\{instanceId}===="); + logger.debug(STR."====\{instanceId}===="); try ( Socket clientSocket = serverSocket.accept(); BufferedReader in = new BufferedReader( diff --git a/gui/src/main/java/cn/octopusyan/alistgui/manager/AListManager.java b/gui/src/main/java/cn/octopusyan/alistgui/manager/AListManager.java index 9307628..79153a8 100644 --- a/gui/src/main/java/cn/octopusyan/alistgui/manager/AListManager.java +++ b/gui/src/main/java/cn/octopusyan/alistgui/manager/AListManager.java @@ -143,24 +143,21 @@ public class AListManager { ConsoleLog.info(getText("alist.status.stop")); if (!running.get()) { ConsoleLog.warning(getText("alist.status.stop.stopped")); - return; } util.destroy(); } - static ChangeListener restartListener; + static ChangeListener restartListener = (_, _, run) -> { + if (run) return; + running.removeListener(AListManager.restartListener); + start(); + }; public static void restart() { if (!running.get()) { start(); } else { stop(); - - restartListener = (_, _, run) -> { - if (run) return; - running.removeListener(restartListener); - start(); - }; running.addListener(restartListener); } } @@ -194,7 +191,7 @@ public class AListManager { //============================={ private }==================================== /** - * TODO 点击开始时检查 aList 执行文件 + * 点击开始时检查 aList 执行文件 */ private static boolean checkAList() { if (new File(Constants.ALIST_FILE).exists()) return true; @@ -216,6 +213,11 @@ public class AListManager { return false; } + /** + * 开始下载AList + * + * @param version 下载版本号 + */ private static void showDownload(String version) { String content = STR.""" \{getText("msg.alist.download.notfile")} diff --git a/gui/src/main/java/cn/octopusyan/alistgui/viewModel/AboutViewModule.java b/gui/src/main/java/cn/octopusyan/alistgui/viewModel/AboutViewModule.java index 0a0663f..5d400c2 100644 --- a/gui/src/main/java/cn/octopusyan/alistgui/viewModel/AboutViewModule.java +++ b/gui/src/main/java/cn/octopusyan/alistgui/viewModel/AboutViewModule.java @@ -17,6 +17,7 @@ import cn.octopusyan.alistgui.view.alert.AlertUtil; import cn.octopusyan.alistgui.view.alert.builder.AlertBuilder; import javafx.application.Platform; import javafx.beans.property.*; +import javafx.beans.value.ChangeListener; import lombok.extern.slf4j.Slf4j; /** @@ -144,8 +145,13 @@ public class AboutViewModule extends BaseViewModel { Platform.runLater(() -> { switch (app) { case AList _ -> { - // 下载完成后,解压并删除文件 - DownloadUtil.unzip(app); + if(AListManager.isRunning()) { + AListManager.stop(); + AListManager.runningProperty().addListener(updateListener); + } else { + // 下载完成后,解压并删除文件 + DownloadUtil.unzip(app); + } // 设置应用版本 aListVersion.setValue(aListNewVersion.getValue()); AListManager.restart(); @@ -163,4 +169,12 @@ public class AboutViewModule extends BaseViewModel { }).execute(); }); } + + static final ChangeListener updateListener = (_, _, run) -> { + if (!run) { + // 下载完成后,解压并删除文件 + DownloadUtil.unzip(ConfigManager.aList()); + } + AListManager.runningProperty().removeListener(AboutViewModule.updateListener); + }; }