dsh-split-workspace 0.8.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 +182 -84
- 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 +1048 -146
- package/lib/index.js +359 -94
- package/native/system-window.jxa +91 -0
- package/package.json +4 -2
package/lib/index.js
CHANGED
|
@@ -1,30 +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 offer "reload interface" instead of requiring a
|
|
18
|
-
* full DSH restart.
|
|
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.
|
|
19
18
|
*/
|
|
20
19
|
|
|
21
|
-
import {
|
|
20
|
+
import { spawn } from "node:child_process";
|
|
21
|
+
import { appendFileSync, closeSync, openSync, readFileSync } from "node:fs";
|
|
22
|
+
import { tmpdir } from "node:os";
|
|
23
|
+
import { resolve } from "node:path";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
22
25
|
|
|
23
|
-
const ROUTE_PATH = "/dsv/system-window";
|
|
24
26
|
const VERSION_PATH = "/dsv/version";
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
27
|
+
const RESTART_PATH = "/dsv/restart";
|
|
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");
|
|
41
|
+
/** The Desktop app has no in-app restart entry in production builds; this
|
|
42
|
+
route recreates that one action at the OS level. */
|
|
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}$/;
|
|
46
|
+
let lastRestartAt = 0;
|
|
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;
|
|
28
51
|
|
|
29
52
|
/** The plugin version currently on disk (not the one this process loaded). */
|
|
30
53
|
function packageVersion() {
|
|
@@ -36,32 +59,6 @@ function packageVersion() {
|
|
|
36
59
|
}
|
|
37
60
|
}
|
|
38
61
|
|
|
39
|
-
/** Read and JSON-parse a small request body. */
|
|
40
|
-
function readJsonBody(req) {
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
let size = 0;
|
|
43
|
-
const chunks = [];
|
|
44
|
-
req.on("data", (chunk) => {
|
|
45
|
-
size += chunk.length;
|
|
46
|
-
if (size > MAX_BODY_BYTES) {
|
|
47
|
-
reject(new Error("request body too large"));
|
|
48
|
-
req.destroy();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
chunks.push(chunk);
|
|
52
|
-
});
|
|
53
|
-
req.on("end", () => {
|
|
54
|
-
try {
|
|
55
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
56
|
-
resolve(text === "" ? {} : JSON.parse(text));
|
|
57
|
-
} catch (error) {
|
|
58
|
-
reject(error);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
req.on("error", reject);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
62
|
function respond(res, status, value) {
|
|
66
63
|
try {
|
|
67
64
|
res.writeHead(status, {
|
|
@@ -72,88 +69,356 @@ function respond(res, status, value) {
|
|
|
72
69
|
} catch {}
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
/** True when this Host was spawned by the DSH Desktop shell. */
|
|
73
|
+
function runningInDesktop() {
|
|
74
|
+
return typeof process.versions.electron === "string" && process.versions.electron !== "";
|
|
75
|
+
}
|
|
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");
|
|
78
135
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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);
|
|
82
142
|
}
|
|
83
|
-
}
|
|
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
|
+
}
|
|
84
177
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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 {}
|
|
97
193
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
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
|
+
|
|
213
|
+
/** POSIX single-quote escaping for one shell word. */
|
|
214
|
+
function shellQuote(value) {
|
|
215
|
+
return "'" + String(value).replace(/'/g, "'\\''") + "'";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The detached command that closes DSH and opens it again.
|
|
220
|
+
*
|
|
221
|
+
* macOS asks the application to quit through AppleScript, so DSH's own quit
|
|
222
|
+
* confirmation (running tasks) still runs. Windows has no comparable public
|
|
223
|
+
* quit entry, so it closes the main window and then terminates the process;
|
|
224
|
+
* the renderer warns before calling this route.
|
|
225
|
+
*/
|
|
226
|
+
export function restartCommand() {
|
|
227
|
+
const pid = process.ppid;
|
|
228
|
+
const executable = process.execPath;
|
|
229
|
+
if (process.platform === "darwin") {
|
|
230
|
+
const appBundle = resolve(executable, "../../..");
|
|
231
|
+
return {
|
|
232
|
+
command: "/bin/sh",
|
|
233
|
+
args: ["-c", [
|
|
234
|
+
"sleep 1",
|
|
235
|
+
`osascript -e 'tell application id "com.deepseek.dsh" to quit' >/dev/null 2>&1 || kill -TERM ${pid} 2>/dev/null`,
|
|
236
|
+
`n=0; while kill -0 ${pid} 2>/dev/null && [ $n -lt 120 ]; do n=$((n+1)); sleep 0.5; done`,
|
|
237
|
+
`open ${shellQuote(appBundle)} >/dev/null 2>&1`,
|
|
238
|
+
].join("; ")],
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (process.platform === "win32") {
|
|
242
|
+
const script = [
|
|
243
|
+
"Start-Sleep -Milliseconds 900",
|
|
244
|
+
`$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue`,
|
|
245
|
+
"if ($p) { $p.CloseMainWindow() | Out-Null; Start-Sleep -Milliseconds 700 }",
|
|
246
|
+
`$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue`,
|
|
247
|
+
`if ($p) { Stop-Process -Id ${pid} -Force -ErrorAction SilentlyContinue }`,
|
|
248
|
+
`for ($i = 0; $i -lt 40; $i++) { if (-not (Get-Process -Id ${pid} -ErrorAction SilentlyContinue)) { break }; Start-Sleep -Milliseconds 250 }`,
|
|
249
|
+
`Start-Process -FilePath '${String(executable).replace(/'/g, "''")}'`,
|
|
250
|
+
].join("; ");
|
|
251
|
+
return {
|
|
252
|
+
command: "powershell.exe",
|
|
253
|
+
args: ["-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", script],
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
command: "/bin/sh",
|
|
258
|
+
args: ["-c", [
|
|
259
|
+
"sleep 1",
|
|
260
|
+
`kill -TERM ${pid} 2>/dev/null`,
|
|
261
|
+
`n=0; while kill -0 ${pid} 2>/dev/null && [ $n -lt 120 ]; do n=$((n+1)); sleep 0.5; done`,
|
|
262
|
+
`setsid ${shellQuote(executable)} >/dev/null 2>&1 &`,
|
|
263
|
+
].join("; ")],
|
|
101
264
|
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Close and reopen the Desktop app without blocking the HTTP response. */
|
|
268
|
+
function scheduleRestart() {
|
|
269
|
+
const now = Date.now();
|
|
270
|
+
if (now - lastRestartAt < RESTART_COOLDOWN_MS) return false;
|
|
271
|
+
lastRestartAt = now;
|
|
272
|
+
setTimeout(() => {
|
|
273
|
+
try {
|
|
274
|
+
const command = restartCommand();
|
|
275
|
+
spawn(command.command, command.args, {
|
|
276
|
+
detached: true,
|
|
277
|
+
stdio: "ignore",
|
|
278
|
+
windowsHide: true,
|
|
279
|
+
}).unref();
|
|
280
|
+
} catch (error) {
|
|
281
|
+
try { console.warn("[dsh-split-workspace] restart failed:", error); } catch {}
|
|
282
|
+
}
|
|
283
|
+
}, 250);
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
102
286
|
|
|
287
|
+
/** @param {import('@deepseek-ai/cordis').Context} ctx */
|
|
288
|
+
export function apply(ctx) {
|
|
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
|
+
}
|
|
103
298
|
ctx.inject(["webServer"], (webCtx) => {
|
|
104
299
|
webCtx.effect(() => {
|
|
105
|
-
const
|
|
300
|
+
const disposeVersion = webCtx.webServer.register({
|
|
106
301
|
kind: "exact",
|
|
107
|
-
path:
|
|
108
|
-
handler:
|
|
302
|
+
path: VERSION_PATH,
|
|
303
|
+
handler: (req, res) => {
|
|
304
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
305
|
+
respond(res, 405, { ok: false, error: "method" });
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const version = packageVersion();
|
|
309
|
+
if (version === null) {
|
|
310
|
+
respond(res, 503, { ok: false, error: "version" });
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
respond(res, 200, { ok: true, version });
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
const disposeRestart = webCtx.webServer.register({
|
|
317
|
+
kind: "exact",
|
|
318
|
+
path: RESTART_PATH,
|
|
319
|
+
handler: (req, res) => {
|
|
109
320
|
if (req.method !== "POST") {
|
|
110
321
|
respond(res, 405, { ok: false, error: "method" });
|
|
111
322
|
return;
|
|
112
323
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
body = await readJsonBody(req);
|
|
116
|
-
} catch {
|
|
117
|
-
respond(res, 400, { ok: false, error: "body" });
|
|
324
|
+
if (!requestOriginAllowed(req)) {
|
|
325
|
+
respond(res, 403, { ok: false, error: "origin" });
|
|
118
326
|
return;
|
|
119
327
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
respond(res, 400, { ok: false, error: "session" });
|
|
328
|
+
if (req.headers["x-dsv-restart"] !== "1") {
|
|
329
|
+
respond(res, 403, { ok: false, error: "confirm" });
|
|
123
330
|
return;
|
|
124
331
|
}
|
|
332
|
+
if (!runningInDesktop()) {
|
|
333
|
+
respond(res, 200, { ok: false, mode: "web", error: "not-desktop" });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const scheduled = scheduleRestart();
|
|
337
|
+
respond(res, 200, { ok: true, mode: "desktop", platform: process.platform, pending: scheduled !== true });
|
|
338
|
+
},
|
|
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 = "";
|
|
125
349
|
try {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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);
|
|
132
364
|
} catch (error) {
|
|
133
|
-
|
|
365
|
+
nativeWindowLog("warn", "help asset missing: " + HELP_ASSETS[name]);
|
|
366
|
+
respond(res, 404, { ok: false, error: "asset" });
|
|
134
367
|
}
|
|
135
368
|
},
|
|
136
369
|
});
|
|
137
|
-
const
|
|
370
|
+
const disposeNativeWindow = webCtx.webServer.register({
|
|
138
371
|
kind: "exact",
|
|
139
|
-
path:
|
|
372
|
+
path: NATIVE_WINDOW_PATH,
|
|
140
373
|
handler: (req, res) => {
|
|
141
|
-
if (req.method !== "
|
|
374
|
+
if (req.method !== "POST" && req.method !== "GET") {
|
|
142
375
|
respond(res, 405, { ok: false, error: "method" });
|
|
143
376
|
return;
|
|
144
377
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
respond(res, 503, { ok: false, error: "version" });
|
|
378
|
+
if (!requestOriginAllowed(req)) {
|
|
379
|
+
respond(res, 403, { ok: false, error: "origin" });
|
|
148
380
|
return;
|
|
149
381
|
}
|
|
150
|
-
|
|
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
|
+
});
|
|
151
414
|
},
|
|
152
415
|
});
|
|
153
416
|
return () => {
|
|
154
|
-
try { disposeWindow(); } catch {}
|
|
155
417
|
try { disposeVersion(); } catch {}
|
|
418
|
+
try { disposeRestart(); } catch {}
|
|
419
|
+
try { disposeHelpAssets(); } catch {}
|
|
420
|
+
try { disposeNativeWindow(); } catch {}
|
|
156
421
|
};
|
|
157
422
|
}, "split-workspace: host routes");
|
|
158
423
|
});
|
|
159
|
-
}
|
|
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"
|