////目标css
<link rel="stylesheet" id="theme_css" href="路径">
////ts
//参数 能够去 electron api 了解
import { Menu, MenuItemConstructorOptions, BrowserWindow, nativeTheme } from "electron";
export class MainMenu {
public static Setup(): void {
const template: MenuItemConstructorOptions[] =
[
{
label: '主题转换', submenu: [
{
label: 'dark',
click: () => {
let allWins = BrowserWindow.getAllWindows();
if(allWins != null && allWins.length > 0)
{
//切换 菜单色 黑
nativeTheme.themeSource = 'dark';
allWins.forEach( win => win.webContents.send('change_theme' , 'dark') );
}
}
},
{
label: 'white',
click: () => {
let allWins = BrowserWindow.getAllWindows();
if(allWins != null && allWins.length > 0)
{
//切换菜单色 白
nativeTheme.themeSource = 'light';
allWins.forEach( win => win.webContents.send('change_theme' , 'white') );
}
}
}
]
}
];
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
}
///主进程
import { MainMenu(设定的名字) } from "路径";
function createWindow() {
//菜单颜色
nativeTheme.themeSource = 'dark';
MainMenu.Setup();
}
app.on("ready", createWindow);