Files
Netcatty/electron/bridges/systemTheme.test.cjs
T
陈大猫andHHXXYY123 2e3dc687cb fix(theme): continue Windows system-theme fix with registrar coverage (#4108)
* fix(theme): broadcast native system theme updates to renderers

nativeTheme.updated only fires for listeners in the main process, so a renderer sitting in system mode never learned that Windows changed the application theme. Forward the resolved preference to every window and let the settings hook re-apply it.

* fix(theme): keep terminal chrome separate from native system policy

refreshActiveChromeThemeSurfaces called setTheme(light|dark), which the main process writes into nativeTheme.themeSource. The stored preference stayed 'system' while Electron was pinned to a fixed color, so Windows application theme changes were ignored.

Only paint the surfaces here. Also re-assert a fixed independent terminal theme when the OS preference changes: the fingerprint short-circuit skipped the refresh, and the hook effect never re-ran while the terminal props stayed stable.

* test(theme): bound the new jsdom chrome tests

A hanging jsdom/React render should fail the test with its name instead of consuming the CI job budget.

* test(theme): provide native theme in bridge registrar fixtures

* test(theme): provide nativeTheme in child-process registrar fixture

The worker tests introduced in #4127 omitted nativeTheme after the system-theme listener registration became part of the production registrar. Provide a real EventEmitter, matching the transfer-limit fixture, so registrar setup succeeds without weakening production behavior.

* ci: retrigger lint-and-test after runner shutdown

The previous ubuntu-latest lint-and-test run was canceled during plugin
contract verification (annotation: "The operation was canceled."). Lint
had already passed; tests never started. Tree is unchanged.

---------

Co-authored-by: HHXXYY123 <117068187+HHXXYY123@users.noreply.github.com>
2026-11-05 23:13:41 +08:00

42 lines
1.7 KiB
JavaScript

const assert = require('node:assert/strict');
const test = require('node:test');
const { EventEmitter } = require('node:events');
const fs = require('node:fs');
const path = require('node:path');
const modulePath = path.join(__dirname, 'systemTheme.cjs');
test('native theme updates reach every live window without a plugin host', () => {
assert.ok(fs.existsSync(modulePath), 'native system theme broadcaster must exist independently of plugins');
const { registerSystemThemeListener } = require('./systemTheme.cjs');
const nativeTheme = new EventEmitter();
nativeTheme.shouldUseDarkColors = false;
const calls = [];
const live = (id) => ({
isDestroyed: () => false,
webContents: {
isDestroyed: () => false,
send: (channel, payload) => calls.push({ id, channel, payload }),
},
});
const windows = [live('main'), live('settings'),
{ isDestroyed: () => true },
{ isDestroyed: () => false, webContents: { isDestroyed: () => true } },
];
const cleanup = registerSystemThemeListener({ nativeTheme, getWindows: () => windows });
nativeTheme.shouldUseDarkColors = true;
nativeTheme.emit('updated');
nativeTheme.shouldUseDarkColors = false;
nativeTheme.emit('updated');
assert.deepEqual(calls, [
{ id: 'main', channel: 'netcatty:system-theme-changed', payload: { isDark: true } },
{ id: 'settings', channel: 'netcatty:system-theme-changed', payload: { isDark: true } },
{ id: 'main', channel: 'netcatty:system-theme-changed', payload: { isDark: false } },
{ id: 'settings', channel: 'netcatty:system-theme-changed', payload: { isDark: false } },
]);
cleanup();
nativeTheme.emit('updated');
assert.equal(calls.length, 4);
assert.equal(nativeTheme.listenerCount('updated'), 0);
});