Add dialog to confirm non-http(s) link
This commit is contained in:
parent
bb66ece664
commit
7c964d51f5
|
@ -317,6 +317,7 @@ var MattermostView = React.createClass({
|
||||||
var currentURL = url.parse(webview.getURL());
|
var currentURL = url.parse(webview.getURL());
|
||||||
var destURL = url.parse(e.url);
|
var destURL = url.parse(e.url);
|
||||||
if (destURL.protocol !== 'http:' && destURL.protocol !== 'https:') {
|
if (destURL.protocol !== 'http:' && destURL.protocol !== 'https:') {
|
||||||
|
ipcRenderer.send('confirm-protocol', destURL.protocol, e.url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentURL.host === destURL.host) {
|
if (currentURL.host === destURL.host) {
|
||||||
|
|
42
src/main.js
42
src/main.js
|
@ -154,6 +154,48 @@ app.on('login', function(event, webContents, request, authInfo, callback) {
|
||||||
mainWindow.webContents.send('login-request', request, authInfo);
|
mainWindow.webContents.send('login-request', request, authInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipc.on('confirm-protocol', (event, protocol, URL) => {
|
||||||
|
const allowedProtocolFile = path.resolve(app.getPath('userData'), 'allowedProtocols.json')
|
||||||
|
fs.readFile(allowedProtocolFile, 'utf-8', (err, data) => {
|
||||||
|
var allowedProtocols = [];
|
||||||
|
if (!err) {
|
||||||
|
allowedProtocols = JSON.parse(data);
|
||||||
|
}
|
||||||
|
if (allowedProtocols.indexOf(protocol) !== -1) {
|
||||||
|
require('shell').openExternal(URL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
electron.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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
|
|
Loading…
Reference in a new issue