@lenorin/dsh-tauri-launcher 1.0.5 → 1.0.6
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/launcher/bin/dsh-launcher.exe +0 -0
- package/lib/client.js +39 -0
- package/package.json +1 -1
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -355,6 +355,45 @@ body [class*='centerCol'] {
|
|
|
355
355
|
if (document.referrer) parentOrigin = new URL(document.referrer).origin
|
|
356
356
|
} catch { /* 兜底 http://tauri.localhost */ }
|
|
357
357
|
|
|
358
|
+
// ---------- 桌面端系统主题跟随 ----------
|
|
359
|
+
// WebView2 页面里的 prefers-color-scheme 只有宿主显式设置
|
|
360
|
+
// PreferredColorScheme 才会随 Windows 变化,而 tauri/wry 未暴露该能力
|
|
361
|
+
// (wry#806),DSH 的 `system` 偏好会被冻结在启动时的取值。启动器轮询
|
|
362
|
+
// 到系统主题变化后经外壳 postMessage 转发到这里:偏好为 `system` 时把
|
|
363
|
+
// ThemeRuntime 持有的 MediaQueryList.matches(冻结值)覆盖为真实系统值
|
|
364
|
+
// 并触发重发布——偏好保持「跟随系统」不变,界面随真实系统主题切换;
|
|
365
|
+
// 用户手动选了固定主题时不干预。浏览器直开不进入本块(Chromium 原生跟随)。
|
|
366
|
+
// ⚠️ 兼容层 hack:依赖 ThemeRuntime 的 media/publish 运行时成员(无真
|
|
367
|
+
// 私有化),外壳升级若重命名则静默退化为现状(跟随失效,无副作用)。
|
|
368
|
+
const applySystemTheme = (scheme) => {
|
|
369
|
+
try {
|
|
370
|
+
const theme = ctx.get('theme')
|
|
371
|
+
if (!theme || !(theme.media instanceof MediaQueryList)) return
|
|
372
|
+
if (typeof theme.publish !== 'function') return
|
|
373
|
+
const snap = typeof theme.getTheme === 'function' ? theme.getTheme() : null
|
|
374
|
+
if (!snap || snap.preference !== 'system') return
|
|
375
|
+
if (snap.active && snap.active.colorScheme === scheme) return
|
|
376
|
+
const desc = Object.getOwnPropertyDescriptor(MediaQueryList.prototype, 'matches')
|
|
377
|
+
if (!desc || typeof desc.get !== 'function') return
|
|
378
|
+
const wantDark = scheme === 'dark'
|
|
379
|
+
Object.defineProperty(theme.media, 'matches', {
|
|
380
|
+
configurable: true,
|
|
381
|
+
get() { return wantDark }
|
|
382
|
+
})
|
|
383
|
+
theme.publish()
|
|
384
|
+
} catch { /* 主题服务异常:忽略,等待下次通知 */ }
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const onSystemThemeMessage = (event) => {
|
|
388
|
+
const data = event.data || {}
|
|
389
|
+
if (event.source !== window.parent) return
|
|
390
|
+
if (event.origin !== parentOrigin) return
|
|
391
|
+
const scheme = data.__tbSystemTheme
|
|
392
|
+
if (scheme === 'light' || scheme === 'dark') applySystemTheme(scheme)
|
|
393
|
+
}
|
|
394
|
+
window.addEventListener('message', onSystemThemeMessage)
|
|
395
|
+
ctx.effect(() => () => window.removeEventListener('message', onSystemThemeMessage), 'dsh-tauri-launcher: system theme follow')
|
|
396
|
+
|
|
358
397
|
const initNav = () => {
|
|
359
398
|
const sessions = ctx.get('sessions')
|
|
360
399
|
const store = sessions && sessions.list
|