converse-desktop/modules/menu-service.js

122 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-04-26 19:26:00 +00:00
/**
* Module for Menu functions.
*/
const {app, Menu, MenuItem, BrowserWindow} = require('electron')
2022-01-16 22:15:06 +00:00
const settingsService = require(__dirname + '/../modules/settings-service')
const prompt = require('electron-prompt');
2019-04-26 19:26:00 +00:00
const menuService = {}
2019-04-26 19:26:00 +00:00
2019-04-27 00:16:08 +00:00
2019-04-26 19:26:00 +00:00
menuService.createMenu = () => {
let converse;
const application = new Menu();
application.append(new MenuItem({
label: 'Converse Desktop'
, submenu: converse = Menu.buildFromTemplate([
{
label: 'Reconnect',
accelerator: 'CmdOrCtrl+R',
click: () => {
const activeWindow = BrowserWindow.getAllWindows()[0]
2020-05-12 15:06:16 +00:00
activeWindow.show()
activeWindow.reload()
}
},
2022-01-16 22:15:06 +00:00
{
label: 'Minimize on close',
type: 'checkbox',
id: 'minimize-on-close',
2022-01-16 22:15:06 +00:00
checked: settingsService.get('minimizeOnClose'),
click: () => {
settingsService.set('minimizeOnClose', converse.getMenuItemById('minimize-on-close').checked);
2022-01-16 22:15:06 +00:00
}
},
{
label: 'Connection Manager...',
click: () => {
let currentValue = settingsService.get('connectionManager') || '';
prompt({
title: 'Connection manager'
, label: 'Connection manager URL:'
, value: currentValue
, resizable: true
, width: 620
, height: 180
}, app.mainWindow).then(function (newValue) {
if (newValue !== null && newValue !== currentValue) {
settingsService.set('connectionManager', newValue === '' ? null : newValue);
app.mainWindow.reload()
}
}).catch(function (ex) {
});
}
},
2020-05-05 21:10:20 +00:00
{
type: 'separator',
},
2019-04-26 19:26:00 +00:00
{
label: 'Quit',
2020-05-13 15:23:33 +00:00
accelerator: 'CmdOrCtrl+Q',
2019-04-26 19:26:00 +00:00
click: () => {
2020-05-12 15:06:16 +00:00
app.isQuitting = true
2019-04-26 19:26:00 +00:00
app.quit()
},
},
])
}));
application.append(new MenuItem({
label: 'Edit'
, submenu: Menu.buildFromTemplate([
2019-04-26 19:26:00 +00:00
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
role: 'undo',
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo',
},
2019-04-26 19:26:00 +00:00
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut',
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy',
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste',
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectAll',
},
])
}));
application.append(new MenuItem({
label: 'Help'
, submenu: Menu.buildFromTemplate([
2020-06-16 21:22:45 +00:00
{
label: 'Debug info',
accelerator: 'F12',
click: () => {
const activeWindow = BrowserWindow.getAllWindows()[0]
2020-06-16 21:22:45 +00:00
activeWindow.webContents.openDevTools()
}
}
])
}));
2019-04-26 19:26:00 +00:00
Menu.setApplicationMenu(application);
2019-04-26 19:26:00 +00:00
}
2019-04-27 00:16:08 +00:00
module.exports = menuService