Add options to menu, export menu config

This commit is contained in:
TC
2020-04-12 18:52:43 +02:00
parent 1c56e7fea6
commit 1de6f3e2ed

86
menu.js
View File

@ -1,29 +1,75 @@
const { app, Menu } = require("electron");
const { isPluginEnabled, enablePlugin, disablePlugin } = require("./store");
const { getAllPlugins } = require("./plugins/utils");
const {
isPluginEnabled,
enablePlugin,
disablePlugin,
autoUpdate,
isAppVisible,
isTrayEnabled,
setOptions,
} = require("./store");
module.exports.setApplicationMenu = () => {
const menuTemplate = [
{
label : "Plugins",
submenu: getAllPlugins().map(plugin => {
return {
label : plugin,
type : "checkbox",
checked: isPluginEnabled(plugin),
click : item => {
if (item.checked) {
enablePlugin(plugin);
} else {
disablePlugin(plugin);
}
const mainMenuTemplate = [
{
label: "Plugins",
submenu: getAllPlugins().map((plugin) => {
return {
label: plugin,
type: "checkbox",
checked: isPluginEnabled(plugin),
click: (item) => {
if (item.checked) {
enablePlugin(plugin);
} else {
disablePlugin(plugin);
}
};
})
}
];
},
};
}),
},
{
label: "Options",
submenu: [
{
label: "Auto-update",
type: "checkbox",
checked: autoUpdate(),
click: (item) => {
setOptions({ autoUpdates: item.checked });
},
},
{
label: "Tray",
submenu: [
{
label: "Disabled",
type: "radio",
checked: !isTrayEnabled(),
click: () => setOptions({ tray: false, appVisible: true }),
},
{
label: "Enabled + app visible",
type: "radio",
checked: isTrayEnabled() && isAppVisible(),
click: () => setOptions({ tray: true, appVisible: true }),
},
{
label: "Enabled + app hidden",
type: "radio",
checked: isTrayEnabled() && !isAppVisible(),
click: () => setOptions({ tray: true, appVisible: false }),
},
],
},
],
},
];
module.exports.mainMenuTemplate = mainMenuTemplate;
module.exports.setApplicationMenu = () => {
const menuTemplate = [...mainMenuTemplate];
if (process.platform === "darwin") {
const name = app.getName();
menuTemplate.unshift({