Cassidy Williams :
I have a Menu in an Electron application, and the items look something like this:
const menuTemplate = [
// ... previous menu items
{
label: "Notifications",
submenu: [
{
label: "Enable reset notification",
type: "checkbox",
checked: true,
click: e => {
mainWindow.showResetNotification = e.checked;
}
},
{
label: "Reminder notifications",
submenu: [
{
label: "Never",
type: "radio",
click: e => {
if (e.checked) {
mainWindow.resetNotification = "never";
}
}
},
{
label: "Every 30 minutes",
type: "radio",
click: e => { /* ... */ }
},
{
label: "Every hour",
type: "radio",
checked: true,
click: e => { /* ... */ }
}
]
}
]
}
];
I want to be able to check something, and save that state so that if I re-open the application, it loads the previous state of the checked menu item (checked vs unchecked).
How can I do this in Electron? I tried local storage, but because it's the main process, it doesn't have access to that.
Thanks in advance!
Matthew Gerstman :
Use a package like electron-store
It's less than <100 lines of code and only has a few dependencies.