Skip to content

Commit

Permalink
Changes to menu handling
Browse files Browse the repository at this point in the history
Most importantly the Electron front-end  doesn't need the 'remote'
module (which is removed in Electron 14) any more
  • Loading branch information
PerBothner committed Jul 2, 2021
1 parent e9d49db commit cc70999
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 194 deletions.
33 changes: 27 additions & 6 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function eventToWindow(event) {
}

ipcMain.on('window-ops', (event, command, arg) => {
let win;
switch (command) {
case 'new-window':
if (! arg.width || ! arg.height) {
Expand All @@ -143,25 +144,45 @@ ipcMain.on('window-ops', (event, command, arg) => {
case 'toggle-devtools':
eventToWindow(event).toggleDevTools();
break;
case 'fullscreen':
win = eventToWindow(event);
arg = arg === 'toggle' ? ! win.isFullScreen()
: arg && arg !== 'false' && arg !== 'off' && arg !== 'no';
win.setFullScreen(arg == 'toggle' ? ! win.isFullScreen() : arg);
break;
case 'set-menubar-visibility':
eventToWindow(event).setMenuBarVisibility(arg);
break;
}
});

ipcMain.on('show-context-menu', (event, items, options) => {
items = items.map((item) => {
function fixMenuItems(items, win = null) {
return items.map((item) => {
const clickClientAction = item.clickClientAction;
if (clickClientAction) {
item.click = function() {
event.sender.send('do-named-command', clickClientAction);
item.click = function(menuItem, browserWindow, event) {
browserWindow.send('do-named-command', clickClientAction);
};
item.clickClientAction = undefined;
}
if (win && item.visible === false && item.label == "Exit full screen")
item.visible = win.isFullScreen()
if (item.accelerator && item.accelerator.indexOf(' ') >= 0)
item.accelerator = undefined;
if (item.submenu)
item.submenu = fixMenuItems(item.submenu, win);
return item;
});
const menu = Menu.buildFromTemplate(items);
let oarg = {window: BrowserWindow.fromWebContents(event.sender)};
}

ipcMain.on('set-application-menu', (event, template) => {
Menu.setApplicationMenu(Menu.buildFromTemplate(fixMenuItems(template)));
});

ipcMain.on('show-context-menu', (event, items, options) => {
let win = BrowserWindow.fromWebContents(event.sender);
const menu = Menu.buildFromTemplate(fixMenuItems(items, win));
let oarg = {window: win };
if (options.x !== undefined && options.y !== undefined) {
oarg.x = Math.round(options.x);
oarg.y = Math.round(options.y);
Expand Down
3 changes: 0 additions & 3 deletions electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
const _electron = require('electron');
const _fs = require('fs');
const _require = require;
const remote = _electron.remote;
const _electronAccess = {
clipboard: _electron.clipboard,
fs: _fs,
ipcRenderer: _electron.ipcRenderer,
Menu: remote.Menu,
MenuItem: remote.MenuItem,
require: _require
}
process.once('loaded', () => {
Expand Down
16 changes: 12 additions & 4 deletions hlib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,20 @@ cmd('enter-mux-mode',
dt.enterMuxMode();
return true;
});
cmd('toggle-menubar',
function(dt, key) {
if (DomTerm.toggleMenubar)
DomTerm.toggleMenubar();
return true;
});
cmd('toggle-fullscreen',
function(dt, key) {
if (screenfull.isFullscreen)
screenfull.exit();
else
screenfull.request();
DomTerm.windowOp('fullscreen', 'toggle');
return true;
});
cmd('exit-fullscreen',
function(dt, key) {
DomTerm.windowOp('fullscreen', 'off');
return true;
});
cmd('toggle-fullscreen-current-window',
Expand Down
4 changes: 2 additions & 2 deletions hlib/domterm-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ function loadHandler(event) {
*/
}
if (! DomTerm.useIFrame || ! DomTerm.isInIFrame())
if (DomTerm.setContextMenu && ! DomTerm.simpleLayout)
DomTerm.setContextMenu();
if (DomTerm.createMenus && ! DomTerm.simpleLayout)
DomTerm.createMenus();
m = location.hash.match(/open=([^&;]*)/);
var open_encoded = m ? decodeURIComponent(m[1]) : null;
if (open_encoded) {
Expand Down
Loading

0 comments on commit cc70999

Please sign in to comment.