@restregular/dsh-powerup 0.19.15 → 0.19.16

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/client.js CHANGED
@@ -143,6 +143,10 @@
143
143
  'page.themeBrief': '在侧边栏点一下图标,在亮色与暗色之间切换。',
144
144
  'page.themeDesc': '在左侧边栏的品牌行加入一个主题切换按钮:点击即在亮色和暗色之间切换,图标随当前配色显示(暗色显示太阳,亮色显示月亮)。主题偏好交给 DSH 自身的主题服务保存,与系统设置里的「外观」保持一致。',
145
145
  'page.themeHow': '启用本功能后,左侧边栏顶部品牌名旁会出现一个太阳/月亮图标,点击即可切换亮暗模式;关闭本功能后按钮消失,主题设置仍由 DSH 管理。',
146
+ 'page.themeSystemLabel': '同时切换操作系统主题',
147
+ 'page.themeSystemHint': '开启后点击按钮会连同 Windows 的系统亮暗模式一起切换;仅 Windows 桌面版生效,其余环境仅切换 DSH 主题。',
148
+ 'theme.osApplied': '已同时切换系统主题',
149
+ 'theme.osFailed': '系统主题切换失败,仅切换了 DSH 主题',
146
150
  'theme.toLight': '切换到亮色模式',
147
151
  'theme.toDark': '切换到暗色模式',
148
152
  'page.actions': '可用操作',
@@ -579,6 +583,10 @@
579
583
  'page.themeBrief': 'Toggle light and dark mode from a sidebar button.',
580
584
  'page.themeDesc': 'Adds a theme toggle button to the sidebar brand row: one click flips between light and dark, with the icon following the active palette (sun in dark mode, moon in light mode). The preference is persisted by DSH\'s own theme service, in sync with the Appearance setting.',
581
585
  'page.themeHow': 'Once enabled, a sun/moon icon appears next to the brand name at the top of the left sidebar; click it to switch palettes. Turning the feature off removes the button; theme preferences remain managed by DSH.',
586
+ 'page.themeSystemLabel': 'Also switch the operating system theme',
587
+ 'page.themeSystemHint': 'When on, clicking the button also flips the Windows system light/dark mode; Windows desktop only, other environments still switch the DSH theme.',
588
+ 'theme.osApplied': 'System theme switched too',
589
+ 'theme.osFailed': 'Could not switch the system theme; only the DSH theme changed',
582
590
  'theme.toLight': 'Switch to light mode',
583
591
  'theme.toDark': 'Switch to dark mode',
584
592
  'page.actions': 'What you can do',
@@ -1020,6 +1028,7 @@
1020
1028
  locateSession: true,
1021
1029
  scrollToTop: true,
1022
1030
  themeToggle: true,
1031
+ themeToggleSystem: false,
1023
1032
  contentRendering: true,
1024
1033
  dualSend: false,
1025
1034
  workspacePrompts: true,
@@ -1048,6 +1057,7 @@
1048
1057
  locateSession: parsed.locateSession !== false,
1049
1058
  scrollToTop: parsed.scrollToTop !== false,
1050
1059
  themeToggle: parsed.themeToggle !== false,
1060
+ themeToggleSystem: parsed.themeToggleSystem === true,
1051
1061
  contentRendering: parsed.contentRendering !== false,
1052
1062
  dualSend: parsed.dualSend === true,
1053
1063
  workspacePrompts: parsed.workspacePrompts !== false,
@@ -5978,6 +5988,30 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
5978
5988
  return core;
5979
5989
  }
5980
5990
 
5991
+ /**
5992
+ * Standalone toast for installers outside the React tree (e.g. the theme
5993
+ * toggle). Reuses the overlay's toast class so it looks native.
5994
+ */
5995
+ let standaloneToast = null;
5996
+ function toastMessage(message) {
5997
+ if (typeof message !== 'string' || message === '' || !hasDocumentSafe()) return;
5998
+ if (standaloneToast !== null) standaloneToast.remove();
5999
+ const node = document.createElement('div');
6000
+ node.className = 'dsh-powerup-toast';
6001
+ node.setAttribute('role', 'status');
6002
+ node.textContent = message;
6003
+ document.body.appendChild(node);
6004
+ standaloneToast = node;
6005
+ setTimeout(() => {
6006
+ if (standaloneToast === node) standaloneToast = null;
6007
+ node.remove();
6008
+ }, 2400);
6009
+ }
6010
+
6011
+ function hasDocumentSafe() {
6012
+ return typeof document !== 'undefined' && document !== null && document.body !== null;
6013
+ }
6014
+
5981
6015
  /**
5982
6016
  * DOM controller for a theme toggle button in the sidebar brand row (the
5983
6017
  * logoRow that also holds the collapsed-rail toggle). It reads the theme
@@ -5985,7 +6019,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
5985
6019
  * showing a sun glyph in dark mode (click to go light) and a moon glyph in
5986
6020
  * light mode (click to go dark). Falls back to `prefers-color-scheme` via
5987
6021
  * the active theme's colorScheme when the preference is `system`.
5988
- * @param {{getTheme?: Function, setTheme?: Function, t?: Function, isEnabled?: Function}} deps
6022
+ * When `applySystem` is enabled, the click also asks the Host to flip the
6023
+ * operating system's light/dark mode and lets DSH follow the system.
6024
+ * @param {{getTheme?: Function, setTheme?: Function, t?: Function, isEnabled?: Function, applySystem?: Function, notify?: Function}} deps
5989
6025
  */
