dsh-split-workspace 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -0
- package/README.md +110 -44
- package/docs/screenshots/help-footer-menu.png +0 -0
- package/docs/screenshots/help-session-menu.png +0 -0
- package/docs/screenshots/help-settings.png +0 -0
- package/docs/screenshots/system-window.png +0 -0
- package/lib/client.js +845 -133
- package/lib/index.js +260 -110
- package/native/system-window.jxa +91 -0
- package/package.json +4 -2
package/lib/index.js
CHANGED
|
@@ -1,39 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Host half of dsh-split-workspace.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* DSH Desktop runs this Host in a Node child process with no Electron APIs, and
|
|
5
|
+
* its main window denies `window.open` (http/https goes to the system browser).
|
|
6
|
+
* No plugin-facing BrowserWindow API exists, so the Host cannot open a native
|
|
7
|
+
* Electron window; the one-conversation "independent window" therefore lives in
|
|
8
|
+
* the client as a first-class in-app surface.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* It also serves the on-disk plugin version so a running page can notice a
|
|
17
|
-
* freshly installed bundle, and it can close and reopen the Desktop app: DSH
|
|
18
|
-
* production builds have no in-app restart entry, so the split menu's
|
|
19
|
-
* "Restart DSH" action asks this Host to perform the OS-level quit and
|
|
20
|
-
* relaunch (the Host is a Node child of the Electron shell).
|
|
10
|
+
* This half adds the actions a renderer cannot perform alone:
|
|
11
|
+
* - it serves the on-disk plugin version, so a running page notices a freshly
|
|
12
|
+
* installed bundle;
|
|
13
|
+
* - it closes and reopens the Desktop app, because production DSH builds have
|
|
14
|
+
* no in-app restart entry (the split menu and update chip call this);
|
|
15
|
+
* - it opens a real, independent OS window on macOS: an AppKit NSWindow hosted
|
|
16
|
+
* by the system WebView (osascript), loading the Host's authenticated web
|
|
17
|
+
* client with a hash marker. The renderer never receives the launch token.
|
|
21
18
|
*/
|
|
22
19
|
|
|
23
20
|
import { spawn } from "node:child_process";
|
|
24
|
-
import { readFileSync } from "node:fs";
|
|
21
|
+
import { appendFileSync, closeSync, openSync, readFileSync } from "node:fs";
|
|
22
|
+
import { tmpdir } from "node:os";
|
|
25
23
|
import { resolve } from "node:path";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
26
25
|
|
|
27
|
-
const ROUTE_PATH = "/dsv/system-window";
|
|
28
26
|
const VERSION_PATH = "/dsv/version";
|
|
29
27
|
const RESTART_PATH = "/dsv/restart";
|
|
30
|
-
const
|
|
28
|
+
const NATIVE_WINDOW_PATH = "/dsv/system-window";
|
|
29
|
+
/** Help-card screenshots shipped in docs/screenshots and served same-origin. */
|
|
30
|
+
const HELP_ASSET_PATH = "/dsv/help";
|
|
31
|
+
const HELP_ASSET_DIR = new URL("../docs/screenshots/", import.meta.url);
|
|
32
|
+
const HELP_ASSETS = {
|
|
33
|
+
"session-menu.png": "help-session-menu.png",
|
|
34
|
+
"footer-menu.png": "help-footer-menu.png",
|
|
35
|
+
"settings.png": "help-settings.png",
|
|
36
|
+
};
|
|
37
|
+
/** Header a same-page action must send; blocks cross-site form posts. */
|
|
38
|
+
const NATIVE_WINDOW_CONFIRM = "x-dsv-system-window";
|
|
39
|
+
const NATIVE_WINDOW_SCRIPT = fileURLToPath(new URL("../native/system-window.jxa", import.meta.url));
|
|
40
|
+
const NATIVE_WINDOW_LOG = resolve(tmpdir(), "dsh-split-workspace-system-window.log");
|
|
31
41
|
/** The Desktop app has no in-app restart entry in production builds; this
|
|
32
42
|
route recreates that one action at the OS level. */
|
|
33
43
|
const RESTART_COOLDOWN_MS = 15000;
|
|
44
|
+
/** Client and Host agree on this session-id alphabet (see src/client/04-tree.js). */
|
|
45
|
+
const SESSION_ID_PATTERN = /^[A-Za-z0-9._:@+-]{1,160}$/;
|
|
34
46
|
let lastRestartAt = 0;
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
/** Live osascript helper processes by session id, so a Host shutdown also
|
|
48
|
+
closes the windows and the menu can offer enter/exit state. */
|
|
49
|
+
const nativeWindows = new Map();
|
|
50
|
+
let nativeWindowExitHook = false;
|
|
37
51
|
|
|
38
52
|
/** The plugin version currently on disk (not the one this process loaded). */
|
|
39
53
|
function packageVersion() {
|
|
@@ -45,32 +59,6 @@ function packageVersion() {
|
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
61
|
|
|
48
|
-
/** Read and JSON-parse a small request body. */
|
|
49
|
-
function readJsonBody(req) {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
let size = 0;
|
|
52
|
-
const chunks = [];
|
|
53
|
-
req.on("data", (chunk) => {
|
|
54
|
-
size += chunk.length;
|
|
55
|
-
if (size > MAX_BODY_BYTES) {
|
|
56
|
-
reject(new Error("request body too large"));
|
|
57
|
-
req.destroy();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
chunks.push(chunk);
|
|
61
|
-
});
|
|
62
|
-
req.on("end", () => {
|
|
63
|
-
try {
|
|
64
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
65
|
-
resolve(text === "" ? {} : JSON.parse(text));
|
|
66
|
-
} catch (error) {
|
|
67
|
-
reject(error);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
req.on("error", reject);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
62
|
function respond(res, status, value) {
|
|
75
63
|
try {
|
|
76
64
|
res.writeHead(status, {
|
|
@@ -86,6 +74,142 @@ function runningInDesktop() {
|
|
|
86
74
|
return typeof process.versions.electron === "string" && process.versions.electron !== "";
|
|
87
75
|
}
|
|
88
76
|
|
|
77
|
+
/** Allow the application origin and local web clients, never a foreign site. */
|
|
78
|
+
function requestOriginAllowed(req) {
|
|
79
|
+
const origin = req.headers.origin;
|
|
80
|
+
if (typeof origin !== "string" || origin === "") return true;
|
|
81
|
+
return origin === "dsh-app://app"
|
|
82
|
+
|| /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/iu.test(origin);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Append one diagnostic line; never include the tokenized URL. */
|
|
86
|
+
function nativeWindowLog(level, message) {
|
|
87
|
+
try {
|
|
88
|
+
appendFileSync(NATIVE_WINDOW_LOG, `[${new Date().toISOString()}] ${level} ${message}\n`);
|
|
89
|
+
} catch {}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Session ids that currently have a live native window. */
|
|
93
|
+
function nativeWindowSessions() {
|
|
94
|
+
const sessions = [];
|
|
95
|
+
for (const [sessionId, child] of nativeWindows) {
|
|
96
|
+
if (child.exitCode === null && child.signalCode === null) sessions.push(sessionId);
|
|
97
|
+
}
|
|
98
|
+
return sessions;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Spawn the macOS helper window. The tokenized URL is passed as an argument
|
|
103
|
+
* (visible only to the same-user process table) and is never returned to the
|
|
104
|
+
* renderer.
|
|
105
|
+
*/
|
|
106
|
+
function openNativeSystemWindow(webCtx, res, sessionId) {
|
|
107
|
+
if (process.platform !== "darwin") {
|
|
108
|
+
respond(res, 200, { ok: false, error: "unsupported-platform", platform: process.platform });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const existing = nativeWindows.get(sessionId);
|
|
112
|
+
if (existing !== undefined && existing.exitCode === null && existing.signalCode === null) {
|
|
113
|
+
// One window per conversation: asking again just reports the open state.
|
|
114
|
+
respond(res, 200, { ok: true, mode: "native", platform: process.platform, reused: true });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const connection = webCtx.get("connection");
|
|
118
|
+
if (connection === null || connection === undefined || typeof connection.authenticatedUrl !== "function") {
|
|
119
|
+
nativeWindowLog("warn", "connection service is unavailable");
|
|
120
|
+
respond(res, 503, { ok: false, error: "connection" });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let url;
|
|
124
|
+
try {
|
|
125
|
+
url = connection.authenticatedUrl(webCtx.webServer.getOrigin() + "/");
|
|
126
|
+
} catch (error) {
|
|
127
|
+
nativeWindowLog("warn", "could not mint the authenticated URL: " + String(error));
|
|
128
|
+
respond(res, 503, { ok: false, error: "web-server" });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const marker = "#dsv-system-window=" + encodeURIComponent(sessionId);
|
|
132
|
+
let child;
|
|
133
|
+
try {
|
|
134
|
+
const logFd = openSync(NATIVE_WINDOW_LOG, "a");
|
|
135
|
+
try {
|
|
136
|
+
child = spawn("/usr/bin/osascript", ["-l", "JavaScript", NATIVE_WINDOW_SCRIPT, url + marker], {
|
|
137
|
+
detached: true,
|
|
138
|
+
stdio: ["ignore", logFd, logFd],
|
|
139
|
+
});
|
|
140
|
+
} finally {
|
|
141
|
+
closeSync(logFd);
|
|
142
|
+
}
|
|
143
|
+
} catch (error) {
|
|
144
|
+
nativeWindowLog("warn", "could not spawn the system window: " + String(error));
|
|
145
|
+
respond(res, 500, { ok: false, error: "spawn" });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
nativeWindows.set(sessionId, child);
|
|
149
|
+
child.once("exit", (code) => {
|
|
150
|
+
if (nativeWindows.get(sessionId) === child) nativeWindows.delete(sessionId);
|
|
151
|
+
if (code !== 0) nativeWindowLog("warn", "system window exited with code " + String(code));
|
|
152
|
+
});
|
|
153
|
+
child.once("error", (error) => {
|
|
154
|
+
if (nativeWindows.get(sessionId) === child) nativeWindows.delete(sessionId);
|
|
155
|
+
nativeWindowLog("warn", "system window process error: " + String(error));
|
|
156
|
+
});
|
|
157
|
+
child.unref();
|
|
158
|
+
respond(res, 200, { ok: true, mode: "native", platform: process.platform });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Close one session's native window, if it is still open. */
|
|
162
|
+
function closeNativeSystemWindow(res, sessionId) {
|
|
163
|
+
const child = nativeWindows.get(sessionId);
|
|
164
|
+
if (child === undefined) {
|
|
165
|
+
respond(res, 200, { ok: true, mode: "native", closed: false });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
nativeWindows.delete(sessionId);
|
|
169
|
+
let closed = false;
|
|
170
|
+
try {
|
|
171
|
+
closed = child.kill() === true;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
nativeWindowLog("warn", "could not close the system window: " + String(error));
|
|
174
|
+
}
|
|
175
|
+
respond(res, 200, { ok: true, mode: "native", closed });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Read a bounded JSON body and hand back one validated window request. */
|
|
179
|
+
function readWindowRequest(req, done) {
|
|
180
|
+
let body = "";
|
|
181
|
+
let settled = false;
|
|
182
|
+
const finish = (value) => {
|
|
183
|
+
if (settled) return;
|
|
184
|
+
settled = true;
|
|
185
|
+
done(value);
|
|
186
|
+
};
|
|
187
|
+
req.on("data", (chunk) => {
|
|
188
|
+
if (settled) return;
|
|
189
|
+
body += chunk;
|
|
190
|
+
if (body.length > 8192) {
|
|
191
|
+
finish(undefined);
|
|
192
|
+
try { req.destroy(); } catch {}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
req.on("end", () => {
|
|
196
|
+
if (settled) return;
|
|
197
|
+
let sessionId;
|
|
198
|
+
let action = "open";
|
|
199
|
+
try {
|
|
200
|
+
const parsed = JSON.parse(body === "" ? "{}" : body);
|
|
201
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
202
|
+
if (typeof parsed.sessionId === "string") sessionId = parsed.sessionId;
|
|
203
|
+
if (parsed.action === "close") action = "close";
|
|
204
|
+
}
|
|
205
|
+
} catch {}
|
|
206
|
+
finish(typeof sessionId === "string" && SESSION_ID_PATTERN.test(sessionId)
|
|
207
|
+
? { sessionId, action }
|
|
208
|
+
: undefined);
|
|
209
|
+
});
|
|
210
|
+
req.on("error", () => { finish(undefined); });
|
|
211
|
+
}
|
|
212
|
+
|
|
89
213
|
/** POSIX single-quote escaping for one shell word. */
|
|
90
214
|
function shellQuote(value) {
|
|
91
215
|
return "'" + String(value).replace(/'/g, "'\\''") + "'";
|
|
@@ -162,66 +286,17 @@ function scheduleRestart() {
|
|
|
162
286
|
|
|
163
287
|
/** @param {import('@deepseek-ai/cordis').Context} ctx */
|
|
164
288
|
export function apply(ctx) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const standaloneUrl = (sessionId) => {
|
|
175
|
-
const app = getService("webApp");
|
|
176
|
-
const connection = getService("connection");
|
|
177
|
-
const origin = app !== null && app !== undefined && typeof app.getAdvertisedUrl === "function"
|
|
178
|
-
? app.getAdvertisedUrl()
|
|
179
|
-
: null;
|
|
180
|
-
if (typeof origin !== "string" || origin === "") return null;
|
|
181
|
-
let base = origin;
|
|
182
|
-
if (connection !== null && connection !== undefined && typeof connection.authenticatedUrl === "function") {
|
|
183
|
-
const authenticated = connection.authenticatedUrl(origin);
|
|
184
|
-
if (typeof authenticated === "string" && authenticated !== "") base = authenticated;
|
|
185
|
-
}
|
|
186
|
-
const url = new URL(base);
|
|
187
|
-
url.hash = "dsvWindow=" + encodeURIComponent(sessionId);
|
|
188
|
-
return url.href;
|
|
189
|
-
};
|
|
190
|
-
|
|
289
|
+
// A Host shutdown should not leave standalone OS windows behind.
|
|
290
|
+
if (!nativeWindowExitHook) {
|
|
291
|
+
nativeWindowExitHook = true;
|
|
292
|
+
process.once("exit", () => {
|
|
293
|
+
for (const child of nativeWindows) {
|
|
294
|
+
try { child.kill(); } catch {}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
191
298
|
ctx.inject(["webServer"], (webCtx) => {
|
|
192
299
|
webCtx.effect(() => {
|
|
193
|
-
const disposeWindow = webCtx.webServer.register({
|
|
194
|
-
kind: "exact",
|
|
195
|
-
path: ROUTE_PATH,
|
|
196
|
-
handler: async (req, res) => {
|
|
197
|
-
if (req.method !== "POST") {
|
|
198
|
-
respond(res, 405, { ok: false, error: "method" });
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
let body;
|
|
202
|
-
try {
|
|
203
|
-
body = await readJsonBody(req);
|
|
204
|
-
} catch {
|
|
205
|
-
respond(res, 400, { ok: false, error: "body" });
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const sessionId = body !== null && typeof body === "object" ? body.sessionId : undefined;
|
|
209
|
-
if (typeof sessionId !== "string" || sessionId === "" || sessionId.length > MAX_SESSION_ID_LENGTH || !SESSION_ID.test(sessionId)) {
|
|
210
|
-
respond(res, 400, { ok: false, error: "session" });
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
const url = standaloneUrl(sessionId);
|
|
215
|
-
if (url === null) {
|
|
216
|
-
respond(res, 503, { ok: false, error: "unavailable" });
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
respond(res, 200, { ok: true, url });
|
|
220
|
-
} catch (error) {
|
|
221
|
-
respond(res, 500, { ok: false, error: String(error !== null && error !== undefined && error.message !== undefined ? error.message : error).slice(0, 200) });
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
300
|
const disposeVersion = webCtx.webServer.register({
|
|
226
301
|
kind: "exact",
|
|
227
302
|
path: VERSION_PATH,
|
|
@@ -246,9 +321,7 @@ export function apply(ctx) {
|
|
|
246
321
|
respond(res, 405, { ok: false, error: "method" });
|
|
247
322
|
return;
|
|
248
323
|
}
|
|
249
|
-
|
|
250
|
-
if (typeof origin === "string" && origin !== "" && origin !== "dsh-app://app"
|
|
251
|
-
&& !/^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/iu.test(origin)) {
|
|
324
|
+
if (!requestOriginAllowed(req)) {
|
|
252
325
|
respond(res, 403, { ok: false, error: "origin" });
|
|
253
326
|
return;
|
|
254
327
|
}
|
|
@@ -264,11 +337,88 @@ export function apply(ctx) {
|
|
|
264
337
|
respond(res, 200, { ok: true, mode: "desktop", platform: process.platform, pending: scheduled !== true });
|
|
265
338
|
},
|
|
266
339
|
});
|
|
340
|
+
const disposeHelpAssets = webCtx.webServer.register({
|
|
341
|
+
kind: "prefix",
|
|
342
|
+
path: HELP_ASSET_PATH,
|
|
343
|
+
handler: (req, res) => {
|
|
344
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
345
|
+
respond(res, 405, { ok: false, error: "method" });
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
let name = "";
|
|
349
|
+
try {
|
|
350
|
+
name = decodeURIComponent(new URL(req.url, "http://dsh.invalid").pathname.slice(HELP_ASSET_PATH.length)).replace(/^\/+/, "");
|
|
351
|
+
} catch {}
|
|
352
|
+
if (!Object.prototype.hasOwnProperty.call(HELP_ASSETS, name)) {
|
|
353
|
+
respond(res, 404, { ok: false, error: "asset" });
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
try {
|
|
357
|
+
const data = readFileSync(new URL(HELP_ASSETS[name], HELP_ASSET_DIR));
|
|
358
|
+
res.writeHead(200, {
|
|
359
|
+
"content-type": "image/png",
|
|
360
|
+
"content-length": data.length,
|
|
361
|
+
"cache-control": "public, max-age=3600",
|
|
362
|
+
});
|
|
363
|
+
res.end(req.method === "HEAD" ? undefined : data);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
nativeWindowLog("warn", "help asset missing: " + HELP_ASSETS[name]);
|
|
366
|
+
respond(res, 404, { ok: false, error: "asset" });
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
const disposeNativeWindow = webCtx.webServer.register({
|
|
371
|
+
kind: "exact",
|
|
372
|
+
path: NATIVE_WINDOW_PATH,
|
|
373
|
+
handler: (req, res) => {
|
|
374
|
+
if (req.method !== "POST" && req.method !== "GET") {
|
|
375
|
+
respond(res, 405, { ok: false, error: "method" });
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (!requestOriginAllowed(req)) {
|
|
379
|
+
respond(res, 403, { ok: false, error: "origin" });
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (req.headers[NATIVE_WINDOW_CONFIRM] !== "1") {
|
|
383
|
+
respond(res, 403, { ok: false, error: "confirm" });
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (!runningInDesktop()) {
|
|
387
|
+
respond(res, 200, { ok: false, mode: "web", error: "not-desktop" });
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (req.method === "GET") {
|
|
391
|
+
respond(res, 200, {
|
|
392
|
+
ok: true,
|
|
393
|
+
mode: "native",
|
|
394
|
+
platform: process.platform,
|
|
395
|
+
sessions: nativeWindowSessions(),
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
readWindowRequest(req, (request) => {
|
|
400
|
+
if (request === undefined) {
|
|
401
|
+
respond(res, 400, { ok: false, error: "session" });
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (request.action === "close") {
|
|
405
|
+
if (process.platform !== "darwin") {
|
|
406
|
+
respond(res, 200, { ok: false, error: "unsupported-platform", platform: process.platform });
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
closeNativeSystemWindow(res, request.sessionId);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
openNativeSystemWindow(webCtx, res, request.sessionId);
|
|
413
|
+
});
|
|
414
|
+
},
|
|
415
|
+
});
|
|
267
416
|
return () => {
|
|
268
|
-
try { disposeWindow(); } catch {}
|
|
269
417
|
try { disposeVersion(); } catch {}
|
|
270
418
|
try { disposeRestart(); } catch {}
|
|
419
|
+
try { disposeHelpAssets(); } catch {}
|
|
420
|
+
try { disposeNativeWindow(); } catch {}
|
|
271
421
|
};
|
|
272
422
|
}, "split-workspace: host routes");
|
|
273
423
|
});
|
|
274
|
-
}
|
|
424
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// dsh-split-workspace — native macOS system window (run by /usr/bin/osascript).
|
|
2
|
+
//
|
|
3
|
+
// DSH Desktop exposes no plugin-facing BrowserWindow API, so a "real" OS window
|
|
4
|
+
// cannot be created from the renderer or from the Node Host process. This
|
|
5
|
+
// helper is the closest native equivalent: an AppKit NSWindow with a WKWebView
|
|
6
|
+
// that loads the Host's authenticated web client. The window owns its own
|
|
7
|
+
// process (this osascript run), so it is completely independent of the DSH main
|
|
8
|
+
// window: it can be moved anywhere, resized, and closed on its own.
|
|
9
|
+
//
|
|
10
|
+
// Usage: osascript -l JavaScript system-window.jxa "<authenticated client URL>"
|
|
11
|
+
//
|
|
12
|
+
// The URL carries the Host launch token once; the page redirects itself to the
|
|
13
|
+
// clean URL and the WKWebView keeps that cookie for later windows. The client
|
|
14
|
+
// bundle then switches to system-window mode from the URL hash marker.
|
|
15
|
+
|
|
16
|
+
ObjC.import('Cocoa');
|
|
17
|
+
ObjC.import('WebKit');
|
|
18
|
+
|
|
19
|
+
function stderr(message) {
|
|
20
|
+
try {
|
|
21
|
+
const data = $.NSString.stringWithString(String(message) + '\n')
|
|
22
|
+
.dataUsingEncoding($.NSUTF8StringEncoding);
|
|
23
|
+
$.NSFileHandle.fileHandleWithStandardError.writeData(data);
|
|
24
|
+
} catch {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function run(argv) {
|
|
28
|
+
const target = argv !== undefined && argv.length > 0 ? String(argv[0]) : '';
|
|
29
|
+
if (target === '') {
|
|
30
|
+
stderr('dsh-split-workspace: system window URL is missing');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let app;
|
|
35
|
+
let win;
|
|
36
|
+
let web;
|
|
37
|
+
try {
|
|
38
|
+
app = $.NSApplication.sharedApplication;
|
|
39
|
+
// Accessory policy: the window is a normal OS window but the helper does
|
|
40
|
+
// not add a Dock icon or a menu bar of its own.
|
|
41
|
+
app.setActivationPolicy(1);
|
|
42
|
+
app.finishLaunching;
|
|
43
|
+
|
|
44
|
+
const visible = $.NSScreen.mainScreen.visibleFrame;
|
|
45
|
+
const width = Math.min(1320, Math.max(900, Math.round(visible.size.width * 0.78)));
|
|
46
|
+
const height = Math.min(920, Math.max(640, Math.round(visible.size.height * 0.86)));
|
|
47
|
+
const x = visible.origin.x + Math.round((visible.size.width - width) / 2);
|
|
48
|
+
const y = visible.origin.y + Math.round((visible.size.height - height) / 2);
|
|
49
|
+
const rect = $.NSMakeRect(x, y, width, height);
|
|
50
|
+
// Titled + closable + resizable. Miniaturize is deliberately omitted: an
|
|
51
|
+
// accessory-policy process has no Dock tile, so a minimized window could
|
|
52
|
+
// not be restored.
|
|
53
|
+
const style = $.NSWindowStyleMaskTitled | $.NSWindowStyleMaskClosable | $.NSWindowStyleMaskResizable;
|
|
54
|
+
win = $.NSWindow.alloc.initWithContentRectStyleMaskBackingDefer(rect, style, 2, false);
|
|
55
|
+
win.setTitle('DeepSeek Harness');
|
|
56
|
+
win.setMinSize($.NSMakeSize(720, 520));
|
|
57
|
+
win.setReleasedWhenClosed(false);
|
|
58
|
+
|
|
59
|
+
const config = $.WKWebViewConfiguration.alloc.init;
|
|
60
|
+
web = $.WKWebView.alloc.initWithFrameConfiguration(rect, config);
|
|
61
|
+
web.setAutoresizingMask($.NSViewWidthSizable | $.NSViewHeightSizable);
|
|
62
|
+
win.setContentView(web);
|
|
63
|
+
win.makeKeyAndOrderFront(null);
|
|
64
|
+
app.activateIgnoringOtherApps(true);
|
|
65
|
+
|
|
66
|
+
web.loadRequest($.NSURLRequest.requestWithURL($.NSURL.URLWithString(target)));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
stderr('dsh-split-workspace: system window failed: ' + String(error));
|
|
69
|
+
try { if (app !== undefined) app.terminate(null); } catch {}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Keep the native title in sync with the client's document title, and quit
|
|
74
|
+
// this helper once the user closes the window. isVisible turns false on a
|
|
75
|
+
// close; a still-opening window is ignored by the title guard below.
|
|
76
|
+
$.NSTimer.scheduledTimerWithTimeIntervalRepeatsBlock(0.7, true, function (timer) {
|
|
77
|
+
try {
|
|
78
|
+
const title = ObjC.unwrap(web.title);
|
|
79
|
+
if (typeof title === 'string' && title !== '' && title !== ObjC.unwrap(win.title)) {
|
|
80
|
+
win.setTitle(title);
|
|
81
|
+
}
|
|
82
|
+
if (win.isVisible === false) {
|
|
83
|
+
app.terminate(null);
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
// A missing title or URL is never fatal; the window stays usable.
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
app.run;
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-split-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange, movable floating windows,
|
|
5
|
+
"description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange, movable floating windows, in-app independent windows, a native OS system window (macOS), a Settings page, and a performance mode for slow machines.",
|
|
6
6
|
"icon": "./icon.svg",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "mhlywxl",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"icon.svg",
|
|
34
34
|
"docs/screenshots/*.png",
|
|
35
35
|
"docs/screenshots/*.gif",
|
|
36
|
+
"CHANGELOG.md",
|
|
37
|
+
"native/system-window.jxa",
|
|
36
38
|
"README.md",
|
|
37
39
|
"LICENSE",
|
|
38
40
|
"THIRD-PARTY-NOTICES.md"
|