@synopackageland/cli 0.52.9 → 0.52.11

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.52.11
4
+
5
+ - Bridge `window-activated` from the injected DSM AppWindow, including switching
6
+ back and showing a minimized window, without observing desktop document focus.
7
+ - Coalesce adjacent full-page visible/focus and window activation signals; cancel
8
+ queued callbacks on deactivation, hiding, subscription disposal or host disposal.
9
+ - Keep existing resize subscriptions and unsupported theme/language events.
10
+
11
+ ## 0.52.10
12
+
13
+ - Supply the file-delegate declaration to desktop and mobile executor approval so WebAPI-only Apps can approve without file scope queries
14
+ - Accept purpose_i18n display metadata for WebAPI profiles, warn about missing UI languages and keep translations outside executor policy bytes
15
+
3
16
  ## 0.52.9
4
17
 
5
18
  - Pin CLI-owned SDK defaults and the Compose administrator adapter to 0.53.11
@@ -46,6 +46,7 @@ export const ERROR_REGISTRY = {
46
46
  INIT_UPSTREAM_INVALID: { code: "INIT_UPSTREAM_INVALID", description: "The upstream repository URL is invalid.", suggestion: "Supply --upstream with an HTTPS repository URL without credentials." },
47
47
  INIT_PUBLISHER_INVALID: { code: "INIT_PUBLISHER_INVALID", description: "The attribution name or publisher URL is invalid.", suggestion: "Use plain single-line project/publisher names and an http(s) publisher URL without credentials." },
48
48
  UPSTREAM_ATTRIBUTION: { code: "UPSTREAM_ATTRIBUTION", description: "Upstream App attribution is incomplete or names the distributor as maintainer.", suggestion: "Name the original project/team or owner as maintainer; set metadata.maintainer_url to the upstream repository and metadata.distributor/distributor_url to your publisher; resolve TODOs before release." },
49
+ WEBAPI_PURPOSE_I18N_MISSING: { code: 'WEBAPI_PURPOSE_I18N_MISSING', description: 'A WebAPI profile lacks purpose translations for one or more UI languages', suggestion: 'Add purpose_i18n entries for en, zh-TW, zh-CN, de, fr, ja, ko, es and it without trailing periods; missing locales fall back to English' },
49
50
  DSM_WINDOW_COLOR_SCHEME: { code: 'DSM_WINDOW_COLOR_SCHEME', description: 'A DSM-window Vue component combines OS theme detection with a dynamic color-scheme binding', suggestion: 'Leave color-scheme unset in DSM windows; follow OS preferences only on the App\'s own full page' },
50
51
  STANDALONE_IDENTITY_WITHOUT_PORTAL: { code: 'STANDALONE_IDENTITY_WITHOUT_PORTAL', description: 'Standalone identity is enabled without an Application Portal declaration', suggestion: 'Use HTTPS-only standalone login outside DSM windows; declare portal only when an alias is needed' },
51
52
  INSTALL_SETTINGS_INVALID: { "code": "INSTALL_SETTINGS_INVALID", "description": "The installation setting declaration is invalid.", "suggestion": "Declare 1–32 lowercase identifier keys in install.settings, each with type https-origin, a plain label and an explicit boolean required; omit defaults and values." },
@@ -32,7 +32,7 @@ export const executorPolicyText = (policy) => JSON.stringify(policy) + '\n';
32
32
  export function executorPolicy(m, arch) {
33
33
  if (m.capabilities.delegate && !validDelegate(m.capabilities.delegate))
34
34
  throw new Error('[EXECUTOR_POLICY] Invalid delegate operations or scope.');
35
- if (m.capabilities.webapi && !validWebAPIProfiles(m.capabilities.webapi))
35
+ if (m.capabilities.webapi && !validWebAPIProfiles(m.capabilities.webapi, true))
36
36
  throw new Error('[EXECUTOR_POLICY] Invalid WebAPI profiles.');
37
37
  const portal = executorPortal(m);
38
38
  const operations = ['status', ...(portal ? PORTAL_OPERATIONS : [])];
@@ -1,9 +1,12 @@
1
1
  /** WebAPI profiles, independently enforced again by the pinned executor. */
2
2
  export interface WebAPIProfile {
3
3
  purpose: string;
4
+ purpose_i18n?: Partial<Record<WebAPIPurposeLocale, string>>;
4
5
  apis: Record<string, Record<string, number[]>>;
5
6
  raw_max_bytes?: number;
6
7
  }
8
+ export declare const webapiPurposeLocales: readonly ["en", "zh-TW", "zh-CN", "de", "fr", "ja", "ko", "es", "it"];
9
+ export type WebAPIPurposeLocale = typeof webapiPurposeLocales[number];
7
10
  export type WebAPIProfiles = Record<string, WebAPIProfile>;
8
- export declare function validWebAPIProfiles(value: unknown): value is WebAPIProfiles;
11
+ export declare function validWebAPIProfiles(value: unknown, allowPurposeI18n?: boolean): value is WebAPIProfiles;
9
12
  export declare function sortedWebAPIProfiles(profiles: WebAPIProfiles): WebAPIProfiles;
@@ -1,10 +1,13 @@
1
+ export const webapiPurposeLocales = ['en', 'zh-TW', 'zh-CN', 'de', 'fr', 'ja', 'ko', 'es', 'it'];
1
2
  const record = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
2
- export function validWebAPIProfiles(value) {
3
+ export function validWebAPIProfiles(value, allowPurposeI18n = false) {
3
4
  if (!record(value) || !Object.keys(value).length || Object.keys(value).length > 32)
4
5
  return false;
5
6
  let total = 0;
6
7
  for (const [name, p] of Object.entries(value)) {
7
- if (!/^[a-z][a-z0-9_-]{0,63}$/.test(name) || name === 'home' || !record(p) || Object.keys(p).some(k => !['purpose', 'apis', 'raw_max_bytes'].includes(k)) || typeof p.purpose !== 'string' || !p.purpose.trim() || Buffer.byteLength(p.purpose) > 1024 || /[\x00-\x1f\x7f]/.test(p.purpose) || !record(p.apis) || !Object.keys(p.apis).length)
8
+ if (!/^[a-z][a-z0-9_-]{0,63}$/.test(name) || name === 'home' || !record(p) || Object.keys(p).some(k => !['purpose', 'apis', 'raw_max_bytes', ...(allowPurposeI18n ? ['purpose_i18n'] : [])].includes(k)) || typeof p.purpose !== 'string' || !p.purpose.trim() || Buffer.byteLength(p.purpose) > 1024 || /[\x00-\x1f\x7f]/.test(p.purpose) || !record(p.apis) || !Object.keys(p.apis).length)
9
+ return false;
10
+ if (p.purpose_i18n !== undefined && (!record(p.purpose_i18n) || Object.entries(p.purpose_i18n).some(([locale, text]) => !webapiPurposeLocales.includes(locale) || typeof text !== 'string' || !text.trim() || Buffer.byteLength(text) > 1024 || /[\x00-\x1f\x7f]/.test(text) || /[.。]$/.test(text.trim()))))
8
11
  return false;
9
12
  if (p.raw_max_bytes !== undefined && (!Number.isSafeInteger(p.raw_max_bytes) || Number(p.raw_max_bytes) < 0 || Number(p.raw_max_bytes) > 10737418240))
10
13
  return false;
@@ -12,6 +12,7 @@ ${PASSWORD_CONFIRM}
12
12
  })();
13
13
  ${ns}.createExecutorAccess = function (options) {
14
14
  options.tasks = ${ns}.rootTasks;
15
+ options.fileDelegate = ${!!manifest.capabilities.delegate};
15
16
  options.webapiProfiles = ${JSON.stringify(manifest.capabilities.webapi ?? {})};
16
17
  options.pins = ${JSON.stringify({ package: manifest.package, executorDigest: manifest.executor.executorDigest, policyDigest: manifest.executor.policyDigest })};
17
18
  options.wait = function (ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); };
@@ -1,5 +1,5 @@
1
1
  export type { HostAdapter, HostTitleResult, HostRequestResult, HostURLResult, HostEvent, HostSubscriptionResult, HostFileNavigationResult, HostUnsupportedResult } from "./host-types.js";
2
- export declare const HOST_ADAPTER_RUNTIME = "function inspectHostPlatform(ctx) {\n ctx = ctx || {};\n var web = typeof window !== \"undefined\";\n var host = false;\n try {\n host = !!(web && ctx.appWindow && typeof SYNO !== \"undefined\" &&\n SYNO.SDS && typeof SYNO.SDS.AppWindow === \"function\" &&\n ctx.appWindow instanceof SYNO.SDS.AppWindow);\n } catch (error) {\n // An unsupported host constructor must not break a standalone shell.\n }\n function read(key) {\n if (!host || typeof _S !== \"function\") return null;\n try { return _S(key); } catch (error) { return null; }\n }\n function text(value) {\n return typeof value === \"string\" && /\\S/.test(value) ? value : null;\n }\n function versionPart(value) {\n if (typeof value === \"number\") {\n if (!isFinite(value) || value < 0 || Math.floor(value) !== value) return null;\n value = String(value);\n }\n return typeof value === \"string\" && value.length > 0 && !/\\D/.test(value) ? value : null;\n }\n var standalone = read(\"standalone\");\n var language = text(read(\"lang\"));\n var major = versionPart(read(\"majorversion\"));\n var minor = versionPart(read(\"minorversion\"));\n var fullVersion = text(read(\"fullversion\"));\n return Object.freeze({\n web: web,\n host: host ? \"dsm\" : web ? \"standalone-web\" : \"unavailable\",\n dsmStandalone: typeof standalone === \"boolean\" ? standalone : null,\n dsmLanguage: language,\n appLocale: text(ctx.locale),\n systemVersion: major !== null && minor !== null ? major + \".\" + minor : null,\n fullVersion: fullVersion,\n theme: null\n });\n}\n\nfunction requestHostFileNavigation(launch, path, isDirectory) {\n if (typeof path !== \"string\" || path.length > 4096 || path.charAt(0) !== \"/\" ||\n /[\\x00-\\x1f\\x7f\\\\]/.test(path)) return { status: \"invalid-input\" };\n var volume = /^\\/volume(?:USB|SATA)?[0-9]+(?=\\/|$)/.exec(path);\n if (volume) path = path.slice(volume[0].length);\n var parts = path.split(\"/\");\n if (parts.length < 2 || parts.slice(1).some(function (part) {\n return !part || part === \".\" || part === \"..\";\n })) return { status: \"invalid-input\" };\n var result = launch(\"SYNO.SDS.App.FileStation3.Instance\", isDirectory ? { opendir: path } : { openfile: path });\n if (result.status !== \"requested\") return result;\n return { status: \"requested\", action: isDirectory ? \"locate-folder\" : \"highlight-file\" };\n}\n\n\nvar REVEAL_RECOVERY_TIMEOUT_MS = 5000;\nvar REVEAL_RECOVERY_POLL_MS = 100;\nvar REVEAL_RECOVERY_QUIET_MS = 300;\nvar hostFileRevealOwners = null, hostFileRevealSequence = 0;\ntry { if (typeof WeakMap === \"function\") hostFileRevealOwners = new WeakMap(); } catch (error) {}\nfunction createHostFileRevealRecovery(path, canAct) {\n var active = true, accepted = false, win = null, dom = null, tuple = null;\n var poll = null, deadline = null, removers = [], reached = false, pending = 0;\n var previous = null, quietSince = null, expires = 0, order = ++hostFileRevealSequence;\n var parent = path.slice(0, path.lastIndexOf(\"/\"));\n function cancel() {\n if (!active) return;\n active = false;\n try { if (poll !== null) clearTimeout(poll); } catch (error) {}\n try { if (deadline !== null) clearTimeout(deadline); } catch (error) {}\n poll = deadline = null;\n removers.splice(0).forEach(function (remove) { try { remove(); } catch (error) {} });\n try {\n if (win && hostFileRevealOwners.get(win).order === order) {\n // Preserve ordering for a late older callback, without retaining its closures.\n hostFileRevealOwners.set(win, { order: order, cancel: null });\n }\n } catch (error) {}\n win = dom = tuple = previous = null;\n }\n function requireMethods(target, names) {\n if (!target || names.some(function (name) { return typeof target[name] !== \"function\"; })) throw new Error(\"unsupported receiver\");\n }\n function guard(fn) {\n return function () {\n if (!active) return;\n try { fn.apply(null, arguments); } catch (error) { cancel(); }\n };\n }\n function listen(target, event, fn) {\n requireMethods(target, [\"on\", \"un\"]);\n var handler = guard(fn), remove = target.un;\n removers.push(function () { remove.call(target, event, handler, target); });\n target.on(event, handler, target);\n }\n function resetQuiet() { previous = null; quietSince = null; }\n function inspect() {\n requireMethods(win, [\"getPanelInstance\", \"getEl\", \"on\", \"un\"]);\n if (win.isDestroyed || win.destroyed || !canAct()) { cancel(); return null; }\n var element = win.getEl(), nextDom = element && element.dom;\n if (!nextDom) { if (dom) cancel(); return null; }\n requireMethods(nextDom, [\"addEventListener\", \"removeEventListener\"]);\n if (dom && nextDom !== dom) { cancel(); return null; }\n if (!dom) {\n dom = nextDom;\n [\"pointerdown\", \"mousedown\", \"touchstart\", \"keydown\", \"wheel\", \"click\", \"input\"].forEach(function (event) {\n var remove = dom.removeEventListener, handler = guard(cancel), target = dom;\n removers.push(function () { remove.call(target, event, handler, true); });\n dom.addEventListener(event, handler, true);\n });\n }\n var panel = win.getPanelInstance();\n if (!panel) { if (tuple) cancel(); return null; }\n requireMethods(panel, [\"getCurrentDir\", \"on\", \"un\"]);\n var view = panel.activeView, store = panel.activeDS;\n requireMethods(view, [\"getStore\", \"getSelectionModel\", \"scrollToItem\"]);\n requireMethods(store, [\"on\", \"un\", \"indexOfId\", \"getAt\", \"getCount\"]);\n var model = view.getSelectionModel();\n requireMethods(model, [\"on\", \"un\", \"getSelections\", \"selectRow\"]);\n if (view.getStore() !== store || panel.isDestroyed || store.isDestroyed || model.isDestroyed) { cancel(); return null; }\n if (tuple && (tuple.panel !== panel || tuple.view !== view || tuple.store !== store || tuple.model !== model)) { cancel(); return null; }\n if (!tuple) {\n tuple = { panel: panel, view: view, store: store, model: model };\n listen(panel, \"destroy\", cancel);\n listen(panel, \"onNodeClick\", function (node) {\n if (!node || !node.attributes || (reached && node.attributes.path !== parent)) cancel();\n });\n listen(store, \"beforeload\", function () {\n pending++; resetQuiet(); inspect();\n });\n listen(store, \"load\", function () {\n if (pending > 0) pending--;\n resetQuiet(); check();\n });\n [\"exception\", \"loadexception\", \"destroy\"].forEach(function (event) { listen(store, event, cancel); });\n listen(model, \"selectionchange\", function () { resetQuiet(); check(); });\n }\n var dir = panel.getCurrentDir(), params = store.baseParams;\n // New File Station panels expose their APIs before the first directory is set.\n // Keep the bound receiver guards and original deadline while startup finishes.\n if (!reached && dir === undefined && (!params || params.folder_path === undefined)) return null;\n if (!params || typeof params.folder_path !== \"string\") throw new Error(\"unsupported store path\");\n // Native reconfigure/selection events can precede the store's path assignment.\n if (dir === parent && params.folder_path === parent) reached = true;\n if (reached && (dir !== parent || params.folder_path !== parent)) { cancel(); return null; }\n var selections = model.getSelections();\n if (!Array.isArray(selections)) throw new Error(\"unsupported selection\");\n if (selections.some(function (record) { return !record || record.id !== path; })) { cancel(); return null; }\n var index = store.indexOfId(path), count = store.getCount();\n if (!Number.isInteger(index) || index < -1 || !Number.isInteger(count) || count < 0) throw new Error(\"unsupported store index\");\n var record = index >= 0 ? store.getAt(index) : null;\n if (index >= 0 && (!record || record.id !== path || index >= count)) throw new Error(\"inconsistent store\");\n return { dir: dir, folder: params.folder_path, count: count, index: index, record: record, selected: selections.length > 0 };\n }\n function check() {\n if (!active) return;\n if (Date.now() >= expires || !canAct()) { cancel(); return; }\n if (!win) return;\n var state = inspect();\n if (!active || !state) return;\n if (pending || state.dir !== parent || state.folder !== parent || state.index < 0) { resetQuiet(); return; }\n if (!previous || Object.keys(state).some(function (key) { return state[key] !== previous[key]; })) {\n previous = state; quietSince = Date.now();\n }\n if (Date.now() - quietSince < REVEAL_RECOVERY_QUIET_MS) return;\n var target = tuple, receiverWindow = win;\n cancel(); // Release every observer before the one permitted selection mutation.\n if (state.selected || !canAct()) return;\n target.model.selectRow(state.index);\n if (canAct() && !receiverWindow.isDestroyed && receiverWindow.getPanelInstance() === target.panel &&\n target.panel.activeView === target.view && target.panel.activeDS === target.store &&\n target.view.getSelectionModel() === target.model) target.view.scrollToItem(state.index);\n }\n function tick() {\n poll = null;\n try {\n check();\n if (active) poll = setTimeout(tick, REVEAL_RECOVERY_POLL_MS);\n } catch (error) { cancel(); }\n }\n function receive(instance) {\n if (!active || accepted) return;\n accepted = true;\n try {\n if (Date.now() >= expires || !canAct()) { cancel(); return; }\n win = instance && instance.window;\n requireMethods(win, [\"getPanelInstance\", \"getEl\", \"on\", \"un\"]);\n var owner = hostFileRevealOwners.get(win);\n if (owner && owner.order > order) { cancel(); return; }\n if (owner && owner.cancel) owner.cancel();\n hostFileRevealOwners.set(win, { order: order, cancel: cancel });\n [\"beforeclose\", \"close\", \"beforedestroy\", \"destroy\", \"hide\"].forEach(function (event) { listen(win, event, cancel); });\n check();\n } catch (error) { cancel(); }\n }\n try {\n if (!parent || !hostFileRevealOwners || typeof setTimeout !== \"function\" || typeof clearTimeout !== \"function\" || typeof Date.now !== \"function\") {\n cancel();\n } else {\n expires = Date.now() + REVEAL_RECOVERY_TIMEOUT_MS;\n deadline = setTimeout(cancel, REVEAL_RECOVERY_TIMEOUT_MS);\n poll = setTimeout(tick, REVEAL_RECOVERY_POLL_MS);\n }\n } catch (error) { cancel(); }\n return { receive: receive, cancel: cancel };\n}\n\nfunction createHostAdapter(ctx) {\n ctx = ctx || {};\n var disposed = false, subscriptions = [], revealRecovery = null;\n function launchApp(appId, config, receiverCallback) {\n if (disposed) return { status: \"unavailable\" };\n if (typeof appId !== \"string\" || !appId || /\\s/.test(appId)) return { status: \"invalid-input\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var sds = SYNO.SDS, map = sds.Config && sds.Config.FnMap, notifier = sds.StatusNotifier;\n if (typeof sds.AppLaunch !== \"function\" || !map ||\n !Object.prototype.hasOwnProperty.call(map, appId) || !map[appId] || !notifier ||\n typeof notifier.isAppEnabled !== \"function\" || !notifier.isAppEnabled(appId) ||\n typeof notifier.isAppLaunchable !== \"function\" || !notifier.isAppLaunchable(appId)) {\n return { status: \"unsupported\" };\n }\n if (receiverCallback) sds.AppLaunch(appId, config, undefined, receiverCallback);\n else sds.AppLaunch(appId, config);\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n }\n function navigateFileStation(path, isDirectory) {\n if (disposed) return { status: \"unavailable\" };\n if (revealRecovery) revealRecovery.cancel();\n revealRecovery = null;\n function launchFile(appId, config) {\n if (isDirectory) return launchApp(appId, config);\n var recovery = createHostFileRevealRecovery(config.openfile, function () { return !disposed && revealRecovery === recovery; });\n revealRecovery = recovery;\n var result = launchApp(appId, config, recovery.receive);\n if (result.status !== \"requested\") recovery.cancel();\n return result;\n }\n return requestHostFileNavigation(launchFile, path, isDirectory);\n }\n function unsupportedOperation() { return { status: disposed ? \"unavailable\" : \"unsupported\" }; }\n return Object.freeze({\n platform: function () {\n if (!disposed) return inspectHostPlatform(ctx);\n return Object.freeze({\n web: typeof window !== \"undefined\", host: \"unavailable\",\n dsmStandalone: null, dsmLanguage: null, appLocale: null,\n systemVersion: null, fullVersion: null, theme: null\n });\n },\n setTitle: function (title) {\n if (disposed) return { status: \"unavailable\" };\n if (typeof title !== \"string\") return { status: \"invalid-input\" };\n try {\n var platform = inspectHostPlatform(ctx);\n if (platform.host === \"dsm\") {\n if (typeof ctx.appWindow.setTitle !== \"function\") return { status: \"unsupported\" };\n ctx.appWindow.setTitle(title, undefined, true);\n return { status: \"ok\", target: \"dsm-window\" };\n }\n if (!platform.web) return { status: \"unavailable\" };\n if (typeof document === \"undefined\") return { status: \"unsupported\" };\n document.title = title;\n return { status: \"ok\", target: \"document\" };\n } catch (error) {\n return { status: \"failed\" };\n }\n },\n activateWindow: function () {\n if (disposed) return { status: \"unavailable\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var win = ctx.appWindow;\n var activate = typeof win.toFront === \"function\" ? win.toFront : win.activate;\n if (typeof activate !== \"function\") return { status: \"unsupported\" };\n // DSM minimizes by hiding; show preserves maximized geometry, unlike restore.\n if (win.hidden === true || win.minimized === true ||\n (typeof win.isVisible === \"function\" && win.isVisible() === false)) {\n if (typeof win.show !== \"function\") return { status: \"unsupported\" };\n win.show();\n }\n activate.call(win);\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n },\n requestClose: function () {\n if (disposed) return { status: \"unavailable\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var win = ctx.appWindow;\n // DSM returns a short-circuit value; only truthy means standalone main.\n if (typeof win.close !== \"function\" || typeof win.isStandaloneMainWindow !== \"function\" ||\n win.isStandaloneMainWindow()) return { status: \"unsupported\" };\n if (win.canClose === false) return { status: \"blocked\" };\n win.close();\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n },\n // DSM's own banner sign-out, for an App that hides the banner (ui.banner: hidden).\n signOut: function () {\n if (disposed) return { status: \"unavailable\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var sds = SYNO.SDS, logout = sds.Utils && sds.Utils.Logout;\n if (!logout || typeof logout.action !== \"function\") return { status: \"unsupported\" };\n if (sds.StatusNotifier) sds.StatusNotifier.fireEvent(\"logout\");\n window.onbeforeunload = sds.onBasicBeforeUnload;\n logout.action();\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n },\n openApp: function (appId) { return launchApp(appId, {}); },\n openURL: function (raw) {\n if (disposed || typeof window === \"undefined\") return { status: \"unavailable\" };\n if (typeof raw !== \"string\" || !raw || /[\\s\\x00-\\x1f\\x7f]/.test(raw)) return { status: \"invalid-input\" };\n if (typeof URL !== \"function\") return { status: \"unsupported\" };\n var url;\n try { url = new URL(raw); } catch (error) { return { status: \"invalid-input\" }; }\n if ((url.protocol !== \"http:\" && url.protocol !== \"https:\") || url.username || url.password) return { status: \"invalid-input\" };\n if (typeof window.open !== \"function\") return { status: \"unsupported\" };\n try {\n var opened = window.open(url.href, \"_blank\", \"noopener,noreferrer\");\n return { status: \"requested\", windowHandleAvailable: !!opened };\n } catch (error) { return { status: \"failed\" }; }\n },\n openFileManager: function (path) { return navigateFileStation(path, true); },\n revealFile: function (path) { return navigateFileStation(path, false); },\n openFile: unsupportedOperation,\n showFileDetails: unsupportedOperation,\n openAppSetting: unsupportedOperation,\n subscribe: function (event, listener) {\n if (disposed) return { status: \"unavailable\" };\n if (typeof listener !== \"function\") return { status: \"invalid-input\" };\n if (event !== \"window-resize\") return { status: \"unsupported\" };\n var win, callback = listener, active = true;\n function handler() { if (!disposed && callback) callback(); }\n function unsubscribe() {\n if (!active) return;\n active = false;\n callback = null;\n var target = win;\n win = null;\n var index = subscriptions.indexOf(unsubscribe);\n if (index !== -1) subscriptions.splice(index, 1);\n try { if (target) target.un(\"resize\", handler, target); } catch (error) {}\n }\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n win = ctx.appWindow;\n if (typeof win.on !== \"function\" || typeof win.un !== \"function\") return { status: \"unsupported\" };\n subscriptions.push(unsubscribe);\n win.on(\"resize\", handler, win);\n if (disposed) return { status: \"unavailable\" };\n return Object.freeze({ status: \"subscribed\", dispose: unsubscribe });\n } catch (error) {\n unsubscribe();\n return { status: \"failed\" };\n }\n },\n dispose: function () {\n if (disposed) return;\n disposed = true;\n if (revealRecovery) revealRecovery.cancel();\n revealRecovery = null;\n subscriptions.slice().forEach(function (unsubscribe) { unsubscribe(); });\n ctx = null;\n }\n });\n}";
2
+ export declare const HOST_ADAPTER_RUNTIME = "function inspectHostPlatform(ctx) {\n ctx = ctx || {};\n var web = typeof window !== \"undefined\";\n var host = false;\n try {\n host = !!(web && ctx.appWindow && typeof SYNO !== \"undefined\" &&\n SYNO.SDS && typeof SYNO.SDS.AppWindow === \"function\" &&\n ctx.appWindow instanceof SYNO.SDS.AppWindow);\n } catch (error) {\n // An unsupported host constructor must not break a standalone shell.\n }\n function read(key) {\n if (!host || typeof _S !== \"function\") return null;\n try { return _S(key); } catch (error) { return null; }\n }\n function text(value) {\n return typeof value === \"string\" && /\\S/.test(value) ? value : null;\n }\n function versionPart(value) {\n if (typeof value === \"number\") {\n if (!isFinite(value) || value < 0 || Math.floor(value) !== value) return null;\n value = String(value);\n }\n return typeof value === \"string\" && value.length > 0 && !/\\D/.test(value) ? value : null;\n }\n var standalone = read(\"standalone\");\n var language = text(read(\"lang\"));\n var major = versionPart(read(\"majorversion\"));\n var minor = versionPart(read(\"minorversion\"));\n var fullVersion = text(read(\"fullversion\"));\n return Object.freeze({\n web: web,\n host: host ? \"dsm\" : web ? \"standalone-web\" : \"unavailable\",\n dsmStandalone: typeof standalone === \"boolean\" ? standalone : null,\n dsmLanguage: language,\n appLocale: text(ctx.locale),\n systemVersion: major !== null && minor !== null ? major + \".\" + minor : null,\n fullVersion: fullVersion,\n theme: null\n });\n}\n\nfunction requestHostFileNavigation(launch, path, isDirectory) {\n if (typeof path !== \"string\" || path.length > 4096 || path.charAt(0) !== \"/\" ||\n /[\\x00-\\x1f\\x7f\\\\]/.test(path)) return { status: \"invalid-input\" };\n var volume = /^\\/volume(?:USB|SATA)?[0-9]+(?=\\/|$)/.exec(path);\n if (volume) path = path.slice(volume[0].length);\n var parts = path.split(\"/\");\n if (parts.length < 2 || parts.slice(1).some(function (part) {\n return !part || part === \".\" || part === \"..\";\n })) return { status: \"invalid-input\" };\n var result = launch(\"SYNO.SDS.App.FileStation3.Instance\", isDirectory ? { opendir: path } : { openfile: path });\n if (result.status !== \"requested\") return result;\n return { status: \"requested\", action: isDirectory ? \"locate-folder\" : \"highlight-file\" };\n}\n\n\nvar REVEAL_RECOVERY_TIMEOUT_MS = 5000;\nvar REVEAL_RECOVERY_POLL_MS = 100;\nvar REVEAL_RECOVERY_QUIET_MS = 300;\nvar hostFileRevealOwners = null, hostFileRevealSequence = 0;\ntry { if (typeof WeakMap === \"function\") hostFileRevealOwners = new WeakMap(); } catch (error) {}\nfunction createHostFileRevealRecovery(path, canAct) {\n var active = true, accepted = false, win = null, dom = null, tuple = null;\n var poll = null, deadline = null, removers = [], reached = false, pending = 0;\n var previous = null, quietSince = null, expires = 0, order = ++hostFileRevealSequence;\n var parent = path.slice(0, path.lastIndexOf(\"/\"));\n function cancel() {\n if (!active) return;\n active = false;\n try { if (poll !== null) clearTimeout(poll); } catch (error) {}\n try { if (deadline !== null) clearTimeout(deadline); } catch (error) {}\n poll = deadline = null;\n removers.splice(0).forEach(function (remove) { try { remove(); } catch (error) {} });\n try {\n if (win && hostFileRevealOwners.get(win).order === order) {\n // Preserve ordering for a late older callback, without retaining its closures.\n hostFileRevealOwners.set(win, { order: order, cancel: null });\n }\n } catch (error) {}\n win = dom = tuple = previous = null;\n }\n function requireMethods(target, names) {\n if (!target || names.some(function (name) { return typeof target[name] !== \"function\"; })) throw new Error(\"unsupported receiver\");\n }\n function guard(fn) {\n return function () {\n if (!active) return;\n try { fn.apply(null, arguments); } catch (error) { cancel(); }\n };\n }\n function listen(target, event, fn) {\n requireMethods(target, [\"on\", \"un\"]);\n var handler = guard(fn), remove = target.un;\n removers.push(function () { remove.call(target, event, handler, target); });\n target.on(event, handler, target);\n }\n function resetQuiet() { previous = null; quietSince = null; }\n function inspect() {\n requireMethods(win, [\"getPanelInstance\", \"getEl\", \"on\", \"un\"]);\n if (win.isDestroyed || win.destroyed || !canAct()) { cancel(); return null; }\n var element = win.getEl(), nextDom = element && element.dom;\n if (!nextDom) { if (dom) cancel(); return null; }\n requireMethods(nextDom, [\"addEventListener\", \"removeEventListener\"]);\n if (dom && nextDom !== dom) { cancel(); return null; }\n if (!dom) {\n dom = nextDom;\n [\"pointerdown\", \"mousedown\", \"touchstart\", \"keydown\", \"wheel\", \"click\", \"input\"].forEach(function (event) {\n var remove = dom.removeEventListener, handler = guard(cancel), target = dom;\n removers.push(function () { remove.call(target, event, handler, true); });\n dom.addEventListener(event, handler, true);\n });\n }\n var panel = win.getPanelInstance();\n if (!panel) { if (tuple) cancel(); return null; }\n requireMethods(panel, [\"getCurrentDir\", \"on\", \"un\"]);\n var view = panel.activeView, store = panel.activeDS;\n requireMethods(view, [\"getStore\", \"getSelectionModel\", \"scrollToItem\"]);\n requireMethods(store, [\"on\", \"un\", \"indexOfId\", \"getAt\", \"getCount\"]);\n var model = view.getSelectionModel();\n requireMethods(model, [\"on\", \"un\", \"getSelections\", \"selectRow\"]);\n if (view.getStore() !== store || panel.isDestroyed || store.isDestroyed || model.isDestroyed) { cancel(); return null; }\n if (tuple && (tuple.panel !== panel || tuple.view !== view || tuple.store !== store || tuple.model !== model)) { cancel(); return null; }\n if (!tuple) {\n tuple = { panel: panel, view: view, store: store, model: model };\n listen(panel, \"destroy\", cancel);\n listen(panel, \"onNodeClick\", function (node) {\n if (!node || !node.attributes || (reached && node.attributes.path !== parent)) cancel();\n });\n listen(store, \"beforeload\", function () {\n pending++; resetQuiet(); inspect();\n });\n listen(store, \"load\", function () {\n if (pending > 0) pending--;\n resetQuiet(); check();\n });\n [\"exception\", \"loadexception\", \"destroy\"].forEach(function (event) { listen(store, event, cancel); });\n listen(model, \"selectionchange\", function () { resetQuiet(); check(); });\n }\n var dir = panel.getCurrentDir(), params = store.baseParams;\n // New File Station panels expose their APIs before the first directory is set.\n // Keep the bound receiver guards and original deadline while startup finishes.\n if (!reached && dir === undefined && (!params || params.folder_path === undefined)) return null;\n if (!params || typeof params.folder_path !== \"string\") throw new Error(\"unsupported store path\");\n // Native reconfigure/selection events can precede the store's path assignment.\n if (dir === parent && params.folder_path === parent) reached = true;\n if (reached && (dir !== parent || params.folder_path !== parent)) { cancel(); return null; }\n var selections = model.getSelections();\n if (!Array.isArray(selections)) throw new Error(\"unsupported selection\");\n if (selections.some(function (record) { return !record || record.id !== path; })) { cancel(); return null; }\n var index = store.indexOfId(path), count = store.getCount();\n if (!Number.isInteger(index) || index < -1 || !Number.isInteger(count) || count < 0) throw new Error(\"unsupported store index\");\n var record = index >= 0 ? store.getAt(index) : null;\n if (index >= 0 && (!record || record.id !== path || index >= count)) throw new Error(\"inconsistent store\");\n return { dir: dir, folder: params.folder_path, count: count, index: index, record: record, selected: selections.length > 0 };\n }\n function check() {\n if (!active) return;\n if (Date.now() >= expires || !canAct()) { cancel(); return; }\n if (!win) return;\n var state = inspect();\n if (!active || !state) return;\n if (pending || state.dir !== parent || state.folder !== parent || state.index < 0) { resetQuiet(); return; }\n if (!previous || Object.keys(state).some(function (key) { return state[key] !== previous[key]; })) {\n previous = state; quietSince = Date.now();\n }\n if (Date.now() - quietSince < REVEAL_RECOVERY_QUIET_MS) return;\n var target = tuple, receiverWindow = win;\n cancel(); // Release every observer before the one permitted selection mutation.\n if (state.selected || !canAct()) return;\n target.model.selectRow(state.index);\n if (canAct() && !receiverWindow.isDestroyed && receiverWindow.getPanelInstance() === target.panel &&\n target.panel.activeView === target.view && target.panel.activeDS === target.store &&\n target.view.getSelectionModel() === target.model) target.view.scrollToItem(state.index);\n }\n function tick() {\n poll = null;\n try {\n check();\n if (active) poll = setTimeout(tick, REVEAL_RECOVERY_POLL_MS);\n } catch (error) { cancel(); }\n }\n function receive(instance) {\n if (!active || accepted) return;\n accepted = true;\n try {\n if (Date.now() >= expires || !canAct()) { cancel(); return; }\n win = instance && instance.window;\n requireMethods(win, [\"getPanelInstance\", \"getEl\", \"on\", \"un\"]);\n var owner = hostFileRevealOwners.get(win);\n if (owner && owner.order > order) { cancel(); return; }\n if (owner && owner.cancel) owner.cancel();\n hostFileRevealOwners.set(win, { order: order, cancel: cancel });\n [\"beforeclose\", \"close\", \"beforedestroy\", \"destroy\", \"hide\"].forEach(function (event) { listen(win, event, cancel); });\n check();\n } catch (error) { cancel(); }\n }\n try {\n if (!parent || !hostFileRevealOwners || typeof setTimeout !== \"function\" || typeof clearTimeout !== \"function\" || typeof Date.now !== \"function\") {\n cancel();\n } else {\n expires = Date.now() + REVEAL_RECOVERY_TIMEOUT_MS;\n deadline = setTimeout(cancel, REVEAL_RECOVERY_TIMEOUT_MS);\n poll = setTimeout(tick, REVEAL_RECOVERY_POLL_MS);\n }\n } catch (error) { cancel(); }\n return { receive: receive, cancel: cancel };\n}\n\nfunction createHostAdapter(ctx) {\n ctx = ctx || {};\n var disposed = false, subscriptions = [], revealRecovery = null;\n function launchApp(appId, config, receiverCallback) {\n if (disposed) return { status: \"unavailable\" };\n if (typeof appId !== \"string\" || !appId || /\\s/.test(appId)) return { status: \"invalid-input\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var sds = SYNO.SDS, map = sds.Config && sds.Config.FnMap, notifier = sds.StatusNotifier;\n if (typeof sds.AppLaunch !== \"function\" || !map ||\n !Object.prototype.hasOwnProperty.call(map, appId) || !map[appId] || !notifier ||\n typeof notifier.isAppEnabled !== \"function\" || !notifier.isAppEnabled(appId) ||\n typeof notifier.isAppLaunchable !== \"function\" || !notifier.isAppLaunchable(appId)) {\n return { status: \"unsupported\" };\n }\n if (receiverCallback) sds.AppLaunch(appId, config, undefined, receiverCallback);\n else sds.AppLaunch(appId, config);\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n }\n function navigateFileStation(path, isDirectory) {\n if (disposed) return { status: \"unavailable\" };\n if (revealRecovery) revealRecovery.cancel();\n revealRecovery = null;\n function launchFile(appId, config) {\n if (isDirectory) return launchApp(appId, config);\n var recovery = createHostFileRevealRecovery(config.openfile, function () { return !disposed && revealRecovery === recovery; });\n revealRecovery = recovery;\n var result = launchApp(appId, config, recovery.receive);\n if (result.status !== \"requested\") recovery.cancel();\n return result;\n }\n return requestHostFileNavigation(launchFile, path, isDirectory);\n }\n function unsupportedOperation() { return { status: disposed ? \"unavailable\" : \"unsupported\" }; }\n return Object.freeze({\n platform: function () {\n if (!disposed) return inspectHostPlatform(ctx);\n return Object.freeze({\n web: typeof window !== \"undefined\", host: \"unavailable\",\n dsmStandalone: null, dsmLanguage: null, appLocale: null,\n systemVersion: null, fullVersion: null, theme: null\n });\n },\n setTitle: function (title) {\n if (disposed) return { status: \"unavailable\" };\n if (typeof title !== \"string\") return { status: \"invalid-input\" };\n try {\n var platform = inspectHostPlatform(ctx);\n if (platform.host === \"dsm\") {\n if (typeof ctx.appWindow.setTitle !== \"function\") return { status: \"unsupported\" };\n ctx.appWindow.setTitle(title, undefined, true);\n return { status: \"ok\", target: \"dsm-window\" };\n }\n if (!platform.web) return { status: \"unavailable\" };\n if (typeof document === \"undefined\") return { status: \"unsupported\" };\n document.title = title;\n return { status: \"ok\", target: \"document\" };\n } catch (error) {\n return { status: \"failed\" };\n }\n },\n activateWindow: function () {\n if (disposed) return { status: \"unavailable\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var win = ctx.appWindow;\n var activate = typeof win.toFront === \"function\" ? win.toFront : win.activate;\n if (typeof activate !== \"function\") return { status: \"unsupported\" };\n // DSM minimizes by hiding; show preserves maximized geometry, unlike restore.\n if (win.hidden === true || win.minimized === true ||\n (typeof win.isVisible === \"function\" && win.isVisible() === false)) {\n if (typeof win.show !== \"function\") return { status: \"unsupported\" };\n win.show();\n }\n activate.call(win);\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n },\n requestClose: function () {\n if (disposed) return { status: \"unavailable\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var win = ctx.appWindow;\n // DSM returns a short-circuit value; only truthy means standalone main.\n if (typeof win.close !== \"function\" || typeof win.isStandaloneMainWindow !== \"function\" ||\n win.isStandaloneMainWindow()) return { status: \"unsupported\" };\n if (win.canClose === false) return { status: \"blocked\" };\n win.close();\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n },\n // DSM's own banner sign-out, for an App that hides the banner (ui.banner: hidden).\n signOut: function () {\n if (disposed) return { status: \"unavailable\" };\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n var sds = SYNO.SDS, logout = sds.Utils && sds.Utils.Logout;\n if (!logout || typeof logout.action !== \"function\") return { status: \"unsupported\" };\n if (sds.StatusNotifier) sds.StatusNotifier.fireEvent(\"logout\");\n window.onbeforeunload = sds.onBasicBeforeUnload;\n logout.action();\n return { status: \"requested\" };\n } catch (error) { return { status: \"failed\" }; }\n },\n openApp: function (appId) { return launchApp(appId, {}); },\n openURL: function (raw) {\n if (disposed || typeof window === \"undefined\") return { status: \"unavailable\" };\n if (typeof raw !== \"string\" || !raw || /[\\s\\x00-\\x1f\\x7f]/.test(raw)) return { status: \"invalid-input\" };\n if (typeof URL !== \"function\") return { status: \"unsupported\" };\n var url;\n try { url = new URL(raw); } catch (error) { return { status: \"invalid-input\" }; }\n if ((url.protocol !== \"http:\" && url.protocol !== \"https:\") || url.username || url.password) return { status: \"invalid-input\" };\n if (typeof window.open !== \"function\") return { status: \"unsupported\" };\n try {\n var opened = window.open(url.href, \"_blank\", \"noopener,noreferrer\");\n return { status: \"requested\", windowHandleAvailable: !!opened };\n } catch (error) { return { status: \"failed\" }; }\n },\n openFileManager: function (path) { return navigateFileStation(path, true); },\n revealFile: function (path) { return navigateFileStation(path, false); },\n openFile: unsupportedOperation,\n showFileDetails: unsupportedOperation,\n openAppSetting: unsupportedOperation,\n subscribe: function (event, listener) {\n if (disposed) return { status: \"unavailable\" };\n if (typeof listener !== \"function\") return { status: \"invalid-input\" };\n if (event === \"window-activated\") {\n var target = ctx.appWindow, bindings = [], timer = null, activeActivation = true;\n function cancelActivation() {\n if (timer !== null) clearTimeout(timer);\n timer = null;\n }\n function signalActivation() {\n if (disposed || !activeActivation) return;\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") { cancelActivation(); return; }\n if (timer !== null) return;\n // One return can produce visible, focus and AppWindow activate signals.\n timer = setTimeout(function () {\n timer = null;\n if (!disposed && activeActivation &&\n !(typeof document !== \"undefined\" && document.visibilityState === \"hidden\")) listener();\n }, 50);\n }\n function bindActivation(object, name, fn, ext) {\n bindings.push(function () {\n if (ext) object.un(name, fn, object);\n else object.removeEventListener(name, fn);\n });\n if (ext) object.on(name, fn, object);\n else object.addEventListener(name, fn);\n }\n function unsubscribeActivation() {\n if (!activeActivation) return;\n activeActivation = false;\n cancelActivation();\n bindings.splice(0).forEach(function (unbind) { try { unbind(); } catch (error) {} });\n target = null;\n listener = null;\n var index = subscriptions.indexOf(unsubscribeActivation);\n if (index !== -1) subscriptions.splice(index, 1);\n }\n try {\n var platform = inspectHostPlatform(ctx);\n if (!platform.web) return { status: \"unavailable\" };\n if (platform.host === \"dsm\") {\n if (typeof target.on !== \"function\" || typeof target.un !== \"function\") return { status: \"unsupported\" };\n // DSM show/toFront reactivates a minimized AppWindow. restore alone\n // changes maximized geometry and is not an activation signal.\n bindActivation(target, \"activate\", signalActivation, true);\n bindActivation(target, \"deactivate\", cancelActivation, true);\n bindActivation(target, \"hide\", cancelActivation, true);\n }\n if (platform.host !== \"dsm\" || platform.dsmStandalone === true) {\n if (typeof document === \"undefined\" || typeof window.addEventListener !== \"function\" ||\n typeof window.removeEventListener !== \"function\" || typeof document.addEventListener !== \"function\" ||\n typeof document.removeEventListener !== \"function\") { unsubscribeActivation(); return { status: \"unsupported\" }; }\n bindActivation(window, \"focus\", signalActivation, false);\n bindActivation(document, \"visibilitychange\", signalActivation, false);\n }\n subscriptions.push(unsubscribeActivation);\n return Object.freeze({ status: \"subscribed\", dispose: unsubscribeActivation });\n } catch (error) { unsubscribeActivation(); return { status: \"failed\" }; }\n }\n if (event !== \"window-resize\") return { status: \"unsupported\" };\n var win, callback = listener, active = true;\n function handler() { if (!disposed && callback) callback(); }\n function unsubscribe() {\n if (!active) return;\n active = false;\n callback = null;\n var target = win;\n win = null;\n var index = subscriptions.indexOf(unsubscribe);\n if (index !== -1) subscriptions.splice(index, 1);\n try { if (target) target.un(\"resize\", handler, target); } catch (error) {}\n }\n try {\n if (inspectHostPlatform(ctx).host !== \"dsm\") return { status: \"unsupported\" };\n win = ctx.appWindow;\n if (typeof win.on !== \"function\" || typeof win.un !== \"function\") return { status: \"unsupported\" };\n subscriptions.push(unsubscribe);\n win.on(\"resize\", handler, win);\n if (disposed) return { status: \"unavailable\" };\n return Object.freeze({ status: \"subscribed\", dispose: unsubscribe });\n } catch (error) {\n unsubscribe();\n return { status: \"failed\" };\n }\n },\n dispose: function () {\n if (disposed) return;\n disposed = true;\n if (revealRecovery) revealRecovery.cancel();\n revealRecovery = null;\n subscriptions.slice().forEach(function (unsubscribe) { unsubscribe(); });\n ctx = null;\n }\n });\n}";
3
3
  /** A static, per-package factory for independent web shells; no Ext or transport. */
4
4
  export declare function renderHostAdapterScript(packageId: string): string;
5
5
  export declare function hostScriptName(build: number): string;
@@ -130,6 +130,63 @@ function createHostAdapter(ctx) {
130
130
  subscribe: function (event, listener) {
131
131
  if (disposed) return { status: "unavailable" };
132
132
  if (typeof listener !== "function") return { status: "invalid-input" };
133
+ if (event === "window-activated") {
134
+ var target = ctx.appWindow, bindings = [], timer = null, activeActivation = true;
135
+ function cancelActivation() {
136
+ if (timer !== null) clearTimeout(timer);
137
+ timer = null;
138
+ }
139
+ function signalActivation() {
140
+ if (disposed || !activeActivation) return;
141
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") { cancelActivation(); return; }
142
+ if (timer !== null) return;
143
+ // One return can produce visible, focus and AppWindow activate signals.
144
+ timer = setTimeout(function () {
145
+ timer = null;
146
+ if (!disposed && activeActivation &&
147
+ !(typeof document !== "undefined" && document.visibilityState === "hidden")) listener();
148
+ }, 50);
149
+ }
150
+ function bindActivation(object, name, fn, ext) {
151
+ bindings.push(function () {
152
+ if (ext) object.un(name, fn, object);
153
+ else object.removeEventListener(name, fn);
154
+ });
155
+ if (ext) object.on(name, fn, object);
156
+ else object.addEventListener(name, fn);
157
+ }
158
+ function unsubscribeActivation() {
159
+ if (!activeActivation) return;
160
+ activeActivation = false;
161
+ cancelActivation();
162
+ bindings.splice(0).forEach(function (unbind) { try { unbind(); } catch (error) {} });
163
+ target = null;
164
+ listener = null;
165
+ var index = subscriptions.indexOf(unsubscribeActivation);
166
+ if (index !== -1) subscriptions.splice(index, 1);
167
+ }
168
+ try {
169
+ var platform = inspectHostPlatform(ctx);
170
+ if (!platform.web) return { status: "unavailable" };
171
+ if (platform.host === "dsm") {
172
+ if (typeof target.on !== "function" || typeof target.un !== "function") return { status: "unsupported" };
173
+ // DSM show/toFront reactivates a minimized AppWindow. restore alone
174
+ // changes maximized geometry and is not an activation signal.
175
+ bindActivation(target, "activate", signalActivation, true);
176
+ bindActivation(target, "deactivate", cancelActivation, true);
177
+ bindActivation(target, "hide", cancelActivation, true);
178
+ }
179
+ if (platform.host !== "dsm" || platform.dsmStandalone === true) {
180
+ if (typeof document === "undefined" || typeof window.addEventListener !== "function" ||
181
+ typeof window.removeEventListener !== "function" || typeof document.addEventListener !== "function" ||
182
+ typeof document.removeEventListener !== "function") { unsubscribeActivation(); return { status: "unsupported" }; }
183
+ bindActivation(window, "focus", signalActivation, false);
184
+ bindActivation(document, "visibilitychange", signalActivation, false);
185
+ }
186
+ subscriptions.push(unsubscribeActivation);
187
+ return Object.freeze({ status: "subscribed", dispose: unsubscribeActivation });
188
+ } catch (error) { unsubscribeActivation(); return { status: "failed" }; }
189
+ }
133
190
  if (event !== "window-resize") return { status: "unsupported" };
134
191
  var win, callback = listener, active = true;
135
192
  function handler() { if (!disposed && callback) callback(); }
@@ -16,7 +16,7 @@ export type HostURLResult = {
16
16
  } | {
17
17
  status: "unsupported" | "unavailable" | "invalid-input" | "failed";
18
18
  };
19
- export type HostEvent = "window-resize" | "host-theme-change" | "host-language-change";
19
+ export type HostEvent = "window-resize" | "window-activated" | "host-theme-change" | "host-language-change";
20
20
  export type HostSubscriptionResult = {
21
21
  status: "subscribed";
22
22
  dispose(): void;
@@ -1135,10 +1135,10 @@ function readCapabilities(value, c) {
1135
1135
  if (name === "composeMounts" && setting === true)
1136
1136
  result.composeMounts = true;
1137
1137
  else if (name === "webapi") {
1138
- if (validWebAPIProfiles(setting))
1138
+ if (validWebAPIProfiles(setting, true))
1139
1139
  result.webapi = setting;
1140
1140
  else
1141
- c.fail("CAPABILITY_INVALID", "webapi requires named profiles with purpose and exact API/method/version lists.");
1141
+ c.fail("CAPABILITY_INVALID", "webapi requires named profiles with purpose and exact API/method/version lists; optional purpose_i18n uses supported locales and nonempty text without trailing periods.");
1142
1142
  }
1143
1143
  else if (name === "delegate") {
1144
1144
  if (validDelegate(setting))
@@ -399,6 +399,7 @@ export const ROOT_RUNTIME = `function createRootAccess(options) {
399
399
  }, verify);
400
400
  }
401
401
  return {
402
+ fileDelegate: options.fileDelegate,
402
403
  webapiProfiles: options.webapiProfiles || {},
403
404
  status: function () { return (isAdmin() ? adminStatus() : userStatus()).then(publish); },
404
405
  authorize: function (password, selectedScope) {
@@ -1,3 +1,4 @@
1
+ import { webapiPurposeLocales } from '../runtime/webapi-profile.js';
1
2
  import { lstatSync, readFileSync, readdirSync } from 'node:fs';
2
3
  import { join, relative } from 'node:path';
3
4
  import { resolvedSdkLaunch } from '../contract/app-launch.js';
@@ -6,6 +7,16 @@ const SKIP_DIRECTORIES = new Set(['node_modules', 'dist', 'build', 'coverage', '
6
7
  /** Advisory source heuristic, not Vue compilation or cross-file data-flow analysis. */
7
8
  export function uiGuidanceWarnings(manifest) {
8
9
  const warnings = [];
10
+ for (const [name, profile] of Object.entries(manifest.capabilities.webapi ?? {})) {
11
+ const missing = webapiPurposeLocales.filter(locale => !profile.purpose_i18n?.[locale]);
12
+ if (missing.length)
13
+ warnings.push({
14
+ code: 'WEBAPI_PURPOSE_I18N_MISSING', severity: 'warning',
15
+ span: { file: 'dsm-package.yaml', line: 1, column: 1 },
16
+ message: `WebAPI profile ${name} is missing purpose_i18n locales: ${missing.join(', ')}`,
17
+ suggestion: 'Add all nine purpose_i18n translations without trailing periods; missing locales fall back to English',
18
+ });
19
+ }
9
20
  if (manifest.capabilities.identity === 'standalone' && !manifest.portal) {
10
21
  warnings.push({
11
22
  code: 'STANDALONE_IDENTITY_WITHOUT_PORTAL', severity: 'warning',
package/docs/app-entry.md CHANGED
@@ -160,3 +160,20 @@ SO_PEERCRED authorization callback (nil denies all). Its owned 0711 directory
160
160
  and 0666 socket admit connections from other packages while the callback and
161
161
  per-request checks decide authority. The entry audit accepts direct calls and
162
162
  rejects constructor aliases; custom listeners remain forbidden.
163
+
164
+
165
+ ## Host activation
166
+
167
+ `ctx.host.subscribe('window-activated', listener)` observes the injected DSM
168
+ AppWindow's `activate` event, including switching back to the App and showing it
169
+ after minimization. The desktop document is shared with other Apps, so its
170
+ browser focus events do not indicate which App is active. A full-page shell
171
+ uses visible `visibilitychange` and `window` focus; DSM standalone pages also
172
+ observe their AppWindow. Signals within 50 ms are delivered once. There is no
173
+ initial callback, and listeners receive no native event data.
174
+
175
+ The return value is `{status: 'subscribed', dispose}` when supported. Dispose
176
+ on component unmount; host disposal removes all listeners and pending delivery.
177
+ Hide/deactivate cancels queued DSM notifications. Older generated hosts report
178
+ `unsupported`, so keep a manual check available. Activation only triggers a
179
+ fresh authenticated status read; it never proves another App completed setup.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.52.9",
3
+ "version": "0.52.11",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -45,6 +45,88 @@
45
45
  "additionalProperties": false
46
46
  }
47
47
  },
48
+ "capabilities": {
49
+ "type": "object",
50
+ "properties": {
51
+ "webapi": {
52
+ "type": "object",
53
+ "additionalProperties": {
54
+ "type": "object",
55
+ "required": [
56
+ "purpose",
57
+ "apis"
58
+ ],
59
+ "properties": {
60
+ "purpose": {
61
+ "type": "string",
62
+ "minLength": 1
63
+ },
64
+ "purpose_i18n": {
65
+ "type": "object",
66
+ "properties": {
67
+ "en": {
68
+ "type": "string",
69
+ "minLength": 1,
70
+ "maxLength": 1024
71
+ },
72
+ "zh-TW": {
73
+ "type": "string",
74
+ "minLength": 1,
75
+ "maxLength": 1024
76
+ },
77
+ "zh-CN": {
78
+ "type": "string",
79
+ "minLength": 1,
80
+ "maxLength": 1024
81
+ },
82
+ "de": {
83
+ "type": "string",
84
+ "minLength": 1,
85
+ "maxLength": 1024
86
+ },
87
+ "fr": {
88
+ "type": "string",
89
+ "minLength": 1,
90
+ "maxLength": 1024
91
+ },
92
+ "ja": {
93
+ "type": "string",
94
+ "minLength": 1,
95
+ "maxLength": 1024
96
+ },
97
+ "ko": {
98
+ "type": "string",
99
+ "minLength": 1,
100
+ "maxLength": 1024
101
+ },
102
+ "es": {
103
+ "type": "string",
104
+ "minLength": 1,
105
+ "maxLength": 1024
106
+ },
107
+ "it": {
108
+ "type": "string",
109
+ "minLength": 1,
110
+ "maxLength": 1024
111
+ }
112
+ },
113
+ "additionalProperties": false
114
+ },
115
+ "apis": {
116
+ "type": "object"
117
+ },
118
+ "raw_max_bytes": {
119
+ "type": "integer",
120
+ "minimum": 0,
121
+ "maximum": 10737418240
122
+ }
123
+ },
124
+ "additionalProperties": false
125
+ }
126
+ }
127
+ },
128
+ "additionalProperties": true
129
+ },
48
130
  "identity_gateway": {"$ref": "identity-gateway.v1.schema.json"},
49
131
  "mobile": {"$ref": "mobile.v1.schema.json"},
50
132
  "i18n": {
package/skills/SKILL.md CHANGED
@@ -470,3 +470,5 @@ npm pack and tarball content checks. Run `npm run gates:full` only when the user
470
470
  explicitly requests extended matrices and integration checks. Publishing does
471
471
  not require a full-gate result. Application fixture acceptance remains scoped
472
472
  to the application task's authorization.
473
+
474
+ WebAPI profile consent: supply all nine `purpose_i18n` locales, keep English `purpose`, and heed `WEBAPI_PURPOSE_I18N_MISSING` from `check`. See [files](reference/files.md). WebAPI-only Apps need no file delegate to approve system privileges.
@@ -172,3 +172,19 @@ never widens access, and files from different users never share a grant.
172
172
  ## Container mounts
173
173
 
174
174
  Containers use a fixed package identity and never inherit the signed-in user's File Station ACL. Mount grants are distinct from user destination grants. Per-user file access requires a session/Broker Adapter, outside this change. Read [compose.md](compose.md); official ACL/project control remains blocked.
175
+
176
+
177
+ WebAPI-only Apps use the shared executor approval without a file delegate.
178
+ Do not add a delegate capability solely to enable approval. The generated entry
179
+ passes `fileDelegate` from `capabilities.delegate` to the SDK; older backends
180
+ that answer `unknown_method` to `delegate.status` have no file scope to approve.
181
+
182
+ For every `capabilities.webapi.<profile>`, retain an English `purpose` and add
183
+ `purpose_i18n` with `en`, `zh-TW`, `zh-CN`, `de`, `fr`, `ja`, `ko`, `es`, `it`.
184
+ Write nonempty descriptions without trailing periods. `check` warns about
185
+ missing locales; the UI falls back to `purpose_i18n.en`, then `purpose`.
186
+ Translations are display metadata; only the original English purpose and exact
187
+ API/method/version allowlist enter the executor policy. Use matching SDK support
188
+ for localized consent and WebAPI-only approval. Test a WebAPI-only approval form
189
+ with a backend that does not register `delegate.status`, as well as a declared
190
+ file delegate with scope selection.
@@ -132,3 +132,13 @@ the endpoint, key location and model. Do not print keys or put them in argv.
132
132
 
133
133
  Set `APP_TEST_AI_ACTION` to one authorized fixture action. Keep a deterministic
134
134
  selector/result assertion after `agent.act`; an AI assertion alone is insufficient.
135
+
136
+
137
+ For the WebAPI-only executor approval regression, build the CLI and matching SDK,
138
+ then run `node test/browser/mobile-executor.mjs --webapi-only`. Set
139
+ `SYNOPKGLAND_BROWSER_DEPS` to a directory containing the SDK, Vue/UI peers and
140
+ `playwright-core`, and `SYNOPKGLAND_SDK_DIR` to that SDK checkout. Use
141
+ `CHROMIUM_PATH` for a system Chromium. The synthetic backend omits
142
+ `delegate.status`; first approval, password retry, upgrade, non-admin and
143
+ anonymous paths verify that no file-scope query is made. This smoke does not
144
+ establish NAS runtime acceptance.