cicy-desktop 2.1.330 → 2.1.331
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/main.js +33 -5
- package/test/autostart-run-key.test.js +59 -0
package/package.json
CHANGED
package/src/main.js
CHANGED
|
@@ -949,22 +949,29 @@ function ensureAutoLaunch() {
|
|
|
949
949
|
// (它先起 master 再起 worker,直接起 electron.exe 会缺 master)。登录项指向一个
|
|
950
950
|
// wscript 隐藏启动的 VBS → `cmd /c node .\bin\cicy-desktop`,全程无控制台窗口。
|
|
951
951
|
const fromSource = !electronApp.isPackaged;
|
|
952
|
-
let opts;
|
|
952
|
+
let opts, runCmd;
|
|
953
953
|
if (fromSource) {
|
|
954
954
|
const vbs = writeSourceAutostartVbs();
|
|
955
955
|
opts = { openAtLogin: want, path: "wscript.exe", args: ["//B", "//Nologo", vbs] };
|
|
956
|
+
runCmd = `wscript.exe //B //Nologo "${vbs}"`;
|
|
956
957
|
} else {
|
|
957
958
|
opts = { openAtLogin: want, args: ["--hidden"] };
|
|
959
|
+
runCmd = `"${process.execPath}" --hidden`;
|
|
958
960
|
}
|
|
959
|
-
const
|
|
960
|
-
fromSource ? { path: opts.path, args: opts.args } : undefined
|
|
961
|
-
)
|
|
962
|
-
if (cur.openAtLogin !== want) {
|
|
961
|
+
const probe = () =>
|
|
962
|
+
electronApp.getLoginItemSettings(fromSource ? { path: opts.path, args: opts.args } : undefined);
|
|
963
|
+
if (probe().openAtLogin !== want) {
|
|
963
964
|
electronApp.setLoginItemSettings(opts);
|
|
964
965
|
log.info(
|
|
965
966
|
`[autostart] openAtLogin → ${want}${fromSource ? ` (source: ${opts.path} ${opts.args.join(" ")})` : ""}`
|
|
966
967
|
);
|
|
967
968
|
}
|
|
969
|
+
// Read it back. setLoginItemSettings() returns without throwing on every
|
|
970
|
+
// Windows node of this fleet and still leaves openAtLogin false, with
|
|
971
|
+
// HKCU\...\Run untouched — so autostart silently never existed, and a node
|
|
972
|
+
// whose app went away (e.g. an installer closed it) never came back, not
|
|
973
|
+
// even after a reboot. When the API did not take, write the Run key.
|
|
974
|
+
if (probe().openAtLogin !== want) ensureWindowsRunKey(want, runCmd);
|
|
968
975
|
} else if (process.platform === "linux") {
|
|
969
976
|
if (!electronApp.isPackaged) return;
|
|
970
977
|
ensureLinuxAutostart(want);
|
|
@@ -974,6 +981,27 @@ function ensureAutoLaunch() {
|
|
|
974
981
|
}
|
|
975
982
|
}
|
|
976
983
|
|
|
984
|
+
// Fallback for the silently-failing setLoginItemSettings (see ensureAutoLaunch):
|
|
985
|
+
// own the HKCU Run entry directly. Async so a slow reg.exe never delays startup;
|
|
986
|
+
// failures are logged, never thrown — autostart is best-effort.
|
|
987
|
+
const WIN_RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
988
|
+
const WIN_RUN_NAME = "CiCy Desktop";
|
|
989
|
+
function ensureWindowsRunKey(want, command) {
|
|
990
|
+
try {
|
|
991
|
+
const { execFile } = require("child_process");
|
|
992
|
+
const args = want
|
|
993
|
+
? ["add", WIN_RUN_KEY, "/v", WIN_RUN_NAME, "/t", "REG_SZ", "/d", command, "/f"]
|
|
994
|
+
: ["delete", WIN_RUN_KEY, "/v", WIN_RUN_NAME, "/f"];
|
|
995
|
+
execFile("reg", args, { windowsHide: true }, (err) => {
|
|
996
|
+
// deleting an absent value exits non-zero — that is the wanted end state.
|
|
997
|
+
if (err && want) log.warn(`[autostart] Run-key fallback failed: ${err.message}`);
|
|
998
|
+
else if (want) log.info(`[autostart] Run-key fallback wrote ${WIN_RUN_NAME} → ${command}`);
|
|
999
|
+
});
|
|
1000
|
+
} catch (e) {
|
|
1001
|
+
log.warn(`[autostart] Run-key fallback threw: ${e.message}`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
977
1005
|
// 源码模式 Windows 登录自启的隐藏启动器(VBS)。写到 %LOCALAPPDATA%\cicy-desktop,幂等覆盖。
|
|
978
1006
|
// 继承当前的 CICY_DEBUG(用 start-cicy-desktop-win.bat 起的就带 =1),其余环境用登录时的用户环境。
|
|
979
1007
|
function writeSourceAutostartVbs() {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright 2026 CiCy AI
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Windows autostart had no test and never worked. Measured across the fleet:
|
|
5
|
+
// app.setLoginItemSettings({openAtLogin:true}) returns without throwing, yet
|
|
6
|
+
// getLoginItemSettings() still reports false and HKCU\...\Run stays untouched
|
|
7
|
+
// (the key exists and is writable — OneDrive lives there). So every Windows node
|
|
8
|
+
// ran with no autostart at all, which is why one whose app went away never came
|
|
9
|
+
// back, not even after a reboot. ensureAutoLaunch() now reads the setting back
|
|
10
|
+
// and owns the Run entry itself when the API did not take.
|
|
11
|
+
const test = require("node:test");
|
|
12
|
+
const assert = require("node:assert/strict");
|
|
13
|
+
const fs = require("node:fs");
|
|
14
|
+
const path = require("node:path");
|
|
15
|
+
|
|
16
|
+
const src = fs.readFileSync(path.join(__dirname, "..", "src", "main.js"), "utf8");
|
|
17
|
+
const fn = src.slice(
|
|
18
|
+
src.indexOf("function ensureAutoLaunch()"),
|
|
19
|
+
src.indexOf("function ensureWindowsRunKey")
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
test("windows autostart verifies the setting instead of trusting the API", () => {
|
|
23
|
+
// A single getLoginItemSettings() call before the write is not enough — the
|
|
24
|
+
// regression is entirely in what happens AFTER setLoginItemSettings().
|
|
25
|
+
assert.match(fn, /const probe = \(\) =>/);
|
|
26
|
+
assert.match(fn, /if \(probe\(\)\.openAtLogin !== want\) \{[^]*setLoginItemSettings\(opts\)/);
|
|
27
|
+
assert.match(fn, /if \(probe\(\)\.openAtLogin !== want\) ensureWindowsRunKey\(want, runCmd\)/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("the Run-key command differs for packaged vs source runs", () => {
|
|
31
|
+
// Packaged: the exe itself, hidden. Source: wscript running the VBS launcher,
|
|
32
|
+
// because starting electron.exe directly skips bin/cicy-desktop's master boot.
|
|
33
|
+
assert.match(fn, /runCmd = `"\$\{process\.execPath\}" --hidden`/);
|
|
34
|
+
assert.match(fn, /runCmd = `wscript\.exe \/\/B \/\/Nologo "\$\{vbs\}"`/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("ensureWindowsRunKey adds or removes the HKCU Run value, async and non-fatal", () => {
|
|
38
|
+
const helper = src.slice(
|
|
39
|
+
src.indexOf("function ensureWindowsRunKey"),
|
|
40
|
+
src.indexOf("// 源码模式 Windows 登录自启")
|
|
41
|
+
);
|
|
42
|
+
assert.match(
|
|
43
|
+
src,
|
|
44
|
+
/WIN_RUN_KEY = "HKCU\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run"/
|
|
45
|
+
);
|
|
46
|
+
assert.match(
|
|
47
|
+
helper,
|
|
48
|
+
/\["add", WIN_RUN_KEY, "\/v", WIN_RUN_NAME, "\/t", "REG_SZ", "\/d", command, "\/f"\]/
|
|
49
|
+
);
|
|
50
|
+
assert.match(helper, /\["delete", WIN_RUN_KEY, "\/v", WIN_RUN_NAME, "\/f"\]/);
|
|
51
|
+
assert.match(helper, /execFile\("reg", args, \{ windowsHide: true \}/); // no console flash, no startup stall
|
|
52
|
+
assert.match(helper, /catch \(e\) \{[^]*log\.warn/); // best-effort: never throws into startup
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("autostart still defaults to on and is honoured per-platform", () => {
|
|
56
|
+
assert.match(fn, /const want = prefs\.openAtLogin !== false/);
|
|
57
|
+
assert.match(fn, /if \(process\.platform === "darwin"\)/);
|
|
58
|
+
assert.match(fn, /else if \(process\.platform === "linux"\)/);
|
|
59
|
+
});
|