Get native theme through IPC not remote
This commit is contained in:
parent
d2cc8e5aa9
commit
71572db7a9
16 changed files with 227 additions and 60 deletions
81
ts/test-electron/context/NativeThemeListener_test.ts
Normal file
81
ts/test-electron/context/NativeThemeListener_test.ts
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import {
|
||||
NativeThemeListener,
|
||||
MinimalIPC,
|
||||
SystemThemeHolder,
|
||||
} from '../../context/NativeThemeListener';
|
||||
import { NativeThemeState } from '../../types/NativeThemeNotifier.d';
|
||||
|
||||
class FakeIPC extends EventEmitter implements MinimalIPC {
|
||||
constructor(private readonly state: NativeThemeState) {
|
||||
super();
|
||||
}
|
||||
|
||||
public sendSync(channel: string) {
|
||||
assert.strictEqual(channel, 'native-theme:init');
|
||||
return this.state;
|
||||
}
|
||||
}
|
||||
|
||||
describe('NativeThemeListener', () => {
|
||||
const holder: SystemThemeHolder = { systemTheme: 'dark' };
|
||||
|
||||
it('syncs the initial native theme', () => {
|
||||
const dark = new NativeThemeListener(
|
||||
new FakeIPC({
|
||||
shouldUseDarkColors: true,
|
||||
}),
|
||||
holder
|
||||
);
|
||||
|
||||
assert.strictEqual(holder.systemTheme, 'dark');
|
||||
assert.isTrue(dark.theme.shouldUseDarkColors);
|
||||
|
||||
const light = new NativeThemeListener(
|
||||
new FakeIPC({
|
||||
shouldUseDarkColors: false,
|
||||
}),
|
||||
holder
|
||||
);
|
||||
|
||||
assert.strictEqual(holder.systemTheme, 'light');
|
||||
assert.isFalse(light.theme.shouldUseDarkColors);
|
||||
});
|
||||
|
||||
it('should react to native theme changes', () => {
|
||||
const ipc = new FakeIPC({
|
||||
shouldUseDarkColors: true,
|
||||
});
|
||||
|
||||
const listener = new NativeThemeListener(ipc, holder);
|
||||
|
||||
ipc.emit('native-theme:changed', null, <NativeThemeState>{
|
||||
shouldUseDarkColors: false,
|
||||
});
|
||||
|
||||
assert.strictEqual(holder.systemTheme, 'light');
|
||||
assert.isFalse(listener.theme.shouldUseDarkColors);
|
||||
});
|
||||
|
||||
it('should notify subscribers of native theme changes', done => {
|
||||
const ipc = new FakeIPC({
|
||||
shouldUseDarkColors: true,
|
||||
});
|
||||
|
||||
const listener = new NativeThemeListener(ipc, holder);
|
||||
|
||||
listener.subscribe(state => {
|
||||
assert.isFalse(state.shouldUseDarkColors);
|
||||
done();
|
||||
});
|
||||
|
||||
ipc.emit('native-theme:changed', null, <NativeThemeState>{
|
||||
shouldUseDarkColors: false,
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue