@owdproject/core 3.4.0 → 4.0.0-alpha.3
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 +112 -13
- package/dist/dom/index.d.mts +65 -0
- package/dist/dom/index.d.ts +65 -0
- package/dist/dom/index.mjs +224 -0
- package/dist/events/index.d.mts +70 -0
- package/dist/events/index.d.ts +70 -0
- package/dist/events/index.mjs +3 -0
- package/dist/index.d.mts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.mjs +115 -0
- package/dist/layout/index.d.mts +41 -0
- package/dist/layout/index.d.ts +41 -0
- package/dist/layout/index.mjs +64 -0
- package/dist/machines/index.d.mts +31 -0
- package/dist/machines/index.d.ts +31 -0
- package/dist/machines/index.mjs +2 -0
- package/dist/managers/index.d.mts +117 -0
- package/dist/managers/index.d.ts +117 -0
- package/dist/managers/index.mjs +6 -0
- package/dist/session/index.d.mts +57 -0
- package/dist/session/index.d.ts +57 -0
- package/dist/session/index.mjs +65 -0
- package/dist/shared/core.B0B0KfVK.mjs +865 -0
- package/dist/shared/core.B1XxB289.mjs +239 -0
- package/dist/shared/core.B3mp7ztE.mjs +237 -0
- package/dist/shared/core.BOvFdEVQ.d.ts +114 -0
- package/dist/shared/core.CsDFgGnX.mjs +40 -0
- package/dist/shared/core.Di1eFcr_.d.mts +114 -0
- package/dist/shared/core.Pd_Ogt4g.mjs +101 -0
- package/dist/shared/core.b3Xldzyu.mjs +29 -0
- package/dist/types/index.d.mts +266 -0
- package/dist/types/index.d.ts +266 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +56 -112
- package/CHANGELOG.md +0 -98
- package/DESKTOP_KERNEL.md +0 -232
- package/MIGRATION_3.3.2.md +0 -23
- package/MIGRATION_3.4.md +0 -126
- package/PLAYGROUND.md +0 -91
- package/dist/module.d.mts +0 -13
- package/dist/module.json +0 -9
- package/dist/module.mjs +0 -254
- package/dist/types.d.mts +0 -7
- package/index.ts +0 -8
- package/kit/authoring.ts +0 -340
- package/kit/defineDesktopApp.ts +0 -56
- package/module.ts +0 -203
- package/runtime/components/Application/DesktopCoreApplicationRender.vue +0 -20
- package/runtime/components/Application/DesktopCoreApplicationWindowsRender.vue +0 -38
- package/runtime/components/background/DesktopCoreBackground.vue +0 -16
- package/runtime/components/core/DesktopCore.vue +0 -43
- package/runtime/components/time/DesktopCoreTime.vue +0 -56
- package/runtime/components/window/DesktopCoreWindow.vue +0 -215
- package/runtime/components/window/DesktopCoreWindowContent.vue +0 -28
- package/runtime/components/window/DesktopCoreWindowNav.vue +0 -66
- package/runtime/components/window/DesktopCoreWindowSnapHintsBase.vue +0 -74
- package/runtime/components/workspace/DesktopCoreWorkspaceEdgeHintsBase.vue +0 -84
- package/runtime/composables/useApplicationEntries.ts +0 -51
- package/runtime/composables/useApplicationManager.ts +0 -285
- package/runtime/composables/useBlockNonInputContextMenu.ts +0 -30
- package/runtime/composables/useDesktopConfig.ts +0 -8
- package/runtime/composables/useDesktopDialogs.ts +0 -16
- package/runtime/composables/useDesktopExtension.ts +0 -8
- package/runtime/composables/useDesktopManager.ts +0 -51
- package/runtime/composables/useDesktopManifest.ts +0 -17
- package/runtime/composables/useDesktopSession.ts +0 -27
- package/runtime/composables/useDesktopShellIdentity.ts +0 -99
- package/runtime/composables/useDesktopShellOptions.ts +0 -36
- package/runtime/composables/useDesktopShellReady.ts +0 -7
- package/runtime/composables/useDesktopWorkArea.ts +0 -93
- package/runtime/composables/useTerminalManager.ts +0 -159
- package/runtime/composables/useToggleWindowMaximize.ts +0 -35
- package/runtime/composables/useWindowDragHandlers.ts +0 -47
- package/runtime/composables/useWindowSnapDrop.ts +0 -112
- package/runtime/composables/useWorkspaceEdgeDrop.ts +0 -176
- package/runtime/composables/useWorkspaceManager.ts +0 -67
- package/runtime/composables/useWorkspaceOverviewCapture.ts +0 -92
- package/runtime/composables/useWorkspaceOverviewLiveScale.ts +0 -151
- package/runtime/constants/desktopShellKeys.ts +0 -12
- package/runtime/constants/shellLayout.ts +0 -5
- package/runtime/dialogs/desktopDialogProvider.ts +0 -73
- package/runtime/internal/controllers/ApplicationController.ts +0 -351
- package/runtime/internal/controllers/WindowController.ts +0 -547
- package/runtime/plugins/01.desktop-shell-init.client.ts +0 -28
- package/runtime/plugins/02.desktop-register-desktop-apps.client.ts +0 -13
- package/runtime/plugins/resize.client.ts +0 -6
- package/runtime/stores/storeApplicationMeta.ts +0 -60
- package/runtime/stores/storeApplicationWindows.ts +0 -21
- package/runtime/stores/storeDesktop.ts +0 -71
- package/runtime/stores/storeDesktopDefaultApps.ts +0 -54
- package/runtime/stores/storeDesktopVolume.ts +0 -19
- package/runtime/stores/storeDesktopWindow.ts +0 -38
- package/runtime/stores/storeDesktopWorkspace.ts +0 -105
- package/runtime/stores/storeIds.ts +0 -35
- package/runtime/types/desktopMenu.ts +0 -10
- package/runtime/utils/initDesktopShell.ts +0 -80
- package/runtime/utils/migratePersistedStoreIds.ts +0 -57
- package/runtime/utils/utilApp.ts +0 -25
- package/runtime/utils/utilCaptureElementToCanvas.ts +0 -21
- package/runtime/utils/utilCommon.ts +0 -26
- package/runtime/utils/utilDebug.ts +0 -30
- package/runtime/utils/utilDetectSnapZone.ts +0 -57
- package/runtime/utils/utilTerminal.ts +0 -6
- package/runtime/utils/utilWindowControllerAdapter.ts +0 -15
- package/runtime/utils/utilWindowLayout.ts +0 -82
- package/runtime/utils/utilWindowMaximizeLayout.ts +0 -44
- package/runtime/utils/utilWorkspaceWindows.ts +0 -33
- package/types/index.d.ts +0 -531
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { g as globalDesktopHooks, a as globalIPCBus } from './core.Pd_Ogt4g.mjs';
|
|
2
|
+
|
|
3
|
+
function shellEscape(str) {
|
|
4
|
+
if (str === "") {
|
|
5
|
+
return "''";
|
|
6
|
+
}
|
|
7
|
+
return `${str.replace(/'/g, `'\\''`)}`;
|
|
8
|
+
}
|
|
9
|
+
function padEnd(str, len) {
|
|
10
|
+
return str.length >= len ? str : str + " ".repeat(len - str.length);
|
|
11
|
+
}
|
|
12
|
+
function formatDuration(ms) {
|
|
13
|
+
const totalSec = Math.max(0, Math.floor(ms / 1e3));
|
|
14
|
+
const m = Math.floor(totalSec / 60);
|
|
15
|
+
const s = totalSec % 60;
|
|
16
|
+
return `${String(m).padStart(2, "0")}m ${String(s).padStart(2, "0")}s`;
|
|
17
|
+
}
|
|
18
|
+
function parseCommandLine(input) {
|
|
19
|
+
const trimmed = input.trim();
|
|
20
|
+
if (!trimmed) {
|
|
21
|
+
return { name: "", args: [] };
|
|
22
|
+
}
|
|
23
|
+
const [name = "", ...args] = trimmed.split(/\s+/);
|
|
24
|
+
return { name, args };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class DesktopKeybindings {
|
|
28
|
+
windowManager;
|
|
29
|
+
workareaProvider;
|
|
30
|
+
customHandlers = /* @__PURE__ */ new Map();
|
|
31
|
+
isListening = false;
|
|
32
|
+
listenerRef;
|
|
33
|
+
constructor(windowManager, options) {
|
|
34
|
+
this.windowManager = windowManager;
|
|
35
|
+
this.workareaProvider = options?.workareaProvider;
|
|
36
|
+
}
|
|
37
|
+
register(shortcut, handler) {
|
|
38
|
+
this.customHandlers.set(shortcut.toLowerCase(), handler);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
listen() {
|
|
42
|
+
if (typeof window === "undefined" || this.isListening) {
|
|
43
|
+
return () => this.stop();
|
|
44
|
+
}
|
|
45
|
+
this.isListening = true;
|
|
46
|
+
this.listenerRef = (e) => this.handleKeyDown(e);
|
|
47
|
+
window.addEventListener("keydown", this.listenerRef);
|
|
48
|
+
return () => this.stop();
|
|
49
|
+
}
|
|
50
|
+
stop() {
|
|
51
|
+
if (typeof window !== "undefined" && this.listenerRef) {
|
|
52
|
+
window.removeEventListener("keydown", this.listenerRef);
|
|
53
|
+
}
|
|
54
|
+
this.isListening = false;
|
|
55
|
+
}
|
|
56
|
+
handleKeyDown(e) {
|
|
57
|
+
const activeEl = document.activeElement;
|
|
58
|
+
if (activeEl && (activeEl.tagName === "INPUT" || activeEl.tagName === "TEXTAREA" || activeEl.isContentEditable)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const isMetaOrCtrl = e.metaKey || e.ctrlKey;
|
|
62
|
+
const isAlt = e.altKey;
|
|
63
|
+
const isShift = e.shiftKey;
|
|
64
|
+
const key = e.key.toLowerCase();
|
|
65
|
+
if (isAlt && key === "tab") {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
this.cycleWindowFocus(isShift ? "backward" : "forward");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (isMetaOrCtrl) {
|
|
71
|
+
const focused = this.windowManager.focusedWindow;
|
|
72
|
+
const workarea = this.workareaProvider?.() ?? {
|
|
73
|
+
x: 0,
|
|
74
|
+
y: 0,
|
|
75
|
+
width: typeof window !== "undefined" ? window.innerWidth : 1920,
|
|
76
|
+
height: typeof window !== "undefined" ? window.innerHeight : 1080
|
|
77
|
+
};
|
|
78
|
+
if (key === "arrowleft" && focused) {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
this.windowManager.snapWindow(focused.id, "left-half", workarea);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (key === "arrowright" && focused) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
this.windowManager.snapWindow(focused.id, "right-half", workarea);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (key === "arrowup" && focused) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
if (!focused.state.maximized) {
|
|
91
|
+
focused.maximize();
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (key === "arrowdown" && focused) {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
if (focused.state.maximized) {
|
|
98
|
+
focused.unmaximize();
|
|
99
|
+
} else {
|
|
100
|
+
focused.minimize();
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (key === "w" && focused && !e.shiftKey) {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
this.windowManager.closeWindow(focused.id);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
cycleWindowFocus(direction) {
|
|
112
|
+
const activeWindows = Array.from(this.windowManager.getSnapshot()).filter((w) => w.active);
|
|
113
|
+
if (activeWindows.length <= 1) return;
|
|
114
|
+
const focusedId = this.windowManager.focusedWindow?.id;
|
|
115
|
+
const currentIndex = activeWindows.findIndex((w) => w.id === focusedId);
|
|
116
|
+
let nextIndex = 0;
|
|
117
|
+
if (direction === "forward") {
|
|
118
|
+
nextIndex = (currentIndex + 1) % activeWindows.length;
|
|
119
|
+
} else {
|
|
120
|
+
nextIndex = (currentIndex - 1 + activeWindows.length) % activeWindows.length;
|
|
121
|
+
}
|
|
122
|
+
const nextWin = activeWindows[nextIndex];
|
|
123
|
+
if (nextWin) {
|
|
124
|
+
this.windowManager.focusWindow(nextWin.id);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
class DesktopCommands {
|
|
130
|
+
commands = /* @__PURE__ */ new Map();
|
|
131
|
+
snapshotCache = Object.freeze([]);
|
|
132
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
133
|
+
hooks;
|
|
134
|
+
ipc;
|
|
135
|
+
constructor(options) {
|
|
136
|
+
this.hooks = options?.hooks ?? globalDesktopHooks;
|
|
137
|
+
this.ipc = options?.ipc ?? globalIPCBus;
|
|
138
|
+
}
|
|
139
|
+
getSnapshot() {
|
|
140
|
+
return this.snapshotCache;
|
|
141
|
+
}
|
|
142
|
+
subscribe(callback) {
|
|
143
|
+
this.subscribers.add(callback);
|
|
144
|
+
callback(this.getSnapshot());
|
|
145
|
+
return () => {
|
|
146
|
+
this.subscribers.delete(callback);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
notify() {
|
|
150
|
+
this.snapshotCache = Object.freeze(
|
|
151
|
+
Array.from(this.commands.values()).map(({ handler: _h, ...meta }) => Object.freeze({ ...meta }))
|
|
152
|
+
);
|
|
153
|
+
const snapshot = this.getSnapshot();
|
|
154
|
+
for (const sub of this.subscribers) {
|
|
155
|
+
try {
|
|
156
|
+
sub(snapshot);
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
register(command, handler) {
|
|
162
|
+
this.commands.set(command.name, {
|
|
163
|
+
...command,
|
|
164
|
+
handler
|
|
165
|
+
});
|
|
166
|
+
this.notify();
|
|
167
|
+
return () => {
|
|
168
|
+
this.unregister(command.name);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
unregister(name) {
|
|
172
|
+
const deleted = this.commands.delete(name);
|
|
173
|
+
if (deleted) {
|
|
174
|
+
this.notify();
|
|
175
|
+
}
|
|
176
|
+
return deleted;
|
|
177
|
+
}
|
|
178
|
+
has(name) {
|
|
179
|
+
return this.commands.has(name);
|
|
180
|
+
}
|
|
181
|
+
getCommands() {
|
|
182
|
+
return this.getSnapshot();
|
|
183
|
+
}
|
|
184
|
+
async exec(input) {
|
|
185
|
+
const { name, args } = parseCommandLine(input);
|
|
186
|
+
if (!name) return void 0;
|
|
187
|
+
const execCtx = {
|
|
188
|
+
input,
|
|
189
|
+
commandName: name,
|
|
190
|
+
args,
|
|
191
|
+
cancel: false,
|
|
192
|
+
overrideOutput: void 0
|
|
193
|
+
};
|
|
194
|
+
await this.hooks.callHook("command:before-exec", execCtx);
|
|
195
|
+
if (execCtx.cancel) {
|
|
196
|
+
return execCtx.overrideOutput ?? {
|
|
197
|
+
message: `Command "${name}" execution cancelled by policy.`,
|
|
198
|
+
isError: true
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const registered = this.commands.get(name);
|
|
202
|
+
if (!registered) {
|
|
203
|
+
const notFoundOutput = {
|
|
204
|
+
message: `${name}: command not found`,
|
|
205
|
+
isError: true
|
|
206
|
+
};
|
|
207
|
+
await this.hooks.callHook("command:after-exec", {
|
|
208
|
+
input,
|
|
209
|
+
commandName: name,
|
|
210
|
+
output: notFoundOutput
|
|
211
|
+
});
|
|
212
|
+
return notFoundOutput;
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const result = await registered.handler(args, input);
|
|
216
|
+
const output = typeof result === "string" ? { message: result, isError: false } : result;
|
|
217
|
+
this.ipc.emit("command:executed", { command: name, args }, { source: "commands" });
|
|
218
|
+
await this.hooks.callHook("command:after-exec", {
|
|
219
|
+
input,
|
|
220
|
+
commandName: name,
|
|
221
|
+
output
|
|
222
|
+
});
|
|
223
|
+
return output;
|
|
224
|
+
} catch (err) {
|
|
225
|
+
const errorOutput = {
|
|
226
|
+
message: err?.message || String(err),
|
|
227
|
+
isError: true
|
|
228
|
+
};
|
|
229
|
+
await this.hooks.callHook("command:after-exec", {
|
|
230
|
+
input,
|
|
231
|
+
commandName: name,
|
|
232
|
+
output: errorOutput
|
|
233
|
+
});
|
|
234
|
+
return errorOutput;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export { DesktopCommands as D, DesktopKeybindings as a, parseCommandLine as b, formatDuration as f, padEnd as p, shellEscape as s };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate';
|
|
2
|
+
|
|
3
|
+
const windowMachine = createMachine({
|
|
4
|
+
id: "window",
|
|
5
|
+
initial: "normal",
|
|
6
|
+
context: ({ input }) => ({
|
|
7
|
+
wasMaximized: false,
|
|
8
|
+
config: input?.config
|
|
9
|
+
}),
|
|
10
|
+
states: {
|
|
11
|
+
normal: {
|
|
12
|
+
entry: assign({ wasMaximized: false }),
|
|
13
|
+
initial: "focused",
|
|
14
|
+
states: {
|
|
15
|
+
focused: {
|
|
16
|
+
initial: "idle",
|
|
17
|
+
states: {
|
|
18
|
+
idle: {
|
|
19
|
+
on: {
|
|
20
|
+
DRAG_START: "dragging",
|
|
21
|
+
RESIZE_START: "resizing"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
dragging: {
|
|
25
|
+
on: {
|
|
26
|
+
DRAG_END: "idle",
|
|
27
|
+
SNAP_DROP: "idle"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
resizing: {
|
|
31
|
+
on: {
|
|
32
|
+
RESIZE_END: "idle"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
on: {
|
|
37
|
+
BLUR: "unfocused",
|
|
38
|
+
MAXIMIZE: "#window.maximized.focused",
|
|
39
|
+
MINIMIZE: "#window.minimized"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
unfocused: {
|
|
43
|
+
on: {
|
|
44
|
+
FOCUS: "focused",
|
|
45
|
+
MAXIMIZE: "#window.maximized.unfocused",
|
|
46
|
+
MINIMIZE: "#window.minimized"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
on: {
|
|
51
|
+
DESTROY: "closed"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
maximized: {
|
|
55
|
+
entry: assign({ wasMaximized: true }),
|
|
56
|
+
initial: "focused",
|
|
57
|
+
states: {
|
|
58
|
+
focused: {
|
|
59
|
+
on: {
|
|
60
|
+
BLUR: "unfocused",
|
|
61
|
+
RESTORE: "#window.normal.focused",
|
|
62
|
+
MINIMIZE: "#window.minimized"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
unfocused: {
|
|
66
|
+
on: {
|
|
67
|
+
FOCUS: "focused",
|
|
68
|
+
RESTORE: "#window.normal.unfocused",
|
|
69
|
+
MINIMIZE: "#window.minimized"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
on: {
|
|
74
|
+
DESTROY: "closed"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
minimized: {
|
|
78
|
+
on: {
|
|
79
|
+
RESTORE: [
|
|
80
|
+
{
|
|
81
|
+
target: "maximized.focused",
|
|
82
|
+
guard: ({ context }) => context.wasMaximized
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
target: "normal.focused"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
DESTROY: "closed"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
closed: {
|
|
92
|
+
type: "final"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const applicationMachine = createMachine({
|
|
98
|
+
id: "application",
|
|
99
|
+
initial: "idle",
|
|
100
|
+
context: ({ input }) => ({
|
|
101
|
+
id: input?.id ?? "",
|
|
102
|
+
config: input?.config,
|
|
103
|
+
windowCount: 0
|
|
104
|
+
}),
|
|
105
|
+
states: {
|
|
106
|
+
idle: {
|
|
107
|
+
on: {
|
|
108
|
+
LAUNCH: "initializing",
|
|
109
|
+
RESTORE: "initializing",
|
|
110
|
+
OPEN_WINDOW: {
|
|
111
|
+
target: "running.active",
|
|
112
|
+
actions: assign({
|
|
113
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
initializing: {
|
|
119
|
+
on: {
|
|
120
|
+
INITIALIZED: [
|
|
121
|
+
{
|
|
122
|
+
target: "running.active",
|
|
123
|
+
guard: ({ context }) => context.windowCount > 0
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
target: "ready"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
OPEN_WINDOW: {
|
|
130
|
+
actions: assign({
|
|
131
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
132
|
+
})
|
|
133
|
+
},
|
|
134
|
+
INIT_FAILED: "error"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
ready: {
|
|
138
|
+
on: {
|
|
139
|
+
LAUNCH: "running.active",
|
|
140
|
+
START_PROCESS: "running.active",
|
|
141
|
+
OPEN_WINDOW: {
|
|
142
|
+
target: "running.active",
|
|
143
|
+
actions: assign({
|
|
144
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
CLOSE_APP: "terminating"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
running: {
|
|
151
|
+
initial: "active",
|
|
152
|
+
states: {
|
|
153
|
+
active: {
|
|
154
|
+
on: {
|
|
155
|
+
MINIMIZE_ALL: "suspended",
|
|
156
|
+
SUSPEND: "suspended",
|
|
157
|
+
SIGSTOP: "suspended",
|
|
158
|
+
CLOSE_WINDOW: [
|
|
159
|
+
{
|
|
160
|
+
target: "#application.terminating",
|
|
161
|
+
guard: ({ context }) => context.windowCount - 1 <= 0,
|
|
162
|
+
actions: assign({
|
|
163
|
+
windowCount: () => 0
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
actions: assign({
|
|
168
|
+
windowCount: ({ context }) => Math.max(0, context.windowCount - 1)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
OPEN_WINDOW: {
|
|
173
|
+
actions: assign({
|
|
174
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
suspended: {
|
|
180
|
+
on: {
|
|
181
|
+
RESTORE_WINDOW: "active",
|
|
182
|
+
RESUME: "active",
|
|
183
|
+
SIGCONT: "active",
|
|
184
|
+
LAUNCH: "active",
|
|
185
|
+
OPEN_WINDOW: {
|
|
186
|
+
target: "active",
|
|
187
|
+
actions: assign({
|
|
188
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
189
|
+
})
|
|
190
|
+
},
|
|
191
|
+
CLOSE_WINDOW: [
|
|
192
|
+
{
|
|
193
|
+
target: "#application.terminating",
|
|
194
|
+
guard: ({ context }) => context.windowCount - 1 <= 0,
|
|
195
|
+
actions: assign({
|
|
196
|
+
windowCount: () => 0
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
actions: assign({
|
|
201
|
+
windowCount: ({ context }) => Math.max(0, context.windowCount - 1)
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
on: {
|
|
209
|
+
CLOSE_APP: "terminating",
|
|
210
|
+
SIGTERM: "terminating",
|
|
211
|
+
SIGKILL: "terminating"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
terminating: {
|
|
215
|
+
entry: assign({
|
|
216
|
+
windowCount: () => 0
|
|
217
|
+
}),
|
|
218
|
+
on: {
|
|
219
|
+
TERMINATED: "ready"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
error: {
|
|
223
|
+
on: {
|
|
224
|
+
RESET: "ready",
|
|
225
|
+
LAUNCH: "running.active",
|
|
226
|
+
OPEN_WINDOW: {
|
|
227
|
+
target: "running.active",
|
|
228
|
+
actions: assign({
|
|
229
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export { applicationMachine as a, windowMachine as w };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Hookable } from 'hookable';
|
|
2
|
+
import { DesktopKernelEvent, DesktopRuntimeHooks, WindowConfig, WindowState, WindowLayout, DesktopWorkareaRect, SpatialTransform } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
type EventHandler = (event: DesktopKernelEvent) => void;
|
|
5
|
+
declare class CoreIPCBus {
|
|
6
|
+
private readonly maxEvents;
|
|
7
|
+
private events;
|
|
8
|
+
private readonly listeners;
|
|
9
|
+
private eventCounter;
|
|
10
|
+
private subscribers;
|
|
11
|
+
constructor(options?: {
|
|
12
|
+
maxEvents?: number;
|
|
13
|
+
});
|
|
14
|
+
emit(channel: string, payload?: any, options?: {
|
|
15
|
+
source?: string;
|
|
16
|
+
severity?: 'info' | 'warn' | 'error';
|
|
17
|
+
}): DesktopKernelEvent;
|
|
18
|
+
on(channel: string, handler: EventHandler): () => void;
|
|
19
|
+
off(channel: string, handler: EventHandler): void;
|
|
20
|
+
getEvents(): DesktopKernelEvent[];
|
|
21
|
+
getActiveChannels(): string[];
|
|
22
|
+
clear(): void;
|
|
23
|
+
subscribe(callback: (events: DesktopKernelEvent[]) => void): () => void;
|
|
24
|
+
}
|
|
25
|
+
declare const globalIPCBus: CoreIPCBus;
|
|
26
|
+
|
|
27
|
+
declare class WindowInstance {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly model: string;
|
|
30
|
+
readonly applicationId?: string;
|
|
31
|
+
config: WindowConfig;
|
|
32
|
+
state: WindowState;
|
|
33
|
+
meta: Record<string, any>;
|
|
34
|
+
private actor;
|
|
35
|
+
private isDisposed;
|
|
36
|
+
private subscribers;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
id: string;
|
|
39
|
+
model: string;
|
|
40
|
+
applicationId?: string;
|
|
41
|
+
config: WindowConfig;
|
|
42
|
+
initialState?: Partial<WindowState>;
|
|
43
|
+
meta?: Record<string, any>;
|
|
44
|
+
workspace?: string;
|
|
45
|
+
});
|
|
46
|
+
private updateState;
|
|
47
|
+
getSnapshot(): WindowState;
|
|
48
|
+
subscribe(callback: (snapshot: WindowState) => void): () => void;
|
|
49
|
+
private notify;
|
|
50
|
+
get stateValue(): string;
|
|
51
|
+
setPosition(data: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
z?: number;
|
|
55
|
+
}): void;
|
|
56
|
+
setSize(data: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
}): void;
|
|
60
|
+
setFocus(value: boolean): void;
|
|
61
|
+
minimize(): boolean;
|
|
62
|
+
unminimize(): boolean;
|
|
63
|
+
maximize(): boolean;
|
|
64
|
+
unmaximize(): boolean;
|
|
65
|
+
toggleMaximize(): boolean;
|
|
66
|
+
startDrag(): void;
|
|
67
|
+
stopDrag(): void;
|
|
68
|
+
startResize(): void;
|
|
69
|
+
stopResize(): void;
|
|
70
|
+
setLayout(layout: WindowLayout, workarea?: DesktopWorkareaRect): boolean;
|
|
71
|
+
clearLayout(): boolean;
|
|
72
|
+
saveBoundsBeforeLayout(): void;
|
|
73
|
+
setWorkspace(workspaceId: string): void;
|
|
74
|
+
get workspace(): string;
|
|
75
|
+
setSpatialTransform(transform: SpatialTransform): void;
|
|
76
|
+
get spatial(): SpatialTransform | undefined;
|
|
77
|
+
dispose(): void;
|
|
78
|
+
}
|
|
79
|
+
declare class WindowManager {
|
|
80
|
+
private windows;
|
|
81
|
+
private snapshotCache;
|
|
82
|
+
private zIndexCounter;
|
|
83
|
+
private subscribers;
|
|
84
|
+
private hooks;
|
|
85
|
+
private ipc;
|
|
86
|
+
constructor(options?: {
|
|
87
|
+
hooks?: Hookable<DesktopRuntimeHooks>;
|
|
88
|
+
ipc?: CoreIPCBus;
|
|
89
|
+
});
|
|
90
|
+
getSnapshot(): WindowInstance[];
|
|
91
|
+
subscribe(callback: (windows: WindowInstance[]) => void): () => void;
|
|
92
|
+
private notify;
|
|
93
|
+
get(id: string): WindowInstance | undefined;
|
|
94
|
+
get focusedWindow(): WindowInstance | undefined;
|
|
95
|
+
incrementZIndex(): number;
|
|
96
|
+
addWindow(instance: WindowInstance): void;
|
|
97
|
+
createWindow(options: {
|
|
98
|
+
id: string;
|
|
99
|
+
model: string;
|
|
100
|
+
applicationId?: string;
|
|
101
|
+
config: WindowConfig;
|
|
102
|
+
initialState?: Partial<WindowState>;
|
|
103
|
+
meta?: Record<string, any>;
|
|
104
|
+
workspace?: string;
|
|
105
|
+
}): WindowInstance;
|
|
106
|
+
focusWindow(id: string): void;
|
|
107
|
+
closeWindow(id: string): boolean;
|
|
108
|
+
closeAllWindows(): void;
|
|
109
|
+
tileWindows(mode: "horizontal" | "vertical" | "grid" | undefined, workarea: DesktopWorkareaRect, workspaceId?: string, gap?: number): number;
|
|
110
|
+
setSpatialTransform(windowId: string, transform: SpatialTransform): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { CoreIPCBus as C, WindowManager as W, WindowInstance as a, globalIPCBus as g };
|
|
114
|
+
export type { EventHandler as E };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function workareaBottom(workarea) {
|
|
2
|
+
return workarea.y + workarea.height;
|
|
3
|
+
}
|
|
4
|
+
function workareaRight(workarea) {
|
|
5
|
+
return workarea.x + workarea.width;
|
|
6
|
+
}
|
|
7
|
+
function computeSnapRect(zone, workarea) {
|
|
8
|
+
const { x, y, width, height } = workarea;
|
|
9
|
+
const halfW = Math.floor(width / 2);
|
|
10
|
+
const halfH = Math.floor(height / 2);
|
|
11
|
+
switch (zone) {
|
|
12
|
+
case "maximize":
|
|
13
|
+
return { x, y, width, height };
|
|
14
|
+
case "left-half":
|
|
15
|
+
return { x, y, width: halfW, height };
|
|
16
|
+
case "right-half":
|
|
17
|
+
return { x: x + halfW, y, width: width - halfW, height };
|
|
18
|
+
case "bottom-half":
|
|
19
|
+
return { x, y: y + halfH, width, height: height - halfH };
|
|
20
|
+
case "top-left":
|
|
21
|
+
return { x, y, width: halfW, height: halfH };
|
|
22
|
+
case "top-right":
|
|
23
|
+
return { x: x + halfW, y, width: width - halfW, height: halfH };
|
|
24
|
+
case "bottom-left":
|
|
25
|
+
return { x, y: y + halfH, width: halfW, height: height - halfH };
|
|
26
|
+
case "bottom-right":
|
|
27
|
+
return {
|
|
28
|
+
x: x + halfW,
|
|
29
|
+
y: y + halfH,
|
|
30
|
+
width: width - halfW,
|
|
31
|
+
height: height - halfH
|
|
32
|
+
};
|
|
33
|
+
default: {
|
|
34
|
+
const _exhaustive = zone;
|
|
35
|
+
return _exhaustive;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { workareaRight as a, computeSnapRect as c, workareaBottom as w };
|