gpt4 book ai didi

javascript - Electron:在加载 mainWindow 时使用 mainWindow.webContents.send

转载 作者:行者123 更新时间:2023-11-30 14:25:52 24 4
gpt4 key购买 nike

当用户更改主题时,我使用 mainWindow.webContents.send 更改 DOM 中的类。我还将它保存在商店中,在键 theme 下。

mainWindow.webContents.send('theme:change', theme);
store.set('theme', theme);

然后在 renderer.js 中:

ipcRenderer.on('theme:change', (event, theme) => {
document.querySelector('body').className = `${theme}`;
});

这成功更改了主题并将其保存在商店中。但是,现在我希望在启动应用程序时加载该主题,而不是返回到默认值。为此,我在 app.on('ready') 中这样做:

mainWindow.webContents.send('theme:change', store.get('theme'));

然而,什么也没有发生。好像没寄过一样我哪里错了?本质上,需要做的是在应用程序加载到商店中的类时更改 body 中的类。

最佳答案

想通了。我不得不把:

mainWindow.webContents.once('dom-ready', () => {
mainWindow.webContents.send('theme:change', store.get('theme'));
})

我正在尝试 mainWindow.on('dom-ready') 这就是它不起作用的原因。

关于javascript - Electron:在加载 mainWindow 时使用 mainWindow.webContents.send,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51932846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com