@nsnanocat/preference-panes 0.9.15 → 1.0.0
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 +21 -15
- package/dist/api.js +1454 -967
- package/dist/module/app.mjs +296 -412
- package/dist/module/index.html +1 -1
- package/dist/module/navigation.mjs +17 -28
- package/dist/preference-panes.mjs +259 -374
- package/dist/web.js +1202 -0
- package/package.json +1 -1
- package/src/api.mjs +191 -0
- package/src/browser/ModuleStatus.mjs +17 -28
- package/src/browser/Navigation.d.mts +12 -32
- package/src/browser/app.mjs +5 -7
- package/src/{lib → browser}/boxjs.mjs +72 -16
- package/src/browser/client.d.mts +44 -129
- package/src/browser/client.mjs +61 -179
- package/src/browser/index.d.ts +7 -11
- package/src/browser/index.mjs +15 -7
- package/src/browser/panel.mjs +31 -22
- package/src/build.mjs +2 -3
- package/src/index.d.ts +16 -2
- package/src/web.mjs +52 -0
- package/src/BoxJS.mjs +0 -72
- package/src/Store.mjs +0 -114
- package/src/lib/response.mjs +0 -16
- package/src/proxy/handler.mjs +0 -39
- package/src/proxy/response.mjs +0 -16
package/dist/module/index.html
CHANGED
|
@@ -269,44 +269,31 @@ class ModuleFrame extends EventTarget {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
/**
|
|
273
|
-
* 模块 JSON Mock 的 HEAD 探测结果。
|
|
274
|
-
* Result returned by a module JSON Mock HEAD probe.
|
|
275
|
-
* @typedef {object} ModuleProbeResult
|
|
276
|
-
* @property {"installed" | "missing"} state 安装状态 / Installation state.
|
|
277
|
-
* @property {string | null} version 业务版本,缺失时为 null / Business version, or null when absent.
|
|
278
|
-
* @property {number | null} httpStatus HTTP 状态码,网络错误时为 null / HTTP status, or null for network errors.
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
272
|
/**
|
|
282
273
|
* 模块探测请求选项。
|
|
283
274
|
* Options for a module probe request.
|
|
284
275
|
* @typedef {object} ModuleProbeOptions
|
|
285
276
|
* @property {typeof globalThis.fetch} [fetch] 可注入的 fetch / Injectable fetch.
|
|
286
277
|
* @property {AbortSignal} [signal] 外部取消信号 / External cancellation signal.
|
|
278
|
+
* @property {string} [json] BoxJS JSON 来源,将随探测请求头传递 / BoxJS JSON source sent in the probe header.
|
|
287
279
|
* @property {number} [timeout] 超时毫秒数,默认 3500 / Timeout in milliseconds, defaults to 3500.
|
|
288
280
|
*/
|
|
289
281
|
|
|
290
282
|
/**
|
|
291
|
-
* 通过模块
|
|
292
|
-
*
|
|
293
|
-
* @param {string | URL} url
|
|
283
|
+
* 通过模块 API 的 HEAD 响应检测安装状态和业务版本。
|
|
284
|
+
* Probe installation and business version from the module API HEAD response.
|
|
285
|
+
* @param {string | URL} url 模块 API 地址 / Module API URL.
|
|
294
286
|
* @param {ModuleProbeOptions} [options] 请求选项 / Request options.
|
|
295
|
-
* @returns {Promise<
|
|
296
|
-
* @throws {Error} 外部取消请求 / External cancellation.
|
|
287
|
+
* @returns {Promise<Response>} 原始 HTTP 响应,可直接读取 status 和响应头 / Native HTTP response; read status and headers directly.
|
|
297
288
|
*/
|
|
298
|
-
async function probeModule(url, { fetch: request = globalThis.fetch, signal, timeout = 3500 } = {}) {
|
|
289
|
+
async function probeModule(url, { fetch: request = globalThis.fetch, json, signal, timeout = 3500 } = {}) {
|
|
299
290
|
const controller = new AbortController();
|
|
300
291
|
const abort = () => controller.abort();
|
|
301
292
|
if (signal?.aborted) abort();
|
|
302
293
|
signal?.addEventListener("abort", abort, { once: true });
|
|
303
294
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
304
295
|
try {
|
|
305
|
-
|
|
306
|
-
return response.status === 200 ? { state: "installed", version: response.headers.get("X-PreferencePanes-Version")?.trim() || null, httpStatus: 200 } : { state: "missing", version: null, httpStatus: response.status };
|
|
307
|
-
} catch (error) {
|
|
308
|
-
if (signal?.aborted) throw error;
|
|
309
|
-
return { state: "missing", version: null, httpStatus: null };
|
|
296
|
+
return await request(url, { method: "HEAD", cache: "no-store", credentials: "omit", signal: controller.signal, headers: json ? { "X-PreferencePanes-JSON": json } : undefined });
|
|
310
297
|
} finally {
|
|
311
298
|
clearTimeout(timer);
|
|
312
299
|
signal?.removeEventListener("abort", abort);
|
|
@@ -344,9 +331,9 @@ class ModuleStatus extends EventTarget {
|
|
|
344
331
|
/**
|
|
345
332
|
* 每次进入重新探测,取消旧请求并忽略其迟到结果。
|
|
346
333
|
* Reprobe on entry, cancelling old requests and ignoring late results.
|
|
347
|
-
* @param {string | URL} url
|
|
334
|
+
* @param {string | URL} url 模块 API 地址 / Module API URL.
|
|
348
335
|
* @param {ModuleProbeOptions} [options] 请求选项 / Request options.
|
|
349
|
-
* @returns {Promise<
|
|
336
|
+
* @returns {Promise<Response | undefined>} 原始响应;被取消时无返回值 / Native response; undefined when cancelled.
|
|
350
337
|
*/
|
|
351
338
|
async check(url, options = {}) {
|
|
352
339
|
this.#controller?.abort();
|
|
@@ -358,13 +345,15 @@ class ModuleStatus extends EventTarget {
|
|
|
358
345
|
externalSignal?.addEventListener("abort", abort, { once: true });
|
|
359
346
|
this.#render("checking");
|
|
360
347
|
try {
|
|
361
|
-
const
|
|
362
|
-
if (controller !== this.#controller) return
|
|
363
|
-
|
|
364
|
-
|
|
348
|
+
const response = await probeModule(url, { ...options, signal: controller.signal });
|
|
349
|
+
if (controller !== this.#controller) return response;
|
|
350
|
+
const version = response.status === 200 ? response.headers.get("X-PreferencePanes-Version")?.trim() || null : null;
|
|
351
|
+
this.#render(response.status === 200 ? "installed" : "missing", version);
|
|
352
|
+
return response;
|
|
365
353
|
} catch (error) {
|
|
366
|
-
if (controller !== this.#controller) return
|
|
367
|
-
throw error;
|
|
354
|
+
if (controller !== this.#controller) return;
|
|
355
|
+
if (externalSignal?.aborted) throw error;
|
|
356
|
+
this.#render("missing");
|
|
368
357
|
} finally {
|
|
369
358
|
externalSignal?.removeEventListener("abort", abort);
|
|
370
359
|
}
|