推进 INI 面板 launch manifest compatibility predicate
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
||||
refreshMachineSessionControlPage,
|
||||
controlPageStatusText,
|
||||
renderMachineSessionControlView,
|
||||
isSupportedIniPanelLaunchApiManifest,
|
||||
} from "../runtime/ui/ini-panel/ui-shell.js";
|
||||
```
|
||||
|
||||
@@ -92,6 +93,9 @@ Use `createIniPanelLaunchApiSchema()`,
|
||||
`linuxCncIniPanelLaunchApi.getLaunchApiSchema()`, or `manifestVersion` when an
|
||||
outer shell needs to check launch manifest compatibility before consuming these
|
||||
fields.
|
||||
Use `isSupportedIniPanelLaunchApiManifest()` or
|
||||
`linuxCncIniPanelLaunchApi.isSupportedLaunchApiManifest()` for a read-only
|
||||
compatibility predicate before using a launch manifest.
|
||||
|
||||
The control-page refresh workflow lives in
|
||||
`runtime/ui/ini-panel/control-page-refresh-workflow.js`. Use
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
import {
|
||||
createIniPanelLauncherLinkViewModel,
|
||||
createIniPanelShellViewModel,
|
||||
isSupportedIniPanelLaunchApiManifest,
|
||||
} from "./ui-shell.js";
|
||||
|
||||
const shellViewModel = createIniPanelShellViewModel();
|
||||
@@ -90,6 +91,7 @@
|
||||
}
|
||||
|
||||
window.linuxCncIniPanelLaunchApi = {
|
||||
isSupportedLaunchApiManifest: isSupportedIniPanelLaunchApiManifest,
|
||||
getLaunchApiSchema: () => shellViewModel.launchApiSchema,
|
||||
getLaunchApiManifest: () => shellViewModel.launchApiManifest,
|
||||
getLauncherLinks: () => shellViewModel.launcherLinks,
|
||||
|
||||
@@ -77,12 +77,23 @@ export function createIniPanelLaunchApiSchema() {
|
||||
};
|
||||
}
|
||||
|
||||
export function isSupportedIniPanelLaunchApiManifest(manifest, schema = createIniPanelLaunchApiSchema()) {
|
||||
if (!manifest || typeof manifest !== "object") {
|
||||
return false;
|
||||
}
|
||||
if (manifest.apiName !== schema.apiName || manifest.manifestVersion !== schema.manifestVersion) {
|
||||
return false;
|
||||
}
|
||||
return schema.fields.every((fieldName) => Object.hasOwn(manifest, fieldName));
|
||||
}
|
||||
|
||||
export function createIniPanelLaunchApiManifest(entries = getVisibleIniPanelEntries()) {
|
||||
const schema = createIniPanelLaunchApiSchema();
|
||||
return {
|
||||
apiName: schema.apiName,
|
||||
manifestVersion: schema.manifestVersion,
|
||||
methods: [
|
||||
"isSupportedLaunchApiManifest",
|
||||
"getLaunchApiSchema",
|
||||
"getLaunchApiManifest",
|
||||
"getLauncherLinks",
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
const launchDoc = await loadLaunchFrame();
|
||||
const launchApi = launchDoc.defaultView.linuxCncIniPanelLaunchApi;
|
||||
if (
|
||||
!launchApi?.isSupportedLaunchApiManifest ||
|
||||
!launchApi?.getLaunchApiSchema ||
|
||||
!launchApi?.getLaunchApiManifest ||
|
||||
!launchApi?.getLauncherLinks ||
|
||||
@@ -85,6 +86,16 @@
|
||||
"launch API schema persistence field",
|
||||
);
|
||||
const launchApiManifest = launchApi.getLaunchApiManifest();
|
||||
assertEqual(
|
||||
launchApi.isSupportedLaunchApiManifest(launchApiManifest),
|
||||
true,
|
||||
"launch API supports manifest",
|
||||
);
|
||||
assertEqual(
|
||||
launchApi.isSupportedLaunchApiManifest({ ...launchApiManifest, manifestVersion: 2 }),
|
||||
false,
|
||||
"launch API rejects unsupported manifest version",
|
||||
);
|
||||
assertEqual(
|
||||
launchApiManifest.apiName,
|
||||
"ini-panel-launch",
|
||||
@@ -97,7 +108,7 @@
|
||||
);
|
||||
assertEqual(
|
||||
launchApiManifest.methods.join(","),
|
||||
"getLaunchApiSchema,getLaunchApiManifest,getLauncherLinks,getControlPageApiMethods",
|
||||
"isSupportedLaunchApiManifest,getLaunchApiSchema,getLaunchApiManifest,getLauncherLinks,getControlPageApiMethods",
|
||||
"launch API manifest methods",
|
||||
);
|
||||
assertEqual(
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
readMachineSessionReadonlyStatus,
|
||||
refreshMachineSessionControlPage,
|
||||
getVisibleIniPanelEntries,
|
||||
isSupportedIniPanelLaunchApiManifest,
|
||||
} from "../../../runtime/ui/ini-panel/ui-shell.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
@@ -48,6 +49,7 @@ const requiredShellExports = [
|
||||
"createIniPanelShellViewModel",
|
||||
"getIniPanelEntryByHref",
|
||||
"getVisibleIniPanelEntries",
|
||||
"isSupportedIniPanelLaunchApiManifest",
|
||||
"createMachineSessionControlPageController",
|
||||
"createMachineSessionReadonlyStatus",
|
||||
"createMachineSessionReadonlyStatusApiManifest",
|
||||
@@ -102,6 +104,7 @@ assert.deepEqual(createIniPanelShellViewModel().pages, getVisibleIniPanelEntries
|
||||
assert.deepEqual(createIniPanelShellViewModel().launcherLinks, createIniPanelLauncherLinkViewModel());
|
||||
assert.deepEqual(createIniPanelShellViewModel().launchApiSchema, createIniPanelLaunchApiSchema());
|
||||
assert.deepEqual(createIniPanelShellViewModel().launchApiManifest, createIniPanelLaunchApiManifest());
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest(createIniPanelShellViewModel().launchApiManifest), true);
|
||||
assert.equal(createIniPanelShellViewModel().launchApiManifest.manifestVersion, createIniPanelLaunchApiSchema().manifestVersion);
|
||||
assert.deepEqual(
|
||||
createIniPanelShellViewModel().controlPage.contract,
|
||||
@@ -137,8 +140,10 @@ assert.equal(typeof createIniPanelShellViewModel().controlPage.renderView, "func
|
||||
assert.match(shellText, /\bexport function createControlPageBrowserApiMethods\b/);
|
||||
assert.match(shellText, /\bexport function createIniPanelLaunchApiSchema\b/);
|
||||
assert.match(shellText, /\bexport function createIniPanelLaunchApiManifest\b/);
|
||||
assert.match(shellText, /\bexport function isSupportedIniPanelLaunchApiManifest\b/);
|
||||
assert.match(controlPageText, /\bgetControlPageApiMethods\b/);
|
||||
assert.match(launchText, /\blinuxCncIniPanelLaunchApi\b/);
|
||||
assert.match(launchText, /\bisSupportedLaunchApiManifest\b/);
|
||||
assert.match(launchText, /\bgetLaunchApiSchema\b/);
|
||||
assert.match(launchText, /\bgetLaunchApiManifest\b/);
|
||||
assert.match(launchText, /\bgetControlPageApiMethods\b/);
|
||||
@@ -150,6 +155,8 @@ assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageContract\
|
||||
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.readControlPageStatus\b/);
|
||||
assert.match(docText, /\bcreateIniPanelLaunchApiManifest\b/);
|
||||
assert.match(docText, /\bcreateIniPanelLaunchApiSchema\b/);
|
||||
assert.match(docText, /\bisSupportedIniPanelLaunchApiManifest\b/);
|
||||
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.isSupportedLaunchApiManifest\b/);
|
||||
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getLaunchApiSchema\b/);
|
||||
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getLaunchApiManifest\b/);
|
||||
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getControlPageApiMethods\b/);
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
createIniPanelLaunchApiSchema,
|
||||
createIniPanelShellViewModel,
|
||||
getVisibleIniPanelEntries,
|
||||
isSupportedIniPanelLaunchApiManifest,
|
||||
} from "../../../runtime/ui/ini-panel/ui-shell.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
@@ -38,6 +39,7 @@ assert.deepEqual(manifest, {
|
||||
apiName: "ini-panel-launch",
|
||||
manifestVersion: 1,
|
||||
methods: [
|
||||
"isSupportedLaunchApiManifest",
|
||||
"getLaunchApiSchema",
|
||||
"getLaunchApiManifest",
|
||||
"getLauncherLinks",
|
||||
@@ -88,6 +90,13 @@ assert.deepEqual(manifest, {
|
||||
assert.deepEqual(createIniPanelShellViewModel().launchApiManifest, manifest);
|
||||
assert.deepEqual(createIniPanelShellViewModel().launchApiSchema, schema);
|
||||
assert.equal(createIniPanelShellViewModel().launchApiManifest.manifestVersion, schema.manifestVersion);
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest(manifest), true);
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest({ ...manifest, manifestVersion: 2 }), false);
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest({ ...manifest, apiName: "other" }), false);
|
||||
const missingFieldManifest = { ...manifest };
|
||||
delete missingFieldManifest.persistenceCapabilities;
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest(missingFieldManifest), false);
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest(null), false);
|
||||
assert.deepEqual(getVisibleIniPanelEntries(), INI_PANEL_ENTRIES);
|
||||
|
||||
manifest.visibleEntries[0].title = "changed";
|
||||
@@ -122,6 +131,8 @@ assert.deepEqual(customManifest.targetPages, [
|
||||
|
||||
assert.match(shellText, /\bexport function createIniPanelLaunchApiManifest\b/);
|
||||
assert.match(shellText, /\bexport function createIniPanelLaunchApiSchema\b/);
|
||||
assert.match(shellText, /\bexport function isSupportedIniPanelLaunchApiManifest\b/);
|
||||
assert.match(launchText, /\bisSupportedLaunchApiManifest\b/);
|
||||
assert.match(launchText, /\bgetLaunchApiSchema\b/);
|
||||
assert.match(launchText, /\bgetLaunchApiManifest\b/);
|
||||
assert.match(launchText, /\blinuxCncIniPanelLaunchApi\b/);
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
getIniPanelEntryByHref,
|
||||
getIniPanelEntryManifest,
|
||||
getVisibleIniPanelEntries,
|
||||
isSupportedIniPanelLaunchApiManifest,
|
||||
loadMachineSessionForControlPageWorkflow,
|
||||
readMachineSessionReadonlyStatus,
|
||||
refreshMachineSessionControlPage,
|
||||
@@ -55,6 +56,7 @@ assert.equal(typeof loadMachineSessionForControlPageWorkflow, "function");
|
||||
assert.equal(typeof readMachineSessionReadonlyStatus, "function");
|
||||
assert.equal(typeof refreshMachineSessionControlPage, "function");
|
||||
assert.equal(typeof renderMachineSessionControlView, "function");
|
||||
assert.equal(typeof isSupportedIniPanelLaunchApiManifest, "function");
|
||||
|
||||
const shellManifest = getIniPanelEntryManifest();
|
||||
shellManifest[0].title = "changed";
|
||||
@@ -93,6 +95,7 @@ assert.deepEqual(shellViewModel.pages, [
|
||||
assert.deepEqual(shellViewModel.launcherLinks, createIniPanelLauncherLinkViewModel());
|
||||
assert.deepEqual(shellViewModel.launchApiSchema, createIniPanelLaunchApiSchema());
|
||||
assert.deepEqual(shellViewModel.launchApiManifest, createIniPanelLaunchApiManifest());
|
||||
assert.equal(isSupportedIniPanelLaunchApiManifest(shellViewModel.launchApiManifest), true);
|
||||
assert.equal(shellViewModel.launchApiManifest.manifestVersion, createIniPanelLaunchApiSchema().manifestVersion);
|
||||
assert.deepEqual(shellViewModel.controlPage.browserApiMethods, createControlPageBrowserApiMethods());
|
||||
assert.equal(shellViewModel.controlPage.createController, createMachineSessionControlPageController);
|
||||
|
||||
Reference in New Issue
Block a user