推进 text12 接续和 control-page session readiness workflow
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
export function createControlPageSessionLoadState({
|
||||
phase,
|
||||
panelReady = false,
|
||||
apiReady = false,
|
||||
controlViewReady = false,
|
||||
stateBundle = null,
|
||||
workflowStatus = null,
|
||||
controlView = null,
|
||||
error = null,
|
||||
} = {}) {
|
||||
return {
|
||||
phase,
|
||||
panelReady,
|
||||
apiReady,
|
||||
controlViewReady,
|
||||
stateBundle,
|
||||
workflowStatus,
|
||||
controlView,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
export function loadMachineSessionForControlPageWorkflow({
|
||||
getPanelWindow,
|
||||
getPanelApi,
|
||||
getControlView,
|
||||
} = {}) {
|
||||
if (typeof getPanelWindow !== "function") {
|
||||
throw new Error("A panel window getter is required.");
|
||||
}
|
||||
if (typeof getPanelApi !== "function") {
|
||||
throw new Error("A panel API getter is required.");
|
||||
}
|
||||
if (typeof getControlView !== "function") {
|
||||
throw new Error("A control view getter is required.");
|
||||
}
|
||||
|
||||
let panelWindow = null;
|
||||
let panelApi = null;
|
||||
let controlView = null;
|
||||
try {
|
||||
panelWindow = getPanelWindow();
|
||||
panelApi = getPanelApi();
|
||||
controlView = getControlView();
|
||||
} catch (error) {
|
||||
return createControlPageSessionLoadState({
|
||||
phase: "error",
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
|
||||
if (!panelWindow) {
|
||||
return createControlPageSessionLoadState({
|
||||
phase: "waiting-panel",
|
||||
});
|
||||
}
|
||||
|
||||
if (!panelApi) {
|
||||
return createControlPageSessionLoadState({
|
||||
phase: "waiting-api",
|
||||
panelReady: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (!controlView) {
|
||||
return createControlPageSessionLoadState({
|
||||
phase: "waiting-session",
|
||||
panelReady: true,
|
||||
apiReady: true,
|
||||
stateBundle: panelApi.getMachineSessionStateBundle?.() ?? null,
|
||||
workflowStatus: panelApi.getMachineSessionWorkflowStatus?.() ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
return createControlPageSessionLoadState({
|
||||
phase: "ready",
|
||||
panelReady: true,
|
||||
apiReady: true,
|
||||
controlViewReady: true,
|
||||
stateBundle: panelApi.getMachineSessionStateBundle?.() ?? null,
|
||||
workflowStatus: panelApi.getMachineSessionWorkflowStatus?.() ?? null,
|
||||
controlView,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user