@michengai/dsh-im-connect 0.1.34 → 0.1.37
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/CHANGELOG.md +16 -1
- package/CHANGELOG.zh-CN.md +16 -1
- package/README.en.md +4 -0
- package/README.md +4 -0
- package/client.js +40 -5
- package/lib/client.js +334 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/plugin-updater.d.ts +22 -0
- package/lib/plugin-updater.d.ts.map +1 -0
- package/lib/plugin-updater.js +277 -0
- package/lib/plugin-updater.js.map +1 -0
- package/package.json +5 -2
- package/src/index.ts +6 -0
- package/src/plugin-update-ui.js +293 -0
- package/src/plugin-updater.ts +259 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { basename, dirname, isAbsolute, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
export const PLUGIN_UPDATE_HEADER = 'x-michengai-plugin-update';
|
|
8
|
+
export const PLUGIN_UPDATE_IPC = 'apply-plugin-updates';
|
|
9
|
+
function header(request, name) {
|
|
10
|
+
const value = request.headers?.[name];
|
|
11
|
+
return Array.isArray(value) ? value[0] : value;
|
|
12
|
+
}
|
|
13
|
+
function isLoopbackAddress(value) {
|
|
14
|
+
const address = value?.toLowerCase().replace(/^\[|\]$/g, '');
|
|
15
|
+
return address === 'localhost' || address === 'localhost.' || address === '::1'
|
|
16
|
+
|| address?.startsWith('127.') === true || address?.startsWith('::ffff:127.') === true;
|
|
17
|
+
}
|
|
18
|
+
export function isTrustedUpdateRequest(request) {
|
|
19
|
+
if (header(request, PLUGIN_UPDATE_HEADER) !== '1')
|
|
20
|
+
return false;
|
|
21
|
+
if (!isLoopbackAddress(request.socket?.remoteAddress))
|
|
22
|
+
return false;
|
|
23
|
+
const site = header(request, 'sec-fetch-site');
|
|
24
|
+
if (site !== undefined && site !== 'same-origin')
|
|
25
|
+
return false;
|
|
26
|
+
const origin = header(request, 'origin');
|
|
27
|
+
const host = header(request, 'host');
|
|
28
|
+
if (origin === undefined || host === undefined)
|
|
29
|
+
return false;
|
|
30
|
+
try {
|
|
31
|
+
const url = new URL(origin);
|
|
32
|
+
return (url.protocol === 'http:' || url.protocol === 'https:') && isLoopbackAddress(url.hostname) && url.host === host;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function validProfileName(value) {
|
|
39
|
+
return typeof value === 'string' && value !== '' && value !== '.' && value !== '..'
|
|
40
|
+
&& !value.includes('/') && !value.includes('\\') && !/[\0-\x1f\x7f]/.test(value);
|
|
41
|
+
}
|
|
42
|
+
function profileNameFromArgv(argv) {
|
|
43
|
+
for (let index = 2; index < argv.length; index += 1) {
|
|
44
|
+
if (argv[index] === '--profile')
|
|
45
|
+
return argv[index + 1];
|
|
46
|
+
if (argv[index]?.startsWith('--profile='))
|
|
47
|
+
return argv[index].slice('--profile='.length);
|
|
48
|
+
}
|
|
49
|
+
return argv[2] === 'web' ? 'web' : undefined;
|
|
50
|
+
}
|
|
51
|
+
export function isDshCliEntry(entry, manifest, packageRoot) {
|
|
52
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
53
|
+
return false;
|
|
54
|
+
const value = manifest;
|
|
55
|
+
if (value.name !== '@deepseek-ai/dsh')
|
|
56
|
+
return false;
|
|
57
|
+
const bin = typeof value.bin === 'string'
|
|
58
|
+
? value.bin
|
|
59
|
+
: typeof value.bin === 'object' && value.bin !== null
|
|
60
|
+
? value.bin.dsh
|
|
61
|
+
: undefined;
|
|
62
|
+
return typeof bin === 'string' && bin !== '' && !isAbsolute(bin) && resolve(packageRoot, bin) === resolve(entry);
|
|
63
|
+
}
|
|
64
|
+
function cliEntry() {
|
|
65
|
+
const value = process.argv[1];
|
|
66
|
+
if (value === undefined || value === '')
|
|
67
|
+
return undefined;
|
|
68
|
+
const entry = value.startsWith('file:') ? fileURLToPath(value) : resolve(process.cwd(), value);
|
|
69
|
+
if (!existsSync(entry))
|
|
70
|
+
return undefined;
|
|
71
|
+
for (let directory = dirname(entry);;) {
|
|
72
|
+
const manifestPath = resolve(directory, 'package.json');
|
|
73
|
+
if (existsSync(manifestPath)) {
|
|
74
|
+
try {
|
|
75
|
+
if (isDshCliEntry(entry, JSON.parse(readFileSync(manifestPath, 'utf8')), directory))
|
|
76
|
+
return entry;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Keep searching parent directories when a package manifest is unreadable.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const parent = dirname(directory);
|
|
83
|
+
if (parent === directory)
|
|
84
|
+
return undefined;
|
|
85
|
+
directory = parent;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function runtime(ctx) {
|
|
89
|
+
const profiles = ctx.get?.('desktopProfiles');
|
|
90
|
+
const desktopPnpm = ctx.get?.('desktopPnpm');
|
|
91
|
+
if (profiles?.current !== undefined) {
|
|
92
|
+
const current = profiles.current;
|
|
93
|
+
if (!validProfileName(current.name) || typeof current.dir !== 'string' || !isAbsolute(current.dir)) {
|
|
94
|
+
throw new Error('当前 Desktop Profile 信息无效,请重启后重试。');
|
|
95
|
+
}
|
|
96
|
+
return { profileName: current.name, profileDir: resolve(current.dir), ...(typeof desktopPnpm?.runPlugin === 'function' ? { desktopPnpm } : {}) };
|
|
97
|
+
}
|
|
98
|
+
const profileDir = resolve(process.env.DSH_PROFILE_DIR ?? resolve(homedir(), '.dsh', 'profiles', 'web'));
|
|
99
|
+
const selected = profileNameFromArgv(process.argv);
|
|
100
|
+
const profileName = validProfileName(selected) ? selected : validProfileName(basename(profileDir)) ? basename(profileDir) : 'web';
|
|
101
|
+
const entry = cliEntry();
|
|
102
|
+
return { profileName, profileDir, ...(entry === undefined ? {} : { cliEntry: entry }) };
|
|
103
|
+
}
|
|
104
|
+
function parseSemver(value) {
|
|
105
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(value);
|
|
106
|
+
if (match === null)
|
|
107
|
+
return undefined;
|
|
108
|
+
return { core: [Number(match[1]), Number(match[2]), Number(match[3])], prerelease: match[4]?.split('.') ?? [] };
|
|
109
|
+
}
|
|
110
|
+
export function isNewerVersion(currentValue, candidateValue) {
|
|
111
|
+
const current = parseSemver(currentValue);
|
|
112
|
+
const candidate = parseSemver(candidateValue);
|
|
113
|
+
if (current === undefined || candidate === undefined)
|
|
114
|
+
return false;
|
|
115
|
+
for (let index = 0; index < 3; index += 1) {
|
|
116
|
+
if (candidate.core[index] !== current.core[index])
|
|
117
|
+
return candidate.core[index] > current.core[index];
|
|
118
|
+
}
|
|
119
|
+
return comparePrerelease(candidate.prerelease, current.prerelease) > 0;
|
|
120
|
+
}
|
|
121
|
+
function comparePrerelease(left, right) {
|
|
122
|
+
if (left.length === 0 || right.length === 0)
|
|
123
|
+
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
124
|
+
const length = Math.max(left.length, right.length);
|
|
125
|
+
for (let index = 0; index < length; index += 1) {
|
|
126
|
+
const a = left[index];
|
|
127
|
+
const b = right[index];
|
|
128
|
+
if (a === undefined || b === undefined)
|
|
129
|
+
return a === b ? 0 : a === undefined ? -1 : 1;
|
|
130
|
+
if (a === b)
|
|
131
|
+
continue;
|
|
132
|
+
const aNumeric = /^\d+$/.test(a);
|
|
133
|
+
const bNumeric = /^\d+$/.test(b);
|
|
134
|
+
if (aNumeric && bNumeric) {
|
|
135
|
+
const aNumber = BigInt(a);
|
|
136
|
+
const bNumber = BigInt(b);
|
|
137
|
+
if (aNumber !== bNumber)
|
|
138
|
+
return aNumber > bNumber ? 1 : -1;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (aNumeric !== bNumeric)
|
|
142
|
+
return aNumeric ? -1 : 1;
|
|
143
|
+
return a > b ? 1 : -1;
|
|
144
|
+
}
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
let latestCache;
|
|
148
|
+
async function latestVersion(packageName) {
|
|
149
|
+
if (latestCache?.packageName === packageName && Date.now() < latestCache.expiresAt)
|
|
150
|
+
return latestCache.version;
|
|
151
|
+
try {
|
|
152
|
+
const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`, { signal: AbortSignal.timeout(8_000) });
|
|
153
|
+
if (!response.ok)
|
|
154
|
+
return undefined;
|
|
155
|
+
const value = await response.json();
|
|
156
|
+
if (typeof value.version !== 'string' || value.version === '')
|
|
157
|
+
return undefined;
|
|
158
|
+
latestCache = { packageName, version: value.version, expiresAt: Date.now() + 5 * 60_000 };
|
|
159
|
+
return value.version;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function currentVersion(manifestUrl) {
|
|
166
|
+
const value = JSON.parse(await readFile(manifestUrl, 'utf8'));
|
|
167
|
+
if (typeof value.version !== 'string' || value.version === '')
|
|
168
|
+
throw new Error('无法读取当前插件版本。');
|
|
169
|
+
return value.version;
|
|
170
|
+
}
|
|
171
|
+
async function status(options, target) {
|
|
172
|
+
const current = await currentVersion(options.manifestUrl);
|
|
173
|
+
const latest = await latestVersion(options.packageName);
|
|
174
|
+
return {
|
|
175
|
+
packageName: options.packageName,
|
|
176
|
+
currentVersion: current,
|
|
177
|
+
...(latest === undefined ? {} : { latestVersion: latest }),
|
|
178
|
+
latestCheckFailed: latest === undefined,
|
|
179
|
+
updateAvailable: latest !== undefined && isNewerVersion(current, latest),
|
|
180
|
+
profileName: target.profileName,
|
|
181
|
+
canAutoUpdate: target.desktopPnpm !== undefined || target.cliEntry !== undefined,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
async function runCliInstall(target, packageSpec) {
|
|
185
|
+
if (target.cliEntry === undefined)
|
|
186
|
+
throw new Error('当前环境不支持自动更新,请使用手工更新命令。');
|
|
187
|
+
await new Promise((resolvePromise, reject) => {
|
|
188
|
+
const child = spawn(process.execPath, [target.cliEntry, 'plugin', '--profile', target.profileName, 'add', '--config.minimumReleaseAge=0', packageSpec, '--registry=https://registry.npmjs.org/'], {
|
|
189
|
+
cwd: target.profileDir, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, NO_COLOR: '1' },
|
|
190
|
+
});
|
|
191
|
+
let detail = '';
|
|
192
|
+
child.stdout?.on('data', chunk => { detail = (detail + String(chunk)).slice(-4_000); });
|
|
193
|
+
child.stderr?.on('data', chunk => { detail = (detail + String(chunk)).slice(-4_000); });
|
|
194
|
+
const timer = setTimeout(() => { child.kill(); reject(new Error('更新超时,请改用手工更新。')); }, 10 * 60_000);
|
|
195
|
+
child.once('error', error => { clearTimeout(timer); reject(error); });
|
|
196
|
+
child.once('exit', code => {
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
if (code === 0)
|
|
199
|
+
resolvePromise();
|
|
200
|
+
else
|
|
201
|
+
reject(new Error(detail.trim() || `更新进程退出码 ${String(code)}`));
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
async function install(target, packageSpec) {
|
|
206
|
+
if (target.desktopPnpm === undefined)
|
|
207
|
+
return runCliInstall(target, packageSpec);
|
|
208
|
+
const handle = target.desktopPnpm.runPlugin(['add', '--config.minimumReleaseAge=0', packageSpec, '--registry=https://registry.npmjs.org/'], target.profileDir);
|
|
209
|
+
const result = await handle.done;
|
|
210
|
+
if (result.exitCode !== 0)
|
|
211
|
+
throw new Error(`更新进程退出码 ${String(result.exitCode)}。`);
|
|
212
|
+
}
|
|
213
|
+
function json(response, statusCode, value) {
|
|
214
|
+
response.writeHead(statusCode, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
215
|
+
response.end(JSON.stringify(value));
|
|
216
|
+
}
|
|
217
|
+
function publicError(error) {
|
|
218
|
+
const message = error instanceof Error ? error.message : '更新暂不可用。';
|
|
219
|
+
return /[A-Za-z]:[\\/]|\/(?:home|root|Users|var|tmp)\//.test(message) ? '更新失败,请查看服务端日志。' : message;
|
|
220
|
+
}
|
|
221
|
+
export function registerPluginUpdater(ctx, options) {
|
|
222
|
+
const host = ctx;
|
|
223
|
+
let installing = false;
|
|
224
|
+
return host.webServer.register({
|
|
225
|
+
kind: 'exact', path: options.endpoint,
|
|
226
|
+
handler: async (request, response) => {
|
|
227
|
+
try {
|
|
228
|
+
const target = runtime(host);
|
|
229
|
+
if (request.method === 'GET' || request.method === 'HEAD') {
|
|
230
|
+
const payload = await status(options, target);
|
|
231
|
+
response.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
232
|
+
response.end(request.method === 'HEAD' ? undefined : JSON.stringify(payload));
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (request.method !== 'POST') {
|
|
236
|
+
response.writeHead(405, { allow: 'GET, HEAD, POST' });
|
|
237
|
+
response.end();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!isTrustedUpdateRequest(request)) {
|
|
241
|
+
json(response, 403, { error: '已拒绝非本机同源更新请求。' });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (installing) {
|
|
245
|
+
json(response, 409, { error: '当前插件正在更新,请稍候。' });
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const before = await status(options, target);
|
|
249
|
+
if (before.latestVersion === undefined) {
|
|
250
|
+
json(response, 503, { error: '暂时无法获取最新版本。' });
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (!before.updateAvailable) {
|
|
254
|
+
json(response, 200, before);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
installing = true;
|
|
258
|
+
try {
|
|
259
|
+
await install(target, `${options.packageName}@${before.latestVersion}`);
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
installing = false;
|
|
263
|
+
}
|
|
264
|
+
const notifyParent = target.desktopPnpm === undefined && typeof process.send === 'function';
|
|
265
|
+
const autoReload = target.desktopPnpm !== undefined || notifyParent;
|
|
266
|
+
json(response, 200, { ...before, updatedVersion: before.latestVersion, restartRequired: true, autoReload });
|
|
267
|
+
if (notifyParent)
|
|
268
|
+
setTimeout(() => { process.send?.(PLUGIN_UPDATE_IPC); }, 150).unref?.();
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
ctx.logger.warn(`plugin updater failed: ${String(error)}`);
|
|
272
|
+
json(response, 503, { error: publicError(error) });
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=plugin-updater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-updater.js","sourceRoot":"","sources":["../src/plugin-updater.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,CAAA;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAA;AAsBvD,SAAS,MAAM,CAAC,OAAoB,EAAE,IAAY;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,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EAAE,cAAc,EAAE,MAAM,CAAC,aAAa,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAA;gBAC3G,IAAI,YAAY;oBAAE,UAAU,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,iBAAiB,CAAC,CAAA,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAA;YAC1F,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;gBAC1D,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YACpD,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-im-connect",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"description": "DeepSeek Harness IM 助理:把本机 agent 接到微信、企微、钉钉、飞书、QQ、Telegram,会话与网页任务分列。",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"packageManager": "pnpm@11.22.0",
|
|
6
7
|
"main": "lib/index.js",
|
|
7
8
|
"types": "lib/index.d.ts",
|
|
8
9
|
"exports": {
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
},
|
|
42
43
|
"license": "Apache-2.0",
|
|
43
44
|
"engines": {
|
|
44
|
-
"node": "
|
|
45
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"@larksuiteoapi/node-sdk": "^1.36.0",
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"@deepseek-ai/dsh-client-ui-primitives": ">=0.1.0-rc.5 <0.2.0",
|
|
59
60
|
"@deepseek-ai/dsh-client-ui-settings": ">=0.1.0-rc.5 <0.2.0",
|
|
60
61
|
"@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.5 <0.2.0",
|
|
62
|
+
"@deepseek-ai/dsh-host-webserver": ">=0.1.2-rc.1 <0.2.0",
|
|
61
63
|
"@deepseek-ai/schemastery": "^3.18.2"
|
|
62
64
|
},
|
|
63
65
|
"peerDependenciesMeta": {
|
|
@@ -72,6 +74,7 @@
|
|
|
72
74
|
"@deepseek-ai/dsh-client-ui-primitives": "0.1.2-rc.1",
|
|
73
75
|
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1",
|
|
74
76
|
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1",
|
|
77
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-rc.1",
|
|
75
78
|
"@deepseek-ai/schemastery": "^3.18.2",
|
|
76
79
|
"@types/node": "^22.10.0",
|
|
77
80
|
"@types/qrcode": "^1.5.6",
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { mkdirSync } from 'node:fs'
|
|
|
9
9
|
import { ChannelManager } from './manager.js'
|
|
10
10
|
import type { EngineConfig } from './engine/types.js'
|
|
11
11
|
import { createRotatingFileAppender } from './engine/file-log.js'
|
|
12
|
+
import { registerPluginUpdater } from './plugin-updater.js'
|
|
12
13
|
|
|
13
14
|
export const name = 'dsh-im-connect'
|
|
14
15
|
export const inject = [
|
|
@@ -40,6 +41,11 @@ export const Config: Schema<PluginConfig> = Schema.object({
|
|
|
40
41
|
})
|
|
41
42
|
|
|
42
43
|
export function apply(ctx: Context, config: PluginConfig): void {
|
|
44
|
+
ctx.effect(() => registerPluginUpdater(ctx, {
|
|
45
|
+
endpoint: '/api/michengai/dsh-im-connect/update',
|
|
46
|
+
packageName: '@michengai/dsh-im-connect',
|
|
47
|
+
manifestUrl: new URL('../package.json', import.meta.url),
|
|
48
|
+
}), 'im-connect.plugin-updater')
|
|
43
49
|
const permissionPresets = (ctx as Context & { permissionPresets: { defaultPreset: string } }).permissionPresets
|
|
44
50
|
const stateDir = config.stateDir !== ''
|
|
45
51
|
? config.stateDir
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
const UPDATE_HEADER = "x-michengai-plugin-update";
|
|
2
|
+
const STYLE_ID = "michengai-plugin-update-ui";
|
|
3
|
+
const CSS = `
|
|
4
|
+
.mpi-version{margin-left:8px;color:var(--dsw-alias-label-tertiary,#9da1aa);font-family:inherit;font-size:12px;font-weight:500;line-height:18px;letter-spacing:0;white-space:nowrap;vertical-align:baseline}.mpi-check{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:28px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2,#4b4d52);border-radius:7px;background:transparent;color:var(--dsw-alias-label-secondary,#b8bbc2);font:inherit;font-size:12px;font-weight:500;line-height:18px;white-space:nowrap;cursor:pointer}.mpi-check:hover{background:var(--dsw-alias-interactive-bg-hover,#3a3b3f);color:var(--dsw-alias-label-primary,#fff)}.mpi-check:focus-visible,.mpi-action:focus-visible,.mpi-dialog-close:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f8cff);outline-offset:2px}.mpi-icon{display:inline-flex;flex:0 0 auto;width:16px;height:16px;align-items:center;justify-content:center;pointer-events:none}.mpi-icon svg{display:block;width:16px;height:16px}
|
|
5
|
+
.mpi-overlay{position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(0,0,0,.62)}.mpi-dialog{position:relative;box-sizing:border-box;width:min(680px,100%);max-height:calc(100vh - 48px);overflow:auto;border:1px solid var(--dsw-alias-border-l2,#4b4d52);border-radius:14px;padding:22px;background:var(--dsw-alias-bg-layer-2,var(--dsw-specific-menu,#202124));color:var(--dsw-alias-label-primary,#fff);box-shadow:var(--dsw-shadow-lv3,0 16px 48px rgba(0,0,0,.24));font-family:inherit}.mpi-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.mpi-dialog h2{margin:0;font-size:18px;line-height:26px}.mpi-dialog-close{display:inline-flex;flex:0 0 28px;width:28px;height:28px;align-items:center;justify-content:center;padding:0;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary,#b8bbc2);cursor:pointer}.mpi-dialog-close:hover{background:var(--dsw-alias-interactive-bg-hover,#3a3b3f);color:var(--dsw-alias-label-primary,#fff)}.mpi-intro{margin:8px 0 18px;color:var(--dsw-alias-label-secondary,#c2c4ca);font-size:13px;line-height:20px}.mpi-meta{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:8px 18px;margin:0 0 16px;font-size:12px;line-height:18px}.mpi-meta dt{color:var(--dsw-alias-label-secondary,#c2c4ca)}.mpi-meta dd{margin:0;font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.mpi-status{margin:0 0 18px;border-radius:7px;padding:12px 14px;background:var(--dsw-alias-bg-layer-3,var(--dsw-specific-menu-item-hover,#252527));font-size:13px;font-weight:600;line-height:20px}.mpi-status[data-kind=error]{color:var(--dsw-alias-state-error-primary,#ff6464)}.mpi-status[data-kind=success]{color:var(--dsw-alias-state-success-primary,#36d67a)}.mpi-manual{border-top:1px solid var(--dsw-alias-border-l2,#4b4d52);padding-top:16px}.mpi-manual h3{margin:0 0 6px;font-size:14px;line-height:20px}.mpi-manual p{margin:0 0 10px;color:var(--dsw-alias-label-secondary,#c2c4ca);font-size:12px;line-height:18px}.mpi-command{display:flex;align-items:center;gap:8px;border:1px solid var(--dsw-alias-border-l2,#4b4d52);border-radius:7px;padding:10px;background:var(--dsw-alias-bg-layer-3,var(--dsw-specific-menu-item-hover,#252527))}.mpi-command code{min-width:0;flex:1;overflow:auto;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px;line-height:18px;white-space:nowrap}.mpi-actions{display:flex;align-items:center;justify-content:flex-end;gap:12px;margin-top:18px}.mpi-actions-group{display:flex;gap:8px}.mpi-action{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:32px;border:1px solid var(--dsw-alias-border-l2,#4b4d52);border-radius:7px;padding:6px 10px;background:transparent;color:inherit;font:inherit;font-size:12px;cursor:pointer}.mpi-action:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,#414247)}.mpi-action:disabled{cursor:not-allowed;opacity:.55}.mpi-primary{border-color:var(--dsw-alias-state-business-primary,#4f8cff);background:var(--dsw-alias-state-business-primary,#4f8cff);color:#fff}.mpi-progress{height:4px;margin-top:10px;overflow:hidden;border-radius:99px;background:var(--dsw-alias-border-l2,#4b4d52)}.mpi-progress::after{display:block;width:32%;height:100%;background:var(--dsw-alias-state-business-primary,#4f8cff);content:'';animation:mpi-wave 1.15s ease-in-out infinite}@keyframes mpi-wave{from{transform:translateX(-110%)}to{transform:translateX(330%)}}@media(max-width:560px){.mpi-overlay{padding:10px}.mpi-dialog{max-height:calc(100vh - 20px);padding:16px}.mpi-actions{align-items:stretch}.mpi-actions-group{justify-content:flex-end;flex-wrap:wrap}.mpi-meta{grid-template-columns:1fr;gap:2px}.mpi-meta dd{margin-bottom:6px}}
|
|
6
|
+
`;
|
|
7
|
+
const ZH = {
|
|
8
|
+
check: "\u68C0\u67E5\u66F4\u65B0",
|
|
9
|
+
update: "\u66F4\u65B0",
|
|
10
|
+
close: "\u5173\u95ED",
|
|
11
|
+
recheck: "\u91CD\u65B0\u68C0\u67E5",
|
|
12
|
+
auto: "\u81EA\u52A8\u66F4\u65B0",
|
|
13
|
+
updating: "\u6B63\u5728\u66F4\u65B0\u2026",
|
|
14
|
+
copy: "\u590D\u5236\u547D\u4EE4",
|
|
15
|
+
copied: "\u5DF2\u590D\u5236",
|
|
16
|
+
copyFailed: "\u590D\u5236\u5931\u8D25",
|
|
17
|
+
checking: "\u6B63\u5728\u68C0\u67E5\u66F4\u65B0\u2026",
|
|
18
|
+
latest: "\u5DF2\u662F\u6700\u65B0\u7248\u672C",
|
|
19
|
+
found: "\u53D1\u73B0\u65B0\u7248\u672C",
|
|
20
|
+
failed: "\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
|
|
21
|
+
current: "\u8FD0\u884C\u7248\u672C",
|
|
22
|
+
latestLabel: "\u6700\u65B0\u7248\u672C",
|
|
23
|
+
profile: "\u76EE\u6807 profile",
|
|
24
|
+
unknown: "\u672A\u77E5",
|
|
25
|
+
manual: "\u624B\u5DE5\u66F4\u65B0",
|
|
26
|
+
manualHint: "\u81EA\u52A8\u66F4\u65B0\u5931\u8D25\u65F6\uFF0C\u53EF\u5728\u5F53\u524D DSH \u7EC8\u7AEF\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\uFF0C\u5B8C\u6210\u540E\u91CD\u542F DSH Web\u3002",
|
|
27
|
+
intro: "\u4EC5\u68C0\u67E5\u5E76\u66F4\u65B0\u5F53\u524D\u63D2\u4EF6\uFF0C\u4E0D\u4F1A\u8054\u52A8\u5B89\u88C5\u5176\u4ED6\u63D2\u4EF6\u3002",
|
|
28
|
+
restart: "\u66F4\u65B0\u5B8C\u6210\uFF0C\u8BF7\u91CD\u542F DSH Web\u3002",
|
|
29
|
+
restarting: "\u66F4\u65B0\u5B8C\u6210\uFF0C\u6B63\u5728\u91CD\u542F DSH Desktop\u2026",
|
|
30
|
+
unavailable: "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u81EA\u52A8\u66F4\u65B0\uFF0C\u8BF7\u4F7F\u7528\u624B\u5DE5\u66F4\u65B0\u547D\u4EE4\u3002"
|
|
31
|
+
};
|
|
32
|
+
const EN = {
|
|
33
|
+
check: "Check for updates",
|
|
34
|
+
update: "Update",
|
|
35
|
+
close: "Close",
|
|
36
|
+
recheck: "Check again",
|
|
37
|
+
auto: "Update automatically",
|
|
38
|
+
updating: "Updating\u2026",
|
|
39
|
+
copy: "Copy command",
|
|
40
|
+
copied: "Copied",
|
|
41
|
+
copyFailed: "Copy failed",
|
|
42
|
+
checking: "Checking for updates\u2026",
|
|
43
|
+
latest: "You are up to date",
|
|
44
|
+
found: "New version available",
|
|
45
|
+
failed: "Could not check for updates. Try again later.",
|
|
46
|
+
current: "Running version",
|
|
47
|
+
latestLabel: "Latest version",
|
|
48
|
+
profile: "Target profile",
|
|
49
|
+
unknown: "Unknown",
|
|
50
|
+
manual: "Manual update",
|
|
51
|
+
manualHint: "If automatic update fails, run this command in the current DSH terminal, then restart DSH Web.",
|
|
52
|
+
intro: "Only this plugin is checked and updated. Other plugins are not changed.",
|
|
53
|
+
restart: "Update complete. Restart DSH Web.",
|
|
54
|
+
restarting: "Update complete. Restarting DSH Desktop\u2026",
|
|
55
|
+
unavailable: "Automatic update is unavailable. Use the manual command."
|
|
56
|
+
};
|
|
57
|
+
function strings() {
|
|
58
|
+
const lang = document.documentElement.lang.toLowerCase();
|
|
59
|
+
const settings = document.querySelector('[role="dialog"]')?.textContent ?? "";
|
|
60
|
+
return lang.startsWith("en") || settings.includes("Settings") && !settings.includes("\u8BBE\u7F6E") ? EN : ZH;
|
|
61
|
+
}
|
|
62
|
+
function ensureStyle() {
|
|
63
|
+
if (document.getElementById(STYLE_ID) !== null) return;
|
|
64
|
+
const style = document.createElement("style");
|
|
65
|
+
style.id = STYLE_ID;
|
|
66
|
+
style.textContent = CSS;
|
|
67
|
+
(document.head ?? document.documentElement).append(style);
|
|
68
|
+
}
|
|
69
|
+
function validPayload(value) {
|
|
70
|
+
if (value === null || typeof value !== "object") return false;
|
|
71
|
+
const item = value;
|
|
72
|
+
return typeof item.packageName === "string" && typeof item.currentVersion === "string" && typeof item.updateAvailable === "boolean" && typeof item.profileName === "string" && typeof item.canAutoUpdate === "boolean" && typeof item.latestCheckFailed === "boolean" && (item.latestVersion === void 0 || typeof item.latestVersion === "string");
|
|
73
|
+
}
|
|
74
|
+
async function requestStatus(endpoint, method, signal) {
|
|
75
|
+
const signalOption = signal === void 0 ? {} : { signal };
|
|
76
|
+
const response = await fetch(endpoint, method === "GET" ? { cache: "no-store", ...signalOption } : {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "content-type": "application/json", [UPDATE_HEADER]: "1" },
|
|
79
|
+
body: "{}",
|
|
80
|
+
...signalOption
|
|
81
|
+
});
|
|
82
|
+
const value = await response.json();
|
|
83
|
+
if (!response.ok || !validPayload(value)) throw new Error(typeof value.error === "string" ? value.error : strings().failed);
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function manualPluginUpdateCommand(profileName, packageName, version) {
|
|
87
|
+
const profile = profileName.trim() === "" ? "" : ` --profile ${profileName.trim()}`;
|
|
88
|
+
return `dsh plugin${profile} add ${packageName}@${version} --registry=https://registry.npmjs.org/`;
|
|
89
|
+
}
|
|
90
|
+
function handlePluginUpdateEscape(event, close) {
|
|
91
|
+
if (event.key !== "Escape") return false;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
event.stopPropagation();
|
|
94
|
+
event.stopImmediatePropagation();
|
|
95
|
+
close();
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
function observePluginUpdate(options) {
|
|
99
|
+
if (typeof document === "undefined" || document.body === null) return () => {
|
|
100
|
+
};
|
|
101
|
+
ensureStyle();
|
|
102
|
+
const controller = new AbortController();
|
|
103
|
+
let payload;
|
|
104
|
+
let overlay;
|
|
105
|
+
let frame;
|
|
106
|
+
const setButtonContent = (button, label, iconName) => {
|
|
107
|
+
const icon = options.createIcon(iconName);
|
|
108
|
+
icon.classList.add("mpi-icon");
|
|
109
|
+
icon.setAttribute("aria-hidden", "true");
|
|
110
|
+
const text = document.createElement("span");
|
|
111
|
+
text.dataset.mpiLabel = "";
|
|
112
|
+
text.textContent = label;
|
|
113
|
+
button.replaceChildren(icon, text);
|
|
114
|
+
};
|
|
115
|
+
const setButtonLabel = (button, label) => {
|
|
116
|
+
const text = button.querySelector("[data-mpi-label]");
|
|
117
|
+
if (text === null) button.textContent = label;
|
|
118
|
+
else text.textContent = label;
|
|
119
|
+
};
|
|
120
|
+
const applyControls = () => {
|
|
121
|
+
const row = document.querySelector(options.titleRowSelector);
|
|
122
|
+
if (row === null) return;
|
|
123
|
+
const heading = row.querySelector("h1,h2");
|
|
124
|
+
if (heading !== null && payload !== void 0) {
|
|
125
|
+
let version = heading.querySelector(`.mpi-version[data-package="${options.packageName}"]`);
|
|
126
|
+
if (version === null) {
|
|
127
|
+
version = document.createElement("span");
|
|
128
|
+
version.className = "mpi-version";
|
|
129
|
+
version.dataset.package = options.packageName;
|
|
130
|
+
heading.append(version);
|
|
131
|
+
}
|
|
132
|
+
const versionLabel = `v${payload.currentVersion}`;
|
|
133
|
+
if (version.textContent !== versionLabel) version.textContent = versionLabel;
|
|
134
|
+
}
|
|
135
|
+
const links = row.querySelector(options.linksSelector);
|
|
136
|
+
if (links === null || links.querySelector(`[data-mpi-check="${options.packageName}"]`) !== null) return;
|
|
137
|
+
const button = document.createElement("button");
|
|
138
|
+
button.type = "button";
|
|
139
|
+
button.className = "mpi-check";
|
|
140
|
+
button.dataset.mpiCheck = options.packageName;
|
|
141
|
+
setButtonContent(button, strings().check, "refresh");
|
|
142
|
+
button.addEventListener("click", openDialog);
|
|
143
|
+
links.append(button);
|
|
144
|
+
};
|
|
145
|
+
const load = async () => {
|
|
146
|
+
payload = await requestStatus(options.endpoint, "GET", controller.signal);
|
|
147
|
+
applyControls();
|
|
148
|
+
return payload;
|
|
149
|
+
};
|
|
150
|
+
const closeDialog = () => {
|
|
151
|
+
overlay?.remove();
|
|
152
|
+
overlay = void 0;
|
|
153
|
+
};
|
|
154
|
+
function openDialog() {
|
|
155
|
+
closeDialog();
|
|
156
|
+
const text = strings();
|
|
157
|
+
overlay = document.createElement("div");
|
|
158
|
+
overlay.className = "mpi-overlay";
|
|
159
|
+
const dialog = document.createElement("section");
|
|
160
|
+
dialog.className = "mpi-dialog";
|
|
161
|
+
dialog.setAttribute("role", "dialog");
|
|
162
|
+
dialog.setAttribute("aria-modal", "true");
|
|
163
|
+
dialog.innerHTML = `<header class="mpi-head"><h2></h2><button type="button" class="mpi-dialog-close" data-action="close"></button></header><p class="mpi-intro"></p><dl class="mpi-meta"><dt></dt><dd data-role="current"></dd><dt></dt><dd data-role="latest"></dd><dt></dt><dd data-role="profile"></dd></dl><div class="mpi-status" role="status"></div><div class="mpi-progress" hidden></div><section class="mpi-manual"><h3></h3><p></p><div class="mpi-command"><code></code><button type="button" class="mpi-action" data-action="copy"></button></div></section><footer class="mpi-actions"><div class="mpi-actions-group"><button type="button" class="mpi-action" data-action="check"></button><button type="button" class="mpi-action mpi-primary" data-action="update"></button></div></footer>`;
|
|
164
|
+
const name = document.documentElement.lang.toLowerCase().startsWith("en") ? options.enName : options.zhName;
|
|
165
|
+
dialog.querySelector("h2").textContent = `${name} ${text.update}`;
|
|
166
|
+
dialog.querySelector(".mpi-intro").textContent = text.intro;
|
|
167
|
+
const terms = dialog.querySelectorAll("dt");
|
|
168
|
+
terms[0].textContent = text.current;
|
|
169
|
+
terms[1].textContent = text.latestLabel;
|
|
170
|
+
terms[2].textContent = text.profile;
|
|
171
|
+
dialog.querySelector(".mpi-manual h3").textContent = text.manual;
|
|
172
|
+
dialog.querySelector(".mpi-manual p").textContent = text.manualHint;
|
|
173
|
+
const status = dialog.querySelector(".mpi-status");
|
|
174
|
+
const progress = dialog.querySelector(".mpi-progress");
|
|
175
|
+
const command = dialog.querySelector(".mpi-command code");
|
|
176
|
+
const close = dialog.querySelector("[data-action=close]");
|
|
177
|
+
const check = dialog.querySelector("[data-action=check]");
|
|
178
|
+
const update = dialog.querySelector("[data-action=update]");
|
|
179
|
+
const copy = dialog.querySelector("[data-action=copy]");
|
|
180
|
+
setButtonContent(close, text.close, "close");
|
|
181
|
+
close.querySelector("[data-mpi-label]")?.remove();
|
|
182
|
+
close.setAttribute("aria-label", text.close);
|
|
183
|
+
close.title = text.close;
|
|
184
|
+
setButtonContent(check, text.recheck, "refresh");
|
|
185
|
+
setButtonContent(update, text.auto, "download");
|
|
186
|
+
setButtonContent(copy, text.copy, "copy");
|
|
187
|
+
let busy = false;
|
|
188
|
+
const setMessage = (message, kind = "") => {
|
|
189
|
+
status.textContent = message;
|
|
190
|
+
status.dataset.kind = kind;
|
|
191
|
+
};
|
|
192
|
+
const setBusy = (value) => {
|
|
193
|
+
busy = value;
|
|
194
|
+
check.disabled = value;
|
|
195
|
+
copy.disabled = value;
|
|
196
|
+
update.disabled = value || payload?.canAutoUpdate !== true || payload.updateAvailable !== true;
|
|
197
|
+
progress.hidden = !value;
|
|
198
|
+
};
|
|
199
|
+
const render = () => {
|
|
200
|
+
dialog.querySelector("[data-role=current]").textContent = payload === void 0 ? text.unknown : `v${payload.currentVersion}`;
|
|
201
|
+
dialog.querySelector("[data-role=latest]").textContent = payload?.latestVersion === void 0 ? text.unknown : `v${payload.latestVersion}`;
|
|
202
|
+
dialog.querySelector("[data-role=profile]").textContent = payload?.profileName ?? text.unknown;
|
|
203
|
+
command.textContent = manualPluginUpdateCommand(payload?.profileName ?? "", options.packageName, payload?.latestVersion ?? "latest");
|
|
204
|
+
update.disabled = busy || payload?.canAutoUpdate !== true || payload.updateAvailable !== true;
|
|
205
|
+
if (payload === void 0) setMessage(text.checking);
|
|
206
|
+
else if (payload.latestCheckFailed) setMessage(text.failed, "error");
|
|
207
|
+
else if (payload.updateAvailable) setMessage(`${text.found}: v${payload.latestVersion ?? text.unknown}`);
|
|
208
|
+
else setMessage(text.latest, "success");
|
|
209
|
+
if (payload !== void 0 && !payload.canAutoUpdate && payload.updateAvailable) setMessage(text.unavailable);
|
|
210
|
+
};
|
|
211
|
+
const checkNow = async () => {
|
|
212
|
+
if (busy) return;
|
|
213
|
+
setBusy(true);
|
|
214
|
+
setMessage(text.checking);
|
|
215
|
+
try {
|
|
216
|
+
await load();
|
|
217
|
+
setBusy(false);
|
|
218
|
+
render();
|
|
219
|
+
} catch (error) {
|
|
220
|
+
setBusy(false);
|
|
221
|
+
setMessage(error instanceof Error ? error.message : text.failed, "error");
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const updateNow = async () => {
|
|
225
|
+
if (busy) return;
|
|
226
|
+
setBusy(true);
|
|
227
|
+
setButtonLabel(update, text.updating);
|
|
228
|
+
setMessage(text.updating);
|
|
229
|
+
try {
|
|
230
|
+
payload = await requestStatus(options.endpoint, "POST", controller.signal);
|
|
231
|
+
applyControls();
|
|
232
|
+
render();
|
|
233
|
+
setMessage(payload.autoReload === true ? text.restarting : text.restart, "success");
|
|
234
|
+
} catch (error) {
|
|
235
|
+
setMessage(error instanceof Error ? error.message : text.failed, "error");
|
|
236
|
+
} finally {
|
|
237
|
+
setButtonLabel(update, text.auto);
|
|
238
|
+
setBusy(false);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
close.addEventListener("click", closeDialog);
|
|
242
|
+
check.addEventListener("click", () => {
|
|
243
|
+
void checkNow();
|
|
244
|
+
});
|
|
245
|
+
update.addEventListener("click", () => {
|
|
246
|
+
void updateNow();
|
|
247
|
+
});
|
|
248
|
+
copy.addEventListener("click", () => {
|
|
249
|
+
void navigator.clipboard?.writeText(command.textContent ?? "").then(() => {
|
|
250
|
+
setButtonLabel(copy, text.copied);
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
setButtonLabel(copy, text.copy);
|
|
253
|
+
}, 1400);
|
|
254
|
+
}).catch(() => {
|
|
255
|
+
setButtonLabel(copy, text.copyFailed);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
overlay.addEventListener("click", (event) => {
|
|
259
|
+
if (event.target === overlay) closeDialog();
|
|
260
|
+
});
|
|
261
|
+
overlay.addEventListener("keydown", (event) => {
|
|
262
|
+
handlePluginUpdateEscape(event, closeDialog);
|
|
263
|
+
}, true);
|
|
264
|
+
overlay.append(dialog);
|
|
265
|
+
document.body.append(overlay);
|
|
266
|
+
render();
|
|
267
|
+
close.focus();
|
|
268
|
+
void checkNow();
|
|
269
|
+
}
|
|
270
|
+
const observer = new MutationObserver(() => {
|
|
271
|
+
if (frame !== void 0) return;
|
|
272
|
+
frame = window.requestAnimationFrame(() => {
|
|
273
|
+
frame = void 0;
|
|
274
|
+
applyControls();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
278
|
+
applyControls();
|
|
279
|
+
void load().catch(() => {
|
|
280
|
+
});
|
|
281
|
+
return () => {
|
|
282
|
+
controller.abort();
|
|
283
|
+
observer.disconnect();
|
|
284
|
+
closeDialog();
|
|
285
|
+
if (frame !== void 0) window.cancelAnimationFrame(frame);
|
|
286
|
+
document.querySelectorAll(`[data-mpi-check="${options.packageName}"],.mpi-version[data-package="${options.packageName}"]`).forEach((node) => node.remove());
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
export {
|
|
290
|
+
handlePluginUpdateEscape,
|
|
291
|
+
manualPluginUpdateCommand,
|
|
292
|
+
observePluginUpdate
|
|
293
|
+
};
|