Skip to content

Commit

Permalink
fixes (#11)
Browse files Browse the repository at this point in the history
- Add quit context menu
- Fix opening url in default browser for "new-window" event
- Update deps
  • Loading branch information
antfu authored Mar 18, 2020
1 parent 05e8bbd commit ffcc51b
Show file tree
Hide file tree
Showing 3 changed files with 773 additions and 1,772 deletions.
48 changes: 33 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
'use strict'

const menubar = require('menubar')
const { app, shell, Menu, Tray } = require('electron');
const path = require('path');
const { menubar } = require('menubar');

const hotelClerk = menubar({
index: 'http://localhost:2000',
dir: __dirname + '/app',
height: 300,
width: 364,
'node-integration': false,
'preload-window': true
});
const iconPath = path.join(__dirname, 'app', 'IconTemplate.png');

hotelClerk.on('after-create-window', function () {
const html = hotelClerk.window.webContents;
app.on('ready', () => {
const tray = new Tray(iconPath);
const contextMenu = Menu.buildFromTemplate([
{ label: 'Quit', role: 'quit', click: () => app.exit() },
]);
tray.addListener('right-click', () => tray.popUpContextMenu(contextMenu))

const hotelClerk = menubar({
tray,
index: 'http://localhost:2000',
browserWindow: {
width: 350,
height: 350,
},
preloadWindow: true,
});

hotelClerk.on('after-create-window', function () {
const webContents = hotelClerk.window.webContents;

html.on('will-navigate', function (event, url) {
event.preventDefault();
require('shell').openExternal(url);
const handleRedirect = (e, url) => {
if (url != webContents.getURL()) {
e.preventDefault()
shell.openExternal(url)
}
};

webContents.on('will-navigate', handleRedirect);
webContents.on('new-window', handleRedirect);
});
});
});
Loading

0 comments on commit ffcc51b

Please sign in to comment.