cicy-desktop 2.1.285 → 2.1.286
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/app-updater.js +28 -4
- package/src/backends/homepage-preload.js +2 -0
- package/src/backends/homepage-react/assets/index-CZILCWSS.js +377 -0
- package/src/backends/homepage-react/index.html +1 -1
- package/src/backends/ipc.js +2 -0
- package/test/app-updater-auto.test.js +20 -0
- package/workers/render/src/App.jsx +19 -1
- package/src/backends/homepage-react/assets/index-BzYBKzQW.js +0 -377
package/package.json
CHANGED
package/src/app-updater.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
const { app, shell } = require("electron");
|
|
18
18
|
const path = require("path");
|
|
19
19
|
const fs = require("fs");
|
|
20
|
+
const os = require("os");
|
|
21
|
+
const { readGlobalConfig, updateGlobalConfig } = require("./utils/global-json");
|
|
20
22
|
const https = require("https");
|
|
21
23
|
const log = require("electron-log");
|
|
22
24
|
const { OSS_RELEASES_BASE } = require("./sidecar/mirrors");
|
|
@@ -135,9 +137,23 @@ function download(url, dest, onProgress, redirects = 0) {
|
|
|
135
137
|
|
|
136
138
|
// ── 状态机 + 广播 ─────────────────────────────────────────────────────────────
|
|
137
139
|
let _win = null;
|
|
138
|
-
let _state = { status: "idle", version: null, current: null, progress: null, filePath: null, error: null };
|
|
140
|
+
let _state = { status: "idle", version: null, current: null, progress: null, filePath: null, error: null, autoUpdate: false, auto: false };
|
|
139
141
|
let _downloading = false;
|
|
140
142
|
|
|
143
|
+
// 「以后自动更新到最新版」开关,存 ~/cicy-ai/global.json desktopAutoUpdate(设备级,与账号无关)。
|
|
144
|
+
// 打开后 check() 发现新版直接下载 + 拉起安装器,不再弹「发现新版本」询问。
|
|
145
|
+
const GLOBAL_JSON = path.join(os.homedir(), "cicy-ai", "global.json");
|
|
146
|
+
function getAutoUpdate() {
|
|
147
|
+
try { return readGlobalConfig(GLOBAL_JSON)?.desktopAutoUpdate === true; } catch { return false; }
|
|
148
|
+
}
|
|
149
|
+
function setAutoUpdate(on) {
|
|
150
|
+
const v = on === true;
|
|
151
|
+
try { updateGlobalConfig(GLOBAL_JSON, (c) => ({ ...(c || {}), desktopAutoUpdate: v })); }
|
|
152
|
+
catch (e) { log.warn("[app-updater] setAutoUpdate failed:", e.message); }
|
|
153
|
+
broadcast({ autoUpdate: v });
|
|
154
|
+
return v;
|
|
155
|
+
}
|
|
156
|
+
|
|
141
157
|
function broadcast(patch) {
|
|
142
158
|
Object.assign(_state, patch);
|
|
143
159
|
try { if (_win && !_win.isDestroyed()) _win.webContents.send("app:update-state", _state); } catch {}
|
|
@@ -147,6 +163,7 @@ function getState() { return _state; }
|
|
|
147
163
|
function init(mainWin) {
|
|
148
164
|
_win = mainWin;
|
|
149
165
|
_state.current = app.getVersion();
|
|
166
|
+
_state.autoUpdate = getAutoUpdate();
|
|
150
167
|
setTimeout(() => check().catch(() => {}), 15_000); // 启动后探一次
|
|
151
168
|
setInterval(() => check().catch(() => {}), 30 * 60 * 1000); // 每 30 分钟
|
|
152
169
|
}
|
|
@@ -162,8 +179,15 @@ async function check() {
|
|
|
162
179
|
// 真能下(200),否则当成「还没就绪」继续显已是最新,避免用户点下载 404。
|
|
163
180
|
const { url } = assetFor(latest);
|
|
164
181
|
const ready = await headOk(url);
|
|
165
|
-
if (ready)
|
|
166
|
-
|
|
182
|
+
if (ready) {
|
|
183
|
+
broadcast({ status: "available", version: latest, current, progress: null, filePath: null, autoUpdate: getAutoUpdate(), auto: false });
|
|
184
|
+
if (getAutoUpdate()) {
|
|
185
|
+
log.info(`[app-updater] auto-update on → downloading ${latest} and installing without asking`);
|
|
186
|
+
broadcast({ auto: true });
|
|
187
|
+
await downloadUpdate();
|
|
188
|
+
if (_state.status === "ready") installNow();
|
|
189
|
+
}
|
|
190
|
+
} else { log.info(`[app-updater] ${latest} 版本号已更新但安装包未就位(HEAD 非 200):${url} — 暂不提示更新`); broadcast({ status: "up-to-date", version: current, current }); }
|
|
167
191
|
} else {
|
|
168
192
|
broadcast({ status: "up-to-date", version: latest || current, current });
|
|
169
193
|
}
|
|
@@ -215,4 +239,4 @@ function installNow() {
|
|
|
215
239
|
} catch (e) { log.warn("[app-updater] install failed:", e.message); }
|
|
216
240
|
}
|
|
217
241
|
|
|
218
|
-
module.exports = { init, check, getState, downloadUpdate, installNow };
|
|
242
|
+
module.exports = { init, check, getState, downloadUpdate, installNow, getAutoUpdate, setAutoUpdate };
|
|
@@ -237,6 +237,8 @@ contextBridge.exposeInMainWorld("cicy", {
|
|
|
237
237
|
checkUpdate: () => logInvoke("app:check-update"),
|
|
238
238
|
downloadUpdate:() => logInvoke("app:download-update"),
|
|
239
239
|
installUpdate: () => logInvoke("app:install-update"),
|
|
240
|
+
getAutoUpdate: () => logInvoke("app:auto-update-get"),
|
|
241
|
+
setAutoUpdate: (on) => logInvoke("app:auto-update-set", on === true),
|
|
240
242
|
onUpdateState: (cb) => {
|
|
241
243
|
const handler = (_e, state) => { try { cb(state); } catch {} };
|
|
242
244
|
ipcRenderer.on("app:update-state", handler);
|