Merge branch 'master' into dev
This commit is contained in:
61
src/main/allowProtocolDialog.js
Normal file
61
src/main/allowProtocolDialog.js
Normal file
@@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
app,
|
||||
dialog,
|
||||
ipcMain
|
||||
} = require('electron');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const allowedProtocolFile = path.resolve(app.getPath('userData'), 'allowedProtocols.json')
|
||||
var allowedProtocols = [];
|
||||
|
||||
function init(mainWindow) {
|
||||
fs.readFile(allowedProtocolFile, 'utf-8', (err, data) => {
|
||||
if (!err) {
|
||||
allowedProtocols = JSON.parse(data);
|
||||
}
|
||||
initDialogEvent(mainWindow);
|
||||
});
|
||||
}
|
||||
|
||||
function initDialogEvent(mainWindow) {
|
||||
ipcMain.on('confirm-protocol', (event, protocol, URL) => {
|
||||
if (allowedProtocols.indexOf(protocol) !== -1) {
|
||||
require('shell').openExternal(URL);
|
||||
return;
|
||||
}
|
||||
dialog.showMessageBox(mainWindow, {
|
||||
title: 'Non http(s) protocol',
|
||||
message: `${protocol} link requires an external application.`,
|
||||
detail: `The requested link is ${URL} . Do you want to continue?`,
|
||||
type: 'warning',
|
||||
buttons: [
|
||||
'Yes',
|
||||
`Yes (Save ${protocol} as allowed)`,
|
||||
'No'
|
||||
],
|
||||
cancelId: 2,
|
||||
noLink: true
|
||||
}, (response) => {
|
||||
switch (response) {
|
||||
case 1:
|
||||
allowedProtocols.push(protocol);
|
||||
fs.writeFile(allowedProtocolFile, JSON.stringify(allowedProtocols), (err) => {
|
||||
if (err) console.error(err);
|
||||
});
|
||||
// fallthrough
|
||||
case 0:
|
||||
require('shell').openExternal(URL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init
|
||||
};
|
@@ -13,6 +13,25 @@ var createTemplate = function(mainWindow, config) {
|
||||
var template = [];
|
||||
|
||||
const platformAppMenu = process.platform === 'darwin' ? [{
|
||||
label: 'About ' + app_name,
|
||||
role: 'about',
|
||||
click: function(item, focusedWindow) {
|
||||
electron.dialog.showMessageBox(mainWindow, {
|
||||
buttons: ["OK"],
|
||||
message: `${app_name} Desktop ${electron.app.getVersion()}`
|
||||
});
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Preferences...',
|
||||
accelerator: 'CmdOrCtrl+,',
|
||||
click: function(item, focusedWindow) {
|
||||
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Hide ' + app_name,
|
||||
accelerator: 'Command+H',
|
||||
selector: 'hide:'
|
||||
@@ -25,36 +44,33 @@ var createTemplate = function(mainWindow, config) {
|
||||
selector: 'unhideAllApplications:'
|
||||
}, {
|
||||
type: 'separator'
|
||||
}] : [];
|
||||
}, {
|
||||
label: 'Quit ' + app_name,
|
||||
accelerator: 'CmdOrCtrl+Q',
|
||||
click: function(item, focusedWindow) {
|
||||
electron.app.quit();
|
||||
}
|
||||
}] : [{
|
||||
label: 'Settings',
|
||||
accelerator: 'CmdOrCtrl+,',
|
||||
click: function(item, focusedWindow) {
|
||||
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Quit',
|
||||
accelerator: 'CmdOrCtrl+Q',
|
||||
click: function(item, focusedWindow) {
|
||||
electron.app.quit();
|
||||
}
|
||||
}];
|
||||
|
||||
template.push({
|
||||
label: '&' + first_menu_name,
|
||||
submenu: [{
|
||||
label: 'About ' + app_name,
|
||||
role: 'about',
|
||||
click: function(item, focusedWindow) {
|
||||
electron.dialog.showMessageBox(mainWindow, {
|
||||
buttons: ["OK"],
|
||||
message: `${app_name} Desktop ${electron.app.getVersion()}`
|
||||
});
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: (process.platform === 'darwin') ? 'Preferences...' : 'Settings',
|
||||
accelerator: 'CmdOrCtrl+,',
|
||||
click: function(item, focusedWindow) {
|
||||
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, ...platformAppMenu, {
|
||||
label: 'Quit',
|
||||
accelerator: 'CmdOrCtrl+Q',
|
||||
click: function(item, focusedWindow) {
|
||||
electron.app.quit();
|
||||
}
|
||||
}]
|
||||
submenu: [
|
||||
...platformAppMenu
|
||||
]
|
||||
});
|
||||
template.push({
|
||||
label: '&Edit',
|
||||
@@ -122,6 +138,8 @@ var createTemplate = function(mainWindow, config) {
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||
}
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: (function() {
|
||||
@@ -205,6 +223,13 @@ var createTemplate = function(mainWindow, config) {
|
||||
}
|
||||
template.push(window_menu);
|
||||
|
||||
template.push({
|
||||
label: '&Help',
|
||||
submenu: [{
|
||||
label: `Version ${electron.app.getVersion()}`,
|
||||
enabled: false
|
||||
}, ]
|
||||
});
|
||||
return template;
|
||||
};
|
||||
|
||||
|
@@ -1,18 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const electron = require('electron');
|
||||
const Menu = electron.Menu;
|
||||
const MenuItem = electron.MenuItem;
|
||||
const {
|
||||
app,
|
||||
Menu,
|
||||
MenuItem
|
||||
} = require('electron');
|
||||
|
||||
var createDefault = function() {
|
||||
var menu = new Menu();
|
||||
menu.append(new MenuItem({
|
||||
function createDefault(mainWindow) {
|
||||
return Menu.buildFromTemplate([{
|
||||
label: `Open ${app.getName()}`,
|
||||
click: () => {
|
||||
mainWindow.show();
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Quit',
|
||||
click: function(item) {
|
||||
require('app').quit();
|
||||
app.quit();
|
||||
}
|
||||
}));
|
||||
return menu;
|
||||
}]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Reference in New Issue
Block a user