@aivin-labs/cli 1.0.27 → 1.0.30
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/README.md +7 -50
- package/bin/cli.mjs +66 -12
- package/bin/lib/context.mjs +61 -113
- package/bin/lib/remote/autoStart.mjs +2 -2
- package/bin/lib/remote/client.mjs +45 -30
- package/bin/lib/remote/constants.mjs +2 -0
- package/bin/lib/remote/credentials.mjs +138 -152
- package/bin/lib/remote/desktop/desktopCastSource.mjs +8 -2
- package/bin/lib/remote/desktop/index.mjs +22 -5
- package/bin/lib/remote/desktop/strings.mjs +10 -0
- package/bin/lib/remote/desktop/traySource.mjs +1127 -976
- package/bin/lib/remote/desktop/uninstall.mjs +1 -1
- package/bin/lib/remote/gui/index.mjs +6 -3
- package/bin/lib/remote/processes.mjs +14 -4
- package/bin/lib/remote/sandbox.mjs +2 -1
- package/bin/lib/remote/tokenRotation.mjs +3 -3
- package/bin/lib/remote/tokenStore.mjs +4 -4
- package/bin/lib/remote/toolHandlers.mjs +8 -2
- package/bin/lib/servers.mjs +69 -0
- package/docs/AIVIN_MASCOT.md +2 -2
- package/docs/CLI.md +1600 -1576
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-mission-flow.png +0 -0
- package/docs/media/cli-capabilities.png +0 -0
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ import { randomUUID } from 'crypto';
|
|
|
6
6
|
import { DEVICE_API_PREFIX, DEVICE_CREDENTIALS_FILE, DEVICE_ID_FILE, REMOTE_CONFIG_DIR } from './constants.mjs';
|
|
7
7
|
import { parseApiKeyClient } from '../auth.mjs';
|
|
8
8
|
import { TokenStoreKind, forgetToken, openToken, preferredTokenStore, sealToken } from './tokenStore.mjs';
|
|
9
|
-
import { writeFileAtomic } from './atomicFile.mjs';
|
|
9
|
+
import { writeFileAtomic } from './atomicFile.mjs';
|
|
10
|
+
import { DEFAULT_SERVER_URL, readActiveServer, resolveServerUrl, serverKey, setActiveServer } from '../servers.mjs';
|
|
10
11
|
|
|
11
12
|
/** Mã máy ổn định (~/.aivin/device-id.json), giữ qua các lần chạy. */
|
|
12
13
|
export function getOrCreateDeviceId() {
|
|
@@ -25,7 +26,7 @@ export function resetDeviceId() {
|
|
|
25
26
|
fs.mkdirSync(REMOTE_CONFIG_DIR, { recursive: true });
|
|
26
27
|
const deviceId = `dev-${randomUUID()}`;
|
|
27
28
|
fs.writeFileSync(DEVICE_ID_FILE, JSON.stringify({ deviceId, hostname: os.hostname(), createdAt: new Date().toISOString() }, null, 2) + '\n');
|
|
28
|
-
|
|
29
|
+
clearAllDeviceCredentials();
|
|
29
30
|
return deviceId;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -33,155 +34,139 @@ export function resetDeviceId() {
|
|
|
33
34
|
* Token đã giải theo nội dung tệp — giải DPAPI / Keychain tốn một tiến trình con (~0,5 s) mà tệp được đọc ở nhiều chỗ (mỗi lời gọi REST
|
|
34
35
|
* lấy tenant từ token). Tệp đổi (ghép lại / xoay token / tiến trình khác ghi) → giải lại.
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
if (data
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
if (disk.
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const { fallback_reason: reason, ...stored } = sealed;
|
|
117
|
-
const raw = writeRecord({ ...rest, ...stored, ...kept, ...(reason ? { seal_failed: { at: Date.now(), reason } } : {}) });
|
|
118
|
-
opened
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
export function
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
export function
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return data ? openToken(data) : null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Xoá token đã lưu. `onlyToken`: chỉ xoá khi tệp còn đúng token đó — daemon cũ (token vừa hết hiệu lực vì máy được ghép lại, vd chạy
|
|
174
|
-
* lại bộ cài trong lúc bản cũ còn nhận việc) không được xoá token MỚI mà daemon mới vừa ghi (chạy thật 26/10/2026: lần khởi động sau mất
|
|
175
|
-
* kết nối).
|
|
176
|
-
*/
|
|
177
|
-
export function clearDeviceCredentials(onlyToken) {
|
|
178
|
-
if (onlyToken && loadDeviceCredentials()?.device_token !== onlyToken) return false;
|
|
179
|
-
forgetToken(readRecord()?.data);
|
|
180
|
-
try { fs.unlinkSync(DEVICE_CREDENTIALS_FILE); } catch { /* không có thì thôi */ }
|
|
181
|
-
opened = { raw: null, token: null };
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
37
|
+
const opened = new Map();
|
|
38
|
+
|
|
39
|
+
function readStore() {
|
|
40
|
+
try { const raw = fs.readFileSync(DEVICE_CREDENTIALS_FILE, 'utf8'); return { raw, data: JSON.parse(raw) }; }
|
|
41
|
+
catch { return null; }
|
|
42
|
+
}
|
|
43
|
+
function resolveCredentialServer(serverUrl) {
|
|
44
|
+
if (serverUrl) return resolveServerUrl(serverUrl);
|
|
45
|
+
const configured = process.env.AIVIN_BASE_URL || process.env.AIVIN_SERVER || readActiveServer();
|
|
46
|
+
if (configured) return resolveServerUrl(configured);
|
|
47
|
+
const store = readStore()?.data;
|
|
48
|
+
if (store?.device_id) return resolveServerUrl(store.server_url || DEFAULT_SERVER_URL);
|
|
49
|
+
const entries = Object.values(store?.servers || {});
|
|
50
|
+
if (entries.length === 1 && entries[0]?.server_url) return resolveServerUrl(entries[0].server_url);
|
|
51
|
+
return DEFAULT_SERVER_URL;
|
|
52
|
+
}
|
|
53
|
+
function readRecord(serverUrl) {
|
|
54
|
+
const url = resolveCredentialServer(serverUrl); const file = readStore();
|
|
55
|
+
if (!file?.data) return null;
|
|
56
|
+
if (file.data.servers && typeof file.data.servers === 'object') {
|
|
57
|
+
const data = file.data.servers[serverKey(url)];
|
|
58
|
+
return data ? { raw: file.raw, data, store: file.data, serverUrl: url } : null;
|
|
59
|
+
}
|
|
60
|
+
if (file.data.device_id && resolveServerUrl(file.data.server_url || DEFAULT_SERVER_URL) === url)
|
|
61
|
+
return { raw: file.raw, data: file.data, store: file.data, legacy: true, serverUrl: url };
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function writeRecord(record, serverUrl) {
|
|
65
|
+
const url = resolveCredentialServer(serverUrl || record.server_url); const current = readStore()?.data;
|
|
66
|
+
let store;
|
|
67
|
+
if (current?.servers && typeof current.servers === 'object') store = { ...current, servers: { ...current.servers } };
|
|
68
|
+
else {
|
|
69
|
+
store = { version: 2, servers: {} };
|
|
70
|
+
if (current?.device_id) { const oldUrl = resolveServerUrl(current.server_url || DEFAULT_SERVER_URL); store.servers[serverKey(oldUrl)] = current; }
|
|
71
|
+
}
|
|
72
|
+
store.version = 2; store.servers[serverKey(url)] = record;
|
|
73
|
+
const raw = JSON.stringify(store, null, 2) + '\n';
|
|
74
|
+
writeFileAtomic(DEVICE_CREDENTIALS_FILE, raw);
|
|
75
|
+
try { fs.chmodSync(DEVICE_CREDENTIALS_FILE, 0o600); } catch { /* Windows ACL follows the user profile */ }
|
|
76
|
+
return raw;
|
|
77
|
+
}
|
|
78
|
+
const DISK_OWNED_FIELDS = ['previous_sealed', 'policy_sealed_at'];
|
|
79
|
+
const SEAL_RETRY_MS = 24 * 3600_000;
|
|
80
|
+
const tokenAccount = (deviceId, url) => `${deviceId}:${serverKey(url)}`;
|
|
81
|
+
function sealPrevious(token, deviceId, url) {
|
|
82
|
+
const account = `${tokenAccount(deviceId, url)}:previous`;
|
|
83
|
+
const { fallback_reason: _why, ...sealed } = sealToken(token, { account });
|
|
84
|
+
return { ...sealed, account };
|
|
85
|
+
}
|
|
86
|
+
const openPrevious = (rec) => (rec && typeof rec === 'object' ? openToken({ ...rec, device_id: rec.account, token_account: rec.account }) : null);
|
|
87
|
+
const forgetPrevious = (rec) => { if (rec && typeof rec === 'object') forgetToken({ ...rec, device_id: rec.account, token_account: rec.account }); };
|
|
88
|
+
const clearOpened = (url) => opened.delete(serverKey(url));
|
|
89
|
+
|
|
90
|
+
export function loadDeviceCredentials(serverUrl) {
|
|
91
|
+
const url = resolveCredentialServer(serverUrl); const key = serverKey(url); const rec = readRecord(url);
|
|
92
|
+
if (!rec?.data) return null;
|
|
93
|
+
const { data, raw } = rec; const cached = opened.get(key);
|
|
94
|
+
if (cached?.raw === raw && cached.token) return { ...data, server_url: url, device_token: cached.token };
|
|
95
|
+
const token = openToken({ ...data, token_account: data.token_account || data.device_id });
|
|
96
|
+
if (!token) return null;
|
|
97
|
+
opened.set(key, { raw, token });
|
|
98
|
+
const retrySeal = !data.seal_failed || Date.now() - Number(data.seal_failed.at || 0) > SEAL_RETRY_MS;
|
|
99
|
+
if (data.device_token && preferredTokenStore() !== TokenStoreKind.FILE && retrySeal) {
|
|
100
|
+
saveDeviceCredentials({ ...data, server_url: url, device_token: token });
|
|
101
|
+
return { ...readRecord(url)?.data, server_url: url, device_token: token };
|
|
102
|
+
}
|
|
103
|
+
return { ...data, server_url: url, device_token: token };
|
|
104
|
+
}
|
|
105
|
+
export function saveDeviceCredentials(creds, { previousToken } = {}) {
|
|
106
|
+
const url = resolveCredentialServer(creds.server_url); const key = serverKey(url); const account = tokenAccount(creds.device_id, url);
|
|
107
|
+
const { device_token: token, token_store: _s, token_enc: _e, seal_failed: _f, ...rest } = creds;
|
|
108
|
+
for (const f of DISK_OWNED_FIELDS) delete rest[f]; delete rest.token_account;
|
|
109
|
+
const disk = readRecord(url)?.data || {}; const kept = {};
|
|
110
|
+
if (disk.device_id === creds.device_id && disk.previous_sealed) kept.previous_sealed = disk.previous_sealed;
|
|
111
|
+
if (disk.device_id === creds.device_id && disk.policy_sealed_at) kept.policy_sealed_at = disk.policy_sealed_at;
|
|
112
|
+
if (previousToken !== undefined) {
|
|
113
|
+
if (kept.previous_sealed) forgetPrevious(kept.previous_sealed);
|
|
114
|
+
delete kept.previous_sealed;
|
|
115
|
+
if (previousToken) kept.previous_sealed = sealPrevious(previousToken, creds.device_id, url);
|
|
116
|
+
}
|
|
117
|
+
const sealed = sealToken(token, { account }); const { fallback_reason: reason, ...stored } = sealed;
|
|
118
|
+
const raw = writeRecord({ ...rest, server_url: url, token_account: account, ...stored, ...kept, ...(reason ? { seal_failed: { at: Date.now(), reason } } : {}) }, url);
|
|
119
|
+
opened.set(key, { raw, token }); return reason || null;
|
|
120
|
+
}
|
|
121
|
+
export function pendingPreviousToken(serverUrl) { return openPrevious(readRecord(serverUrl)?.data?.previous_sealed); }
|
|
122
|
+
export function confirmTokenRotation(currentToken, serverUrl) {
|
|
123
|
+
if (!readRecord(serverUrl)?.data?.previous_sealed) return false;
|
|
124
|
+
const creds = loadDeviceCredentials(serverUrl);
|
|
125
|
+
if (!creds || (currentToken && creds.device_token !== currentToken)) return false;
|
|
126
|
+
saveDeviceCredentials(creds, { previousToken: null }); return true;
|
|
127
|
+
}
|
|
128
|
+
export function revertTokenRotation(failedToken, serverUrl) {
|
|
129
|
+
const creds = loadDeviceCredentials(serverUrl);
|
|
130
|
+
if (!creds || (failedToken && creds.device_token !== failedToken)) return null;
|
|
131
|
+
const previous = pendingPreviousToken(serverUrl);
|
|
132
|
+
if (!previous || previous === creds.device_token) return null;
|
|
133
|
+
saveDeviceCredentials({ ...creds, device_token: previous }, { previousToken: null });
|
|
134
|
+
return readStoredTokenFresh(serverUrl) === previous ? previous : null;
|
|
135
|
+
}
|
|
136
|
+
export function notePolicySealed(serverUrl) {
|
|
137
|
+
const url = resolveCredentialServer(serverUrl); const rec = readRecord(url);
|
|
138
|
+
if (!rec?.data || rec.data.policy_sealed_at) return;
|
|
139
|
+
try {
|
|
140
|
+
const raw = writeRecord({ ...rec.data, policy_sealed_at: new Date().toISOString() }, url);
|
|
141
|
+
const cached = opened.get(serverKey(url)); if (cached?.raw === rec.raw) opened.set(serverKey(url), { raw, token: cached.token });
|
|
142
|
+
} catch { /* daemon still remembers it in memory */ }
|
|
143
|
+
}
|
|
144
|
+
export function policySealedNoted(serverUrl) { return !!readRecord(serverUrl)?.data?.policy_sealed_at; }
|
|
145
|
+
export function readStoredTokenFresh(serverUrl) {
|
|
146
|
+
const data = readRecord(serverUrl)?.data;
|
|
147
|
+
return data ? openToken({ ...data, token_account: data.token_account || data.device_id }) : null;
|
|
148
|
+
}
|
|
149
|
+
export function clearDeviceCredentials(onlyToken, serverUrl) {
|
|
150
|
+
const url = resolveCredentialServer(serverUrl); const rec = readRecord(url);
|
|
151
|
+
if (onlyToken && loadDeviceCredentials(url)?.device_token !== onlyToken) return false;
|
|
152
|
+
if (rec?.data) {
|
|
153
|
+
forgetToken({ ...rec.data, token_account: rec.data.token_account || rec.data.device_id }); forgetPrevious(rec.data.previous_sealed);
|
|
154
|
+
const store = rec.store?.servers ? { ...rec.store, servers: { ...rec.store.servers } } : { version: 2, servers: {} };
|
|
155
|
+
delete store.servers[serverKey(url)];
|
|
156
|
+
if (Object.keys(store.servers).length) {
|
|
157
|
+
const raw = JSON.stringify(store, null, 2) + '\n'; writeFileAtomic(DEVICE_CREDENTIALS_FILE, raw);
|
|
158
|
+
try { fs.chmodSync(DEVICE_CREDENTIALS_FILE, 0o600); } catch { /* Windows ACL follows the user profile */ }
|
|
159
|
+
} else { try { fs.unlinkSync(DEVICE_CREDENTIALS_FILE); } catch { /* already clear */ } }
|
|
160
|
+
}
|
|
161
|
+
clearOpened(url); return true;
|
|
162
|
+
}
|
|
163
|
+
export function clearAllDeviceCredentials() {
|
|
164
|
+
const store = readStore()?.data;
|
|
165
|
+
const records = store?.servers ? Object.values(store.servers) : store?.device_id ? [store] : [];
|
|
166
|
+
for (const rec of records) { forgetToken({ ...rec, token_account: rec.token_account || rec.device_id }); forgetPrevious(rec.previous_sealed); }
|
|
167
|
+
try { fs.unlinkSync(DEVICE_CREDENTIALS_FILE); } catch { /* already clear */ }
|
|
168
|
+
opened.clear(); return true;
|
|
169
|
+
}
|
|
185
170
|
/**
|
|
186
171
|
* Máy tính tổ chức: BE cấp token thiết bị lúc tạo container và đặt vào env (`AIVIN_DEVICE_TOKEN` / `AIVIN_DEVICE_ID` / `AIVIN_SERVER`) — không
|
|
187
172
|
* ghép máy, không ghi tệp token. Thiếu biến → `null`.
|
|
@@ -189,7 +174,7 @@ export function clearDeviceCredentials(onlyToken) {
|
|
|
189
174
|
export function credentialsFromEnv(env = process.env) {
|
|
190
175
|
const token = String(env.AIVIN_DEVICE_TOKEN || '').trim();
|
|
191
176
|
const deviceId = String(env.AIVIN_DEVICE_ID || '').trim();
|
|
192
|
-
const serverUrl = String(env.AIVIN_SERVER || '').trim().
|
|
177
|
+
const serverUrl = String(env.AIVIN_SERVER || '').trim() ? resolveServerUrl(String(env.AIVIN_SERVER).trim()) : '';
|
|
193
178
|
if (!token || !deviceId || !serverUrl) return null;
|
|
194
179
|
return { device_token: token, device_id: deviceId, name: String(env.AIVIN_DEVICE_NAME || deviceId), server_url: serverUrl };
|
|
195
180
|
}
|
|
@@ -262,6 +247,7 @@ function savePairResult(res, { serverUrl, deviceId, roots, name }) {
|
|
|
262
247
|
lang: data.user_lang || data.lang || undefined,
|
|
263
248
|
};
|
|
264
249
|
saveDeviceCredentials(creds);
|
|
250
|
+
setActiveServer(serverUrl);
|
|
265
251
|
return creds;
|
|
266
252
|
}
|
|
267
253
|
|
|
@@ -114,10 +114,15 @@ namespace AivinDesktopCast {
|
|
|
114
114
|
static class Out {
|
|
115
115
|
static readonly object gate = new object();
|
|
116
116
|
static readonly JavaScriptSerializer json = new JavaScriptSerializer { MaxJsonLength = int.MaxValue };
|
|
117
|
+
// stdin/stdout là ống (không console): Console.In/Out mặc định theo bảng mã OEM (437…) còn Node đọc/ghi UTF-8 — 06/11/2026 gõ
|
|
118
|
+
// "tôi đang gõ tiếng Việt" từ xa ra "t├┤i ─æang g├╡ ti├ß║┐ng". Mở luồng chuẩn với UTF-8 (không BOM) khai rõ ràng.
|
|
119
|
+
static readonly UTF8Encoding utf8 = new UTF8Encoding(false);
|
|
120
|
+
static readonly StreamWriter stdout = new StreamWriter(Console.OpenStandardOutput(), utf8);
|
|
121
|
+
public static readonly StreamReader Stdin = new StreamReader(Console.OpenStandardInput(), utf8);
|
|
117
122
|
|
|
118
123
|
public static void Send(Dictionary<string, object> msg) {
|
|
119
124
|
string line = json.Serialize(msg);
|
|
120
|
-
lock (gate) {
|
|
125
|
+
lock (gate) { stdout.WriteLine(line); stdout.Flush(); }
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
public static Dictionary<string, object> Parse(string text) {
|
|
@@ -509,7 +514,7 @@ namespace AivinDesktopCast {
|
|
|
509
514
|
static void ReadInputLoop() {
|
|
510
515
|
try {
|
|
511
516
|
string line;
|
|
512
|
-
while (running && (line =
|
|
517
|
+
while (running && (line = Out.Stdin.ReadLine()) != null) {
|
|
513
518
|
line = line.Trim();
|
|
514
519
|
if (string.IsNullOrEmpty(line)) continue;
|
|
515
520
|
if (line == "stop") {
|
|
@@ -900,6 +905,7 @@ if ($dll -and (Test-Path -LiteralPath $dll)) {
|
|
|
900
905
|
Add-Type -TypeDefinition ([IO.File]::ReadAllText($src)) -ReferencedAssemblies $refs -OutputAssembly $dll -OutputType Library
|
|
901
906
|
Add-Type -Path $dll
|
|
902
907
|
}
|
|
908
|
+
try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false) } catch {}
|
|
903
909
|
try {
|
|
904
910
|
[AivinDesktopCast.CastHost]::Run($env:AIVIN_CAST_ARGS)
|
|
905
911
|
} catch {
|
|
@@ -149,7 +149,7 @@ export function unregisterStartup() {
|
|
|
149
149
|
|
|
150
150
|
// --- Biên dịch Aivin.exe + lối tắt Start menu ------------------------------------------------------------------------------------
|
|
151
151
|
|
|
152
|
-
const SETUP_PS1 = `param([string]$Src, [string]$Ico, [string]$Out, [string]$Lnk, [string]$Target, [string]$Desc, [string]$LnkArgs)
|
|
152
|
+
const SETUP_PS1 = `param([string]$Src, [string]$Ico, [string]$Out, [string]$Lnk, [string]$Target, [string]$Desc, [string]$LnkArgs, [string]$DesktopLnkName, [string]$RemoveDesktopLnkName)
|
|
153
153
|
$ErrorActionPreference = 'Stop'
|
|
154
154
|
if ($Src) {
|
|
155
155
|
$p = New-Object System.CodeDom.Compiler.CompilerParameters
|
|
@@ -160,9 +160,9 @@ if ($Src) {
|
|
|
160
160
|
$r = (New-Object Microsoft.CSharp.CSharpCodeProvider).CompileAssemblyFromSource($p, [IO.File]::ReadAllText($Src, [Text.Encoding]::UTF8))
|
|
161
161
|
if ($r.Errors.HasErrors) { $r.Errors | Where-Object { -not $_.IsWarning } | ForEach-Object { [Console]::Error.WriteLine($_.ToString()) }; exit 1 }
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
New-Item -ItemType Directory -Force -Path (Split-Path $
|
|
165
|
-
$s = (New-Object -ComObject WScript.Shell).CreateShortcut($
|
|
163
|
+
function New-AivinShortcut($Path) {
|
|
164
|
+
New-Item -ItemType Directory -Force -Path (Split-Path $Path) | Out-Null
|
|
165
|
+
$s = (New-Object -ComObject WScript.Shell).CreateShortcut($Path)
|
|
166
166
|
$s.TargetPath = $Target
|
|
167
167
|
if ($LnkArgs) { $s.Arguments = $LnkArgs }
|
|
168
168
|
$s.IconLocation = "$Target,0"
|
|
@@ -170,6 +170,11 @@ if ($Lnk) {
|
|
|
170
170
|
$s.Description = $Desc
|
|
171
171
|
$s.Save()
|
|
172
172
|
}
|
|
173
|
+
if ($Lnk) { New-AivinShortcut $Lnk }
|
|
174
|
+
$shell = New-Object -ComObject WScript.Shell
|
|
175
|
+
$desktopPath = $shell.SpecialFolders.Item('Desktop')
|
|
176
|
+
if ($DesktopLnkName) { New-AivinShortcut (Join-Path $desktopPath $DesktopLnkName) }
|
|
177
|
+
if ($RemoveDesktopLnkName) { Remove-Item -LiteralPath (Join-Path $desktopPath $RemoveDesktopLnkName) -Force -ErrorAction SilentlyContinue }
|
|
173
178
|
`;
|
|
174
179
|
|
|
175
180
|
function runSetup(params, dir) {
|
|
@@ -230,6 +235,16 @@ export function ensureStartMenuShortcut({ exe = launcherExePath(), lnk = startMe
|
|
|
230
235
|
return lnk;
|
|
231
236
|
}
|
|
232
237
|
|
|
238
|
+
export function desktopShortcutName() {
|
|
239
|
+
return `${DISPLAY_NAME}.lnk`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function ensureDesktopShortcut({ exe = launcherExePath(), lang = 'en', dir = DESKTOP_DIR } = {}) {
|
|
243
|
+
const name = desktopShortcutName();
|
|
244
|
+
runSetup({ DesktopLnkName: name, Target: exe, Desc: trayStrings(lang).shortcut }, dir);
|
|
245
|
+
return name;
|
|
246
|
+
}
|
|
247
|
+
|
|
233
248
|
/** Lối tắt trong "Send to" (chuột phải → Send to → AIVIN Bot): Aivin.exe --share <các tệp> — một lần cho cả nhóm tệp đã chọn. */
|
|
234
249
|
export function sendToShortcutPath(env = process.env) {
|
|
235
250
|
return path.join(env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), 'Microsoft', 'Windows', 'SendTo', `${DISPLAY_NAME}.lnk`);
|
|
@@ -329,12 +344,13 @@ export function installDesktop({ argv, rollback = null, lang = 'en', autostart =
|
|
|
329
344
|
const lnk = startMenuShortcutPath();
|
|
330
345
|
for (const p of legacyStartMenuShortcutPaths()) fs.rmSync(p, { force: true });
|
|
331
346
|
if (built || !fs.existsSync(lnk)) ensureStartMenuShortcut({ exe, lnk, lang });
|
|
347
|
+
const desktopShortcut = ensureDesktopShortcut({ exe, lang });
|
|
332
348
|
if (autostart) registerStartup(exe);
|
|
333
349
|
const openWith = registerOpenWith(exe, lang);
|
|
334
350
|
if (launch && built) quitRunningTray({ exe });
|
|
335
351
|
else if (launch) restartListener();
|
|
336
352
|
if (launch) launchTray({ exe, mode: launchMode });
|
|
337
|
-
return { exe, shortcut: lnk, built, autostart: startupState().enabled, openWith };
|
|
353
|
+
return { exe, shortcut: lnk, desktopShortcut, built, autostart: startupState().enabled, openWith };
|
|
338
354
|
}
|
|
339
355
|
|
|
340
356
|
/** "Mở bằng / Gửi cho AIVIN Bot" (fileAssociation.mjs) + lối tắt Send to — lỗi registry không làm hỏng cả bước cài. */
|
|
@@ -361,6 +377,7 @@ export function uninstallDesktop({ wait = sleepSync } = {}) {
|
|
|
361
377
|
unregisterFileAssociations();
|
|
362
378
|
unregisterUninstallEntry();
|
|
363
379
|
fs.rmSync(startMenuShortcutPath(), { force: true });
|
|
380
|
+
try { runSetup({ RemoveDesktopLnkName: desktopShortcutName() }, DESKTOP_DIR); } catch { /* shortcut may already be gone or desktop unavailable */ }
|
|
364
381
|
fs.rmSync(sendToShortcutPath(), { force: true });
|
|
365
382
|
for (const p of legacyStartMenuShortcutPaths()) fs.rmSync(p, { force: true });
|
|
366
383
|
for (let i = 0; i < 20 && fs.existsSync(exe); i++) {
|
|
@@ -10,6 +10,11 @@ export const TRAY_STRINGS = Object.freeze({
|
|
|
10
10
|
quickChat: 'Quick chat',
|
|
11
11
|
quickVoice: 'Quick voice',
|
|
12
12
|
terminal: 'Mở Terminal',
|
|
13
|
+
server: 'Máy chủ',
|
|
14
|
+
serverCloud: 'Cloud',
|
|
15
|
+
serverVn: 'VN',
|
|
16
|
+
serverLocal: 'Local',
|
|
17
|
+
serverConfirm: 'Đổi máy chủ sang {server}? Việc đang chạy trên máy này sẽ bị dừng.',
|
|
13
18
|
connect: 'Kết nối máy này…',
|
|
14
19
|
pause: 'Tạm dừng nhận việc',
|
|
15
20
|
resume: 'Tiếp tục nhận việc',
|
|
@@ -49,6 +54,11 @@ export const TRAY_STRINGS = Object.freeze({
|
|
|
49
54
|
quickChat: 'Quick chat',
|
|
50
55
|
quickVoice: 'Quick voice',
|
|
51
56
|
terminal: 'Open Terminal',
|
|
57
|
+
server: 'Server',
|
|
58
|
+
serverCloud: 'Cloud',
|
|
59
|
+
serverVn: 'VN',
|
|
60
|
+
serverLocal: 'Local',
|
|
61
|
+
serverConfirm: 'Switch to {server}? Current work on this computer will be stopped.',
|
|
52
62
|
connect: 'Connect this computer…',
|
|
53
63
|
pause: 'Pause work',
|
|
54
64
|
resume: 'Resume work',
|