feat(editor): 添加 ECS UI 系统和编辑器更新优化 (#238)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { check } from '@tauri-apps/plugin-updater';
|
||||
import { check, Update } from '@tauri-apps/plugin-updater';
|
||||
|
||||
export interface UpdateCheckResult {
|
||||
available: boolean;
|
||||
@@ -7,33 +7,33 @@ export interface UpdateCheckResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// 全局存储更新对象,以便后续安装
|
||||
let pendingUpdate: Update | null = null;
|
||||
|
||||
/**
|
||||
* 检查应用更新
|
||||
* 检查应用更新(仅检查,不安装)
|
||||
*
|
||||
* 自动检查 GitHub Releases 是否有新版本
|
||||
* 如果有更新,提示用户并可选择安装
|
||||
* 返回检查结果,由调用者决定是否安装
|
||||
*/
|
||||
export async function checkForUpdates(silent: boolean = false): Promise<UpdateCheckResult> {
|
||||
export async function checkForUpdates(): Promise<UpdateCheckResult> {
|
||||
try {
|
||||
const update = await check();
|
||||
|
||||
if (update?.available) {
|
||||
if (!silent) {
|
||||
// Tauri 会自动显示更新对话框(因为配置了 dialog: true)
|
||||
// 用户点击确认后会自动下载并安装,安装完成后会自动重启
|
||||
await update.downloadAndInstall();
|
||||
}
|
||||
|
||||
pendingUpdate = update;
|
||||
return {
|
||||
available: true,
|
||||
version: update.version,
|
||||
currentVersion: update.currentVersion
|
||||
};
|
||||
} else {
|
||||
pendingUpdate = null;
|
||||
return { available: false };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查更新失败:', error);
|
||||
pendingUpdate = null;
|
||||
return {
|
||||
available: false,
|
||||
error: error instanceof Error ? error.message : '检查更新失败'
|
||||
@@ -42,11 +42,34 @@ export async function checkForUpdates(silent: boolean = false): Promise<UpdateCh
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动时静默检查更新
|
||||
* 安装待处理的更新
|
||||
* 需要先调用 checkForUpdates 检测到更新
|
||||
*/
|
||||
export async function checkForUpdatesOnStartup(): Promise<void> {
|
||||
// 延迟 3 秒后检查,避免影响启动速度
|
||||
setTimeout(() => {
|
||||
checkForUpdates(true);
|
||||
}, 3000);
|
||||
export async function installUpdate(): Promise<boolean> {
|
||||
if (!pendingUpdate) {
|
||||
console.error('没有待安装的更新');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await pendingUpdate.downloadAndInstall();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('安装更新失败:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动时静默检查更新
|
||||
* 返回 Promise 以便调用者可以获取结果
|
||||
*/
|
||||
export async function checkForUpdatesOnStartup(): Promise<UpdateCheckResult> {
|
||||
// 延迟 2 秒后检查,避免影响启动速度
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(async () => {
|
||||
const result = await checkForUpdates();
|
||||
resolve(result);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user