feat: 添加GUI检查更新功能,添加nojre打包方式

This commit is contained in:
octopus_yan 2024-09-21 19:32:21 +08:00
parent 828a2fdb62
commit fbdf6b3ba7
9 changed files with 115 additions and 62 deletions

19
pom.xml
View File

@ -258,7 +258,6 @@
<vmArgs> <vmArgs>
<arg>--enable-preview</arg> <arg>--enable-preview</arg>
<arg>-Xmx100m</arg> <arg>-Xmx100m</arg>
<!-- <arg>-Djava.awt.headless=false</arg>-->
</vmArgs> </vmArgs>
</configuration> </configuration>
<executions> <executions>
@ -270,6 +269,7 @@
</goals> </goals>
<configuration> <configuration>
<platform>windows</platform> <platform>windows</platform>
<zipballName>${project.name}-windows</zipballName>
<createZipball>true</createZipball> <createZipball>true</createZipball>
<winConfig> <winConfig>
<headerType>gui</headerType> <headerType>gui</headerType>
@ -277,6 +277,23 @@
</winConfig> </winConfig>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>bundling-for-windows-nojre</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<zipballName>${project.name}-windows-nojre</zipballName>
<platform>windows</platform>
<createZipball>true</createZipball>
<bundleJre>false</bundleJre>
<winConfig>
<headerType>gui</headerType>
<generateMsi>false</generateMsi>
</winConfig>
</configuration>
</execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -3,7 +3,6 @@ package cn.octopusyan.alistgui.controller;
import cn.octopusyan.alistgui.base.BaseController; import cn.octopusyan.alistgui.base.BaseController;
import cn.octopusyan.alistgui.config.I18n; import cn.octopusyan.alistgui.config.I18n;
import cn.octopusyan.alistgui.manager.ConfigManager; import cn.octopusyan.alistgui.manager.ConfigManager;
import cn.octopusyan.alistgui.view.alert.AlertUtil;
import cn.octopusyan.alistgui.viewModel.AboutViewModule; import cn.octopusyan.alistgui.viewModel.AboutViewModule;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -60,8 +59,7 @@ public class AboutController extends BaseController<AboutViewModule> {
} }
public void checkGuiUpdate() { public void checkGuiUpdate() {
// TODO 检查 gui 版本 viewModel.checkUpdate(ConfigManager.gui());
AlertUtil.info("待开发。。。").show();
} }
} }

View File

@ -205,7 +205,7 @@ public class AListManager {
} }
var task = new CheckUpdateTask(ConfigManager.aList()); var task = new CheckUpdateTask(ConfigManager.aList());
task.onListen(new TaskListener.UpgradeUpgradeListener(task) { task.onListen(new TaskListener.UpgradeListener(task) {
@Override @Override
public void onChecked(boolean hasUpgrade, String version) { public void onChecked(boolean hasUpgrade, String version) {
Platform.runLater(() -> showDownload(version)); Platform.runLater(() -> showDownload(version));

View File

@ -10,18 +10,12 @@ import lombok.Data;
@Data @Data
public class Gui implements UpgradeApp { public class Gui implements UpgradeApp {
@JsonIgnore @JsonIgnore
private final String owner = "alist-org"; private final String owner = "octopusYan";
@JsonIgnore @JsonIgnore
private final String repo = "alist"; private final String repo = "alist-gui";
private String releaseFile = "alist-gui-windows-nojre.zip";
private String releaseFile = "alist-gui-{version}-windows.zip";
private String version = PropertiesUtils.getInstance().getProperty("app.version"); private String version = PropertiesUtils.getInstance().getProperty("app.version");
public String getReleaseFile() {
return getReleaseFile(version);
}
public String getReleaseFile(String version) {
return releaseFile.replace("{version}", version);
}
} }

View File

@ -1,7 +1,6 @@
package cn.octopusyan.alistgui.task; package cn.octopusyan.alistgui.task;
import cn.octopusyan.alistgui.base.BaseTask; import cn.octopusyan.alistgui.base.BaseTask;
import cn.octopusyan.alistgui.config.Constants;
import cn.octopusyan.alistgui.manager.http.HttpUtil; import cn.octopusyan.alistgui.manager.http.HttpUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -13,10 +12,12 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class DownloadTask extends BaseTask { public class DownloadTask extends BaseTask {
private final String downloadUrl; private final String downloadUrl;
private final String savePath;
public DownloadTask(String downloadUrl) { public DownloadTask(String downloadUrl, String savePath) {
super(STR."Download \{downloadUrl}"); super(STR."Download \{downloadUrl}");
this.downloadUrl = downloadUrl; this.downloadUrl = downloadUrl;
this.savePath = savePath;
} }
public void onListen(DownloadListener listener) { public void onListen(DownloadListener listener) {
@ -27,7 +28,7 @@ public class DownloadTask extends BaseTask {
protected void task() throws Exception { protected void task() throws Exception {
HttpUtil.getInstance().download( HttpUtil.getInstance().download(
downloadUrl, downloadUrl,
Constants.BIN_DIR_PATH, savePath,
listener instanceof DownloadListener ? ((DownloadListener) listener)::onProgress : null listener instanceof DownloadListener ? ((DownloadListener) listener)::onProgress : null
); );
} }

View File

@ -89,8 +89,8 @@ public abstract class TaskListener implements BaseTask.Listener {
/** /**
* 检查更新监听默认实现 * 检查更新监听默认实现
*/ */
public static abstract class UpgradeUpgradeListener extends TaskListener implements CheckUpdateTask.UpgradeListener { public static abstract class UpgradeListener extends TaskListener implements CheckUpdateTask.UpgradeListener {
public UpgradeUpgradeListener(BaseTask task) { public UpgradeListener(BaseTask task) {
super(task); super(task);
} }

View File

@ -7,6 +7,7 @@ import cn.hutool.core.util.ZipUtil;
import cn.octopusyan.alistgui.config.Constants; import cn.octopusyan.alistgui.config.Constants;
import cn.octopusyan.alistgui.manager.ConsoleLog; import cn.octopusyan.alistgui.manager.ConsoleLog;
import cn.octopusyan.alistgui.model.upgrade.AList; import cn.octopusyan.alistgui.model.upgrade.AList;
import cn.octopusyan.alistgui.model.upgrade.Gui;
import cn.octopusyan.alistgui.model.upgrade.UpgradeApp; import cn.octopusyan.alistgui.model.upgrade.UpgradeApp;
import cn.octopusyan.alistgui.task.DownloadTask; import cn.octopusyan.alistgui.task.DownloadTask;
import cn.octopusyan.alistgui.task.listener.TaskListener; import cn.octopusyan.alistgui.task.listener.TaskListener;
@ -24,7 +25,6 @@ import java.util.zip.ZipFile;
@Slf4j @Slf4j
public class DownloadUtil { public class DownloadUtil {
/** /**
* 下载文件 * 下载文件
* *
@ -32,7 +32,12 @@ public class DownloadUtil {
* @param version 下载版本 * @param version 下载版本
*/ */
public static DownloadTask startDownload(UpgradeApp app, String version, Runnable runnable) { public static DownloadTask startDownload(UpgradeApp app, String version, Runnable runnable) {
var task = new DownloadTask(app.getDownloadUrl(version)); var parentPath = switch (app) {
case AList _ -> Constants.BIN_DIR_PATH;
case Gui _ -> Constants.DATA_DIR_PATH;
default -> throw new IllegalStateException(STR."Unexpected value: \{app}");
};
var task = new DownloadTask(app.getDownloadUrl(version), parentPath);
task.onListen(new TaskListener.DownloadListener(task) { task.onListen(new TaskListener.DownloadListener(task) {
@Override @Override
@ -64,6 +69,11 @@ public class DownloadUtil {
path = StrUtil.replace(path, "*", "_"); path = StrUtil.replace(path, "*", "_");
} }
// 打包后文件都在alist-gui文件夹下解压时去掉
if (app instanceof Gui) {
path = path.replaceFirst(Constants.APP_NAME, "");
}
final File outItemFile = FileUtil.file(parentPath, path); final File outItemFile = FileUtil.file(parentPath, path);
if (zipEntry.isDirectory()) { if (zipEntry.isDirectory()) {
// 目录 // 目录

View File

@ -1,14 +1,19 @@
package cn.octopusyan.alistgui.viewModel; package cn.octopusyan.alistgui.viewModel;
import cn.octopusyan.alistgui.Application;
import cn.octopusyan.alistgui.base.BaseViewModel; import cn.octopusyan.alistgui.base.BaseViewModel;
import cn.octopusyan.alistgui.config.Constants;
import cn.octopusyan.alistgui.config.Context; import cn.octopusyan.alistgui.config.Context;
import cn.octopusyan.alistgui.manager.AListManager;
import cn.octopusyan.alistgui.manager.ConfigManager; import cn.octopusyan.alistgui.manager.ConfigManager;
import cn.octopusyan.alistgui.manager.ConsoleLog; import cn.octopusyan.alistgui.manager.ConsoleLog;
import cn.octopusyan.alistgui.model.upgrade.AList; import cn.octopusyan.alistgui.model.upgrade.AList;
import cn.octopusyan.alistgui.model.upgrade.Gui;
import cn.octopusyan.alistgui.model.upgrade.UpgradeApp; import cn.octopusyan.alistgui.model.upgrade.UpgradeApp;
import cn.octopusyan.alistgui.task.CheckUpdateTask; import cn.octopusyan.alistgui.task.CheckUpdateTask;
import cn.octopusyan.alistgui.task.listener.TaskListener; import cn.octopusyan.alistgui.task.listener.TaskListener;
import cn.octopusyan.alistgui.util.DownloadUtil; import cn.octopusyan.alistgui.util.DownloadUtil;
import cn.octopusyan.alistgui.util.ProcessesUtil;
import cn.octopusyan.alistgui.view.alert.AlertUtil; import cn.octopusyan.alistgui.view.alert.AlertUtil;
import cn.octopusyan.alistgui.view.alert.builder.AlertBuilder; import cn.octopusyan.alistgui.view.alert.builder.AlertBuilder;
import javafx.application.Platform; import javafx.application.Platform;
@ -61,52 +66,22 @@ public class AboutViewModule extends BaseViewModel {
* 检查更新 * 检查更新
*/ */
public void checkUpdate(UpgradeApp app) { public void checkUpdate(UpgradeApp app) {
// 检查任务 // 检查任务
startUpgrade(app, () -> { startUpgrade(app, () -> onChecked(app));
// 判断 检查的应用
boolean tag = app instanceof AList;
boolean upgrade = tag ? aListUpgrade.get() : guiUpgrade.get();
String version = tag ? aListVersion.get() : guiVersion.get();
String newVersion = tag ? aListNewVersion.get() : guiNewVersion.get();
String title = Context.getLanguageBinding(STR."about.\{tag ? "alist" : "app"}.update").getValue();
String currentLabel = Context.getLanguageBinding("update.current").get();
String newLabel = Context.getLanguageBinding("update.remote").get();
String header = Context.getLanguageBinding(STR."update.upgrade.\{upgrade ? "new" : "not"}").get();
// 版本检查消息
String msg = STR."\{app.getRepo()}\{upgrade ? "" : STR." \{version}"} \{header} \{upgrade ? newVersion : ""}";
log.info(msg);
ConsoleLog.info(msg);
// 弹窗
AlertBuilder builder = upgrade ? AlertUtil.confirm() : AlertUtil.info();
builder.title(title)
.header(header)
.content(STR."""
\{currentLabel} : \{version}
\{newLabel} : \{newVersion}
""")
.show(() -> {
// 可升级且点击了确定后开始下载任务
if (upgrade)
DownloadUtil.startDownload(app, newVersion, () -> {
// 下载完成后解压并删除文件
DownloadUtil.unzip(app);
// 设置应用版本
Platform.runLater(() -> aListVersion.setValue(aListNewVersion.getValue()));
}).execute();
});
});
} }
/**
* 开始检查更新
*
* @param app 更新的应用
* @param runnable 检查后执行的任务
*/
private void startUpgrade(UpgradeApp app, Runnable runnable) { private void startUpgrade(UpgradeApp app, Runnable runnable) {
// 检查更新的任务 // 检查更新的任务
var task = new CheckUpdateTask(app); var task = new CheckUpdateTask(app);
// 任务监听 // 任务监听
task.onListen(new TaskListener.UpgradeUpgradeListener(task) { task.onListen(new TaskListener.UpgradeListener(task) {
@Override @Override
protected void onSucceed() { protected void onSucceed() {
@ -135,4 +110,62 @@ public class AboutViewModule extends BaseViewModel {
// 执行任务 // 执行任务
task.execute(); task.execute();
} }
private void onChecked(UpgradeApp app) {
// 判断 检查的应用
boolean tag = app instanceof AList;
boolean upgrade = tag ? aListUpgrade.get() : guiUpgrade.get();
String version = tag ? aListVersion.get() : guiVersion.get();
String newVersion = tag ? aListNewVersion.get() : guiNewVersion.get();
String title = Context.getLanguageBinding(STR."about.\{tag ? "alist" : "app"}.update").getValue();
String currentLabel = Context.getLanguageBinding("update.current").get();
String newLabel = Context.getLanguageBinding("update.remote").get();
String header = Context.getLanguageBinding(STR."update.upgrade.\{upgrade ? "new" : "not"}").get();
// 版本检查消息
String msg = STR."\{app.getRepo()}\{upgrade ? "" : STR." \{version}"} \{header} \{upgrade ? newVersion : ""}";
log.info(msg);
ConsoleLog.info(msg);
// 弹窗
AlertBuilder builder = upgrade ? AlertUtil.confirm() : AlertUtil.info();
builder.title(title)
.header(header)
.content(STR."""
\{currentLabel} : \{version}
\{newLabel} : \{newVersion}
""")
.show(() -> {
// 可升级且点击了确定后开始下载任务
if (upgrade)
DownloadUtil.startDownload(app, newVersion, () -> {
// 下载完成后解压并删除文件
DownloadUtil.unzip(app);
// 解压后
Platform.runLater(() -> {
switch (app) {
case AList _ -> {
// 设置应用版本
aListVersion.setValue(aListNewVersion.getValue());
AListManager.restart();
}
case Gui _ -> {
log.info(STR."guiNewVersion => \{guiNewVersion.get()}");
// 重启
Platform.setImplicitExit(true);
Application.getPrimaryStage().close();
ProcessesUtil.init(Constants.DATA_DIR_PATH).exec(STR."\{Constants.APP_NAME}.exe");
}
default -> throw new IllegalStateException(STR."Unexpected value: \{app}");
}
});
}).execute();
});
}
} }

View File

@ -1,3 +1,3 @@
app.name=${project.name} app.name=${project.name}
app.title=AList GUI app.title=AList GUI
app.version=${project.version} app.version=v${project.version}