electron#nativeTheme TypeScript Examples
The following examples show how to use
electron#nativeTheme.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.ts From bluebubbles-server with Apache License 2.0 | 6 votes |
createTray = () => {
let iconPath = path.join(FileSystem.resources, "macos", "icons", "tray-icon-dark.png");
if (!nativeTheme.shouldUseDarkColors)
iconPath = path.join(FileSystem.resources, "macos", "icons", "tray-icon-light.png");
// If the tray is already created, just change the icon color
if (tray) {
tray.setImage(iconPath);
return;
}
try {
tray = new Tray(iconPath);
tray.setToolTip("BlueBubbles");
tray.setContextMenu(buildTray());
// Rebuild the tray each time it's clicked
tray.on("click", () => {
tray.setContextMenu(buildTray());
});
} catch (ex: any) {
Server().log('Failed to load macOS tray entry!', 'error');
Server().log(ex?.message ?? String(ex), 'debug');
}
}
Example #2
Source File: theme.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
async listenForUpdate(): Promise<ServiceResult> {
return new Promise((resolve, reject) => {
nativeTheme.off('updated', this.updateTheme);
nativeTheme.on('updated', this.updateTheme);
resolve({
code: 200,
result: null
});
});
}
Example #3
Source File: theme.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
async unlistenForUpdate(): Promise<ServiceResult> {
return new Promise((resolve, reject) => {
nativeTheme.off('updated', this.updateTheme);
resolve({
code: 200,
result: null
});
});
}
Example #4
Source File: theme.ts From shadowsocks-electron with GNU General Public License v3.0 | 6 votes |
async getSystemThemeInfo(): Promise<ServiceResult> {
return new Promise((resolve, reject) => {
resolve({
code: 200,
result: {
shouldUseDarkColors: nativeTheme.shouldUseDarkColors,
shouldUseHighContrastColors: nativeTheme.shouldUseHighContrastColors,
shouldUseInvertedColorScheme: nativeTheme.shouldUseInvertedColorScheme
}
});
});
}
Example #5
Source File: index.ts From electron-playground with MIT License | 6 votes |
// 设置顶部APP图标的操作和图标
export function setUpTray() {
const lightIcon = path.join(__dirname, '..', '..', 'resources', 'tray', 'StatusIcon_light.png')
const darkIcon = path.join(__dirname, '..', '..', 'resources', 'tray', 'StatusIcon_dark.png')
tray = new Tray(nativeTheme.shouldUseDarkColors ? darkIcon : lightIcon)
const contextMenu = Menu.buildFromTemplate([
{
label: '打开Playground',
click: () => {
restoreMainWindow()
},
},
{
label: '退出',
click: () => {
app.quit()
},
},
])
tray.setToolTip('Electron-Playground')
tray.setContextMenu(contextMenu)
nativeTheme.on('updated', () => {
tray.setImage(nativeTheme.shouldUseDarkColors ? darkIcon : lightIcon)
})
// windows下双击托盘图标打开app
tray.on('double-click', () => {
restoreMainWindow()
})
}
Example #6
Source File: index.ts From TidGi-Desktop with Mozilla Public License 2.0 | 6 votes |
/**
* Do some side effect when config change, update other services or filesystem
* @param preference new preference settings
*/
private async reactWhenPreferencesChanged<K extends keyof IPreferences>(key: K, value: IPreferences[K]): Promise<void> {
// maybe pauseNotificationsBySchedule or pauseNotifications or ...
if (key.startsWith('pauseNotifications')) {
await this.notificationService.updatePauseNotificationsInfo();
}
if (key === 'themeSource') {
nativeTheme.themeSource = value as IPreferences['themeSource'];
}
if (key === 'language') {
await requestChangeLanguage(value as string);
}
}
Example #7
Source File: settings.ts From fluent-reader with BSD 3-Clause "New" or "Revised" License | 6 votes |
export function setThemeListener(manager: WindowManager) {
nativeTheme.removeAllListeners()
nativeTheme.on("updated", () => {
if (manager.hasWindow()) {
let contents = manager.mainWindow.webContents
if (!contents.isDestroyed()) {
contents.send("theme-updated", nativeTheme.shouldUseDarkColors)
}
}
})
}
Example #8
Source File: electron.ts From fluent-reader with BSD 3-Clause "New" or "Revised" License | 6 votes |
ipcMain.handle("import-all-settings", (_, configs: SchemaTypes) => {
restarting = true
store.clear()
for (let [key, value] of Object.entries(configs)) {
// @ts-ignore
store.set(key, value)
}
performUpdate(store)
nativeTheme.themeSource = store.get("theme", ThemeSettings.Default)
setTimeout(
() => {
winManager.mainWindow.close()
},
process.platform === "darwin" ? 1000 : 0
) // Why ???
})
Example #9
Source File: window.ts From fluent-reader with BSD 3-Clause "New" or "Revised" License | 5 votes |
createWindow = () => {
if (!this.hasWindow()) {
this.mainWindow = new BrowserWindow({
title: "Fluent Reader",
backgroundColor:
process.platform === "darwin"
? "#00000000"
: nativeTheme.shouldUseDarkColors
? "#282828"
: "#faf9f8",
vibrancy: "sidebar",
x: this.mainWindowState.x,
y: this.mainWindowState.y,
width: this.mainWindowState.width,
height: this.mainWindowState.height,
minWidth: 992,
minHeight: 600,
frame: process.platform === "darwin",
titleBarStyle: "hiddenInset",
fullscreenable: process.platform === "darwin",
show: false,
webPreferences: {
webviewTag: true,
contextIsolation: true,
spellcheck: false,
preload: path.join(
app.getAppPath(),
(app.isPackaged ? "dist/" : "") + "preload.js"
),
nativeWindowOpen: false,
},
})
this.mainWindowState.manage(this.mainWindow)
this.mainWindow.on("ready-to-show", () => {
this.mainWindow.show()
this.mainWindow.focus()
if (!app.isPackaged) this.mainWindow.webContents.openDevTools()
})
this.mainWindow.loadFile(
(app.isPackaged ? "dist/" : "") + "index.html"
)
this.mainWindow.on("maximize", () => {
this.mainWindow.webContents.send("maximized")
})
this.mainWindow.on("unmaximize", () => {
this.mainWindow.webContents.send("unmaximized")
})
this.mainWindow.on("enter-full-screen", () => {
this.mainWindow.webContents.send("enter-fullscreen")
})
this.mainWindow.on("leave-full-screen", () => {
this.mainWindow.webContents.send("leave-fullscreen")
})
this.mainWindow.on("focus", () => {
this.mainWindow.webContents.send("window-focus")
})
this.mainWindow.on("blur", () => {
this.mainWindow.webContents.send("window-blur")
})
this.mainWindow.webContents.on("context-menu", (_, params) => {
if (params.selectionText) {
this.mainWindow.webContents.send(
"window-context-menu",
[params.x, params.y],
params.selectionText
)
}
})
}
}
Example #10
Source File: settings.ts From fluent-reader with BSD 3-Clause "New" or "Revised" License | 5 votes |
ipcMain.on("get-theme-dark-color", event => {
event.returnValue = nativeTheme.shouldUseDarkColors
})
Example #11
Source File: settings.ts From fluent-reader with BSD 3-Clause "New" or "Revised" License | 5 votes |
ipcMain.handle("set-theme", (_, theme: ThemeSettings) => {
store.set(THEME_STORE_KEY, theme)
nativeTheme.themeSource = theme
})
Example #12
Source File: electron.ts From fluent-reader with BSD 3-Clause "New" or "Revised" License | 5 votes |
function init() {
performUpdate(store)
nativeTheme.themeSource = store.get("theme", ThemeSettings.Default)
}
Example #13
Source File: index.ts From TidGi-Desktop with Mozilla Public License 2.0 | 5 votes |
private shouldUseDarkColorsSync(): boolean {
return nativeTheme.shouldUseDarkColors;
}
Example #14
Source File: index.ts From TidGi-Desktop with Mozilla Public License 2.0 | 5 votes |
private async init(): Promise<void> {
const themeSource = await this.preferenceService.get('themeSource');
// apply theme
nativeTheme.themeSource = themeSource;
nativeTheme.addListener('updated', () => {
this.updateThemeSubject({ shouldUseDarkColors: this.shouldUseDarkColorsSync() });
});
}
Example #15
Source File: background.ts From cashcash-desktop with MIT License | 5 votes |
nativeTheme.themeSource = 'light';
Example #16
Source File: index.ts From bluebubbles-server with Apache License 2.0 | 5 votes |
private getTheme() {
nativeTheme.on("updated", () => {
this.setTheme(nativeTheme.shouldUseDarkColors);
});
}
Example #17
Source File: main.ts From bluebubbles-server with Apache License 2.0 | 5 votes |
app.on("ready", () => {
createTray();
createWindow();
nativeTheme.on("updated", () => {
createTray();
});
});