mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-25 19:08:04 +01:00
Rename files
This commit is contained in:
46
ts/main/NativeThemeNotifier.main.ts
Normal file
46
ts/main/NativeThemeNotifier.main.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { BrowserWindow } from 'electron';
|
||||
import { ipcMain as ipc, nativeTheme } from 'electron';
|
||||
|
||||
import type { NativeThemeState } from '../types/NativeThemeNotifier.d.ts';
|
||||
|
||||
function getState(): NativeThemeState {
|
||||
return {
|
||||
shouldUseDarkColors: nativeTheme.shouldUseDarkColors,
|
||||
};
|
||||
}
|
||||
|
||||
export class NativeThemeNotifier {
|
||||
readonly #listeners = new Set<BrowserWindow>();
|
||||
|
||||
public initialize(): void {
|
||||
nativeTheme.on('updated', () => {
|
||||
this.#notifyListeners();
|
||||
});
|
||||
|
||||
ipc.on('native-theme:init', event => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
event.returnValue = getState();
|
||||
});
|
||||
}
|
||||
|
||||
public addWindow(window: BrowserWindow): void {
|
||||
if (this.#listeners.has(window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#listeners.add(window);
|
||||
|
||||
window.once('closed', () => {
|
||||
this.#listeners.delete(window);
|
||||
});
|
||||
}
|
||||
|
||||
#notifyListeners(): void {
|
||||
for (const window of this.#listeners) {
|
||||
window.webContents.send('native-theme:changed', getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user