5990
6026
  function createThemeToggleCore(deps) {
5991
6027
  const options = deps ?? {};
@@ -5993,6 +6029,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
5993
6029
  const setTheme = typeof options.setTheme === 'function' ? options.setTheme : () => {};
5994
6030
  const t = typeof options.t === 'function' ? options.t : (key) => key;
5995
6031
  const isEnabled = typeof options.isEnabled === 'function' ? options.isEnabled : () => true;
6032
+ const applySystem = typeof options.applySystem === 'function' ? options.applySystem : () => Promise.resolve({ ok: false });
6033
+ const notify = typeof options.notify === 'function' ? options.notify : () => {};
5996
6034
 
5997
6035
  let button = null;
5998
6036
  let observer = null;
@@ -6057,7 +6095,24 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
6057
6095
  button.addEventListener('click', (event) => {
6058
6096
  event.preventDefault();
6059
6097
  event.stopPropagation();
6060
- setTheme(isDark() ? 'light' : 'dark');
6098
+ const next = isDark() ? 'light' : 'dark';
6099
+ if (getSettings().themeToggleSystem === true) {
6100
+ void applySystem(next).then((result) => {
6101
+ if (result?.ok === true) {
6102
+ // Host switched the OS theme; let DSH follow the system so both
6103
+ // palettes stay in sync.
6104
+ setTheme('system');
6105
+ } else {
6106
+ setTheme(next);
6107
+ notify(t('theme.osFailed'));
6108
+ }
6109
+ }).catch(() => {
6110
+ setTheme(next);
6111
+ notify(t('theme.osFailed'));
6112
+ });
6113
+ } else {
6114
+ setTheme(next);
6115
+ }
6061
6116
  refresh();
6062
6117
  });
6063
6118
  refresh();
@@ -6114,6 +6169,16 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
6114
6169
  setTheme: (id) => {
6115
6170
  try { if (typeof theme.setTheme === 'function') theme.setTheme(id); } catch { /* ignore */ }
6116
6171
  },
6172
+ notify: toastMessage,
6173
+ applySystem: (id) => {
6174
+ const scheme = id === 'dark' ? 'dark' : 'light';
6175
+ return fetch('/dsh-powerup/api/system-theme', {
6176
+ method: 'POST',
6177
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
6178
+ body: JSON.stringify({ scheme }),
6179
+ }).then((response) => response.json().catch(() => ({ ok: false })))
6180
+ .then((data) => ({ ok: data?.ok === true, supported: data?.supported === true }));
6181
+ },
6117
6182
  });
6118
6183
  scope.effect(() => {
6119
6184
  core.start();
@@ -11337,6 +11402,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
11337
11402
  featureCard('themeToggle', QuickIcon, 'page.themeTitle', 'page.themeBrief', {
11338
11403
  descKey: 'page.themeDesc',
11339
11404
  howKey: 'page.themeHow',
11405
+ detail: settingRow('themeToggleSystem', settings.themeToggleSystem === true,
11406
+ t('page.themeSystemLabel'), t('page.themeSystemHint')),
11340
11407
  }),
11341
11408
  featureCard('launcher', LauncherIcon, 'page.launcherTitle', 'page.launcherBrief', {
11342
11409
  descKey: 'page.launcherDesc',
package/index.js CHANGED
@@ -26,6 +26,7 @@
26
26
  * for the current session's composer
27
27
  * GET /dsh-powerup/api/quick-replies → reads the current session's options
28
28
  * POST /dsh-powerup/api/quick-replies → clears them after a user message
29
+ * POST /dsh-powerup/api/system-theme → flips the Windows OS light/dark mode
29
30
  *
30
31
  * The Client half drives other plugins' installation through the built-in
31
32
  * `pluginManager` Remote. Only the process restart, the self-update handoff,
@@ -38,6 +39,7 @@
38
39
  */
39
40
 
40
41
  import { randomUUID } from 'node:crypto';
42
+ import { execFile } from 'node:child_process';
41
43
  import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
42
44
  import { dirname, join, resolve as resolvePath, sep } from 'node:path';
43
45
  import { homedir } from 'node:os';
@@ -59,10 +61,28 @@ import {
59
61
  createQuickRepliesStore,
60
62
  createQuickRepliesTool,
61
63
  } from './lib/quick-replies.js';
64
+ import { describeSystemTheme, setSystemTheme } from './lib/system-theme.js';
62
65
 
63
66
  /** Prefix owned by this plugin. */
64
67
  const ROUTE = '/dsh-powerup/api';
65
68
 
69
+ /** Run a host command with a bounded timeout, capturing its output. */
70
+ function runCommand(command, args) {
71
+ return new Promise((resolve) => {
72
+ try {
73
+ execFile(command, args, { windowsHide: true, timeout: 8000 }, (error, stdout, stderr) => {
74
+ resolve({
75
+ code: typeof error?.code === 'number' ? error.code : (error ? 1 : 0),
76
+ stdout: String(stdout ?? ''),
77
+ stderr: String(stderr ?? ''),
78
+ });
79
+ });
80
+ } catch (error) {
81
+ resolve({ code: 1, stderr: String(error?.message ?? error) });
82
+ }
83
+ });
84
+ }
85
+
66
86
  /** The bundle this pair of routes may replace while its own UI unloads. */
67
87
  const MODULE_ID = '@restregular/dsh-powerup';
68
88
 
@@ -555,11 +575,31 @@ async function handle(req, res, ctx) {
555
575
 
556
576
  const url = new URL(req.url ?? ROUTE, 'http://localhost');
557
577
  const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
558
- if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress' && op !== 'progress-requirements' && op !== 'progress-history' && op !== 'direct-ask' && op !== 'ask-title' && op !== 'quick-replies') {
578
+ if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress' && op !== 'progress-requirements' && op !== 'progress-history' && op !== 'direct-ask' && op !== 'ask-title' && op !== 'quick-replies' && op !== 'system-theme') {
559
579
  sendJson(res, { ok: false, error: 'not-found' }, 404);
560
580
  return;
561
581
  }
562
582
 
583
+ if (op === 'system-theme') {
584
+ const capability = describeSystemTheme();
585
+ if (req.method === 'GET') {
586
+ sendJson(res, { ok: true, ...capability });
587
+ return;
588
+ }
589
+ if (req.method !== 'POST') {
590
+ sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
591
+ return;
592
+ }
593
+ try {
594
+ const body = await readJsonBody(req);
595
+ const result = await setSystemTheme(body, { run: runCommand });
596
+ sendJson(res, result, result.ok ? 200 : 409);
597
+ } catch (error) {
598
+ sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
599
+ }
600
+ return;
601
+ }
602
+
563
603
  if (op === 'quick-replies') {
564
604
  const store = createQuickRepliesStore({
565
605
  file: storePath(QUICK_REPLIES_FILE),
@@ -0,0 +1,72 @@
1
+ /**
2
+ * dsh-powerup — flip the Windows OS light/dark mode.
3
+ *
4
+ * The browser cannot change the operating system palette; only the Host half
5
+ * can. On Windows the per-user preference lives under
6
+ * `HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize` with two
7
+ * DWORD values: `AppsUseLightTheme` (app palette) and `SystemUsesLightTheme`
8
+ * (taskbar/Start palette). After writing them, an `ImmersiveColorSet`
9
+ * `WM_SETTINGCHANGE` broadcast tells running apps to re-read the preference.
10
+ *
11
+ * Both writes go through `reg.exe` / PowerShell `Add-Type`, launched via the
12
+ * injected `run` callback so this module stays pure and testable. The caller
13
+ * must guarantee the request came from the loopback Host origin.
14
+ *
15
+ * @module dsh-powerup/system-theme
16
+ */
17
+
18
+ /** Registry key holding the per-user light/dark preference. */
19
+ export const PERSONALIZE_KEY = 'Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize';
20
+
21
+ /**
22
+ * Describe whether this Host can switch the OS theme.
23
+ * @param {{ platform?: string, execPath?: string }} env runtime environment
24
+ * @returns {{ supported: boolean, reason?: string }}
25
+ */
26
+ export function describeSystemTheme(env = {}) {
27
+ const platform = typeof env.platform === 'string' ? env.platform : process.platform;
28
+ if (platform !== 'win32') {
29
+ return { supported: false, reason: 'OS theme switching is only available on Windows.' };
30
+ }
31
+ return { supported: true };
32
+ }
33
+
34
+ /**
35
+ * Apply the requested OS color scheme.
36
+ * @param {{ scheme: 'light' | 'dark' }} request
37
+ * @param {{ platform?: string, run: (command: string, args: string[]) => Promise<{ code: number, stdout?: string, stderr?: string }> }} deps
38
+ * @returns {Promise<{ ok: boolean, supported: boolean, scheme?: string, reason?: string }>}
39
+ */
40
+ export async function setSystemTheme(request, deps) {
41
+ const capability = describeSystemTheme(deps ?? {});
42
+ if (!capability.supported) return { ok: false, supported: false, reason: capability.reason };
43
+ const scheme = request?.scheme === 'light' ? 'light' : request?.scheme === 'dark' ? 'dark' : null;
44
+ if (scheme === null) return { ok: false, supported: true, reason: 'scheme must be light or dark' };
45
+ const run = typeof deps?.run === 'function' ? deps.run : null;
46
+ if (run === null) return { ok: false, supported: true, reason: 'no command runner available' };
47
+
48
+ const value = scheme === 'light' ? '1' : '0';
49
+ const key = `HKCU\\${PERSONALIZE_KEY}`;
50
+ try {
51
+ for (const name of ['AppsUseLightTheme', 'SystemUsesLightTheme']) {
52
+ const result = await run('reg.exe', ['add', key, '/v', name, '/t', 'REG_DWORD', '/d', value, '/f']);
53
+ if (result?.code !== 0) {
54
+ return { ok: false, supported: true, reason: `failed to write ${name}: ${String(result?.stderr ?? '').trim()}` };
55
+ }
56
+ }
57
+ // Broadcast the settings change so running apps pick up the new palette.
58
+ // PowerShell is available on every supported Windows desktop; Add-Type is
59
+ // scoped to this process so no file is written.
60
+ const ps = [
61
+ '-NoProfile', '-NonInteractive', '-Command',
62
+ "Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;public class PowerupTheme{[DllImport(\"user32.dll\",SetLastError=true,CharSet=CharSet.Auto)]public static extern IntPtr SendMessageTimeout(IntPtr hWnd,uint Msg,UIntPtr wParam,string lParam,uint fuFlags,uint uTimeout,out UIntPtr lpdwResult);};';" +
63
+ '$r=[UIntPtr]::Zero;[void][PowerupTheme]::SendMessageTimeout([IntPtr]0xffff,0x001A,[UIntPtr]::Zero,"ImmersiveColorSet",2,1000,[ref]$r)',
64
+ ];
65
+ const broadcast = await run('powershell.exe', ps);
66
+ // The broadcast is best-effort: even if it fails the registry values are
67
+ // written and will apply to apps that start afterwards.
68
+ return { ok: true, supported: true, scheme, broadcast: broadcast?.code === 0 };
69
+ } catch (error) {
70
+ return { ok: false, supported: true, reason: String(error?.message ?? error) };
71
+ }
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.19.15",
3
+ "version": "0.19.16",
4
4
  "description": "为 DeepSeek Harness 提供一组可选的小型增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格、会话切换、定位当前会话、工作区提示词、旁路模型生成的结构化任务进度;所有功能均可在 Power-Up 页面独立开关。 · Opt-in upgrades for DeepSeek Harness: Trajectory context menu and step references, job stop reasons, one-click plugin install, an adaptive sidebar launcher, session switching, locating the current session, workspace prompts, and non-blocking model-generated structured task progress — each toggled independently on the Power-Up page.",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
@@ -26,6 +26,7 @@
26
26
  "lib/task-resume.js",
27
27
  "lib/direct-ask.js",
28
28
  "lib/quick-replies.js",
29
+ "lib/system-theme.js",
29
30
  "locale/*.json",
30
31
  "icon.svg",
31
32
  "README.md",
@@ -99,7 +100,7 @@
99
100
  "node": ">=22.13.0"
100
101
  },
101
102
  "scripts": {
102
- "test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs && node test/task-resume.mjs && node test/direct-ask.mjs && node test/quick-replies.mjs"
103
+ "test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs && node test/task-resume.mjs && node test/direct-ask.mjs && node test/quick-replies.mjs && node test/system-theme.mjs"
103
104
  },
104
105
  "license": "MIT",
105
106
  "author": "RestRegular"