Merge branch 'release/v1.2.1'
This commit is contained in:
@@ -317,6 +317,7 @@ var MattermostView = React.createClass({
|
||||
var currentURL = url.parse(webview.getURL());
|
||||
var destURL = url.parse(e.url);
|
||||
if (destURL.protocol !== 'http:' && destURL.protocol !== 'https:') {
|
||||
ipcRenderer.send('confirm-protocol', destURL.protocol, e.url);
|
||||
return;
|
||||
}
|
||||
if (currentURL.host === destURL.host) {
|
||||
|
16
src/main.js
16
src/main.js
@@ -16,6 +16,7 @@ const path = require('path');
|
||||
var settings = require('./common/settings');
|
||||
var certificateStore = require('./main/certificateStore').load(path.resolve(app.getPath('userData'), 'certificate.json'));
|
||||
var appMenu = require('./main/menus/app');
|
||||
const allowProtocolDialog = require('./main/allowProtocolDialog');
|
||||
|
||||
var argv = require('yargs').argv;
|
||||
|
||||
@@ -164,6 +165,8 @@ app.on('login', function(event, webContents, request, authInfo, callback) {
|
||||
mainWindow.webContents.send('login-request', request, authInfo);
|
||||
});
|
||||
|
||||
allowProtocolDialog.init(mainWindow);
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
app.on('ready', function() {
|
||||
@@ -171,11 +174,12 @@ app.on('ready', function() {
|
||||
// set up tray icon
|
||||
trayIcon = new Tray(trayImages.normal);
|
||||
trayIcon.setToolTip(app.getName());
|
||||
var tray_menu = require('./main/menus/tray').createDefault();
|
||||
trayIcon.setContextMenu(tray_menu);
|
||||
trayIcon.on('click', function() {
|
||||
mainWindow.focus();
|
||||
});
|
||||
trayIcon.on('right-click', () => {
|
||||
trayIcon.popUpContextMenu();
|
||||
});
|
||||
trayIcon.on('balloon-click', function() {
|
||||
mainWindow.focus();
|
||||
});
|
||||
@@ -221,7 +225,7 @@ app.on('ready', function() {
|
||||
// On HiDPI Windows environment, the taskbar icon is pixelated. So this line is necessary.
|
||||
window_options.icon = path.resolve(__dirname, 'resources/appicon.png');
|
||||
}
|
||||
window_options.fullScreenable = true;
|
||||
window_options.title = app.getName();
|
||||
mainWindow = new BrowserWindow(window_options);
|
||||
mainWindow.setFullScreenable(true); // fullscreenable option has no effect.
|
||||
if (window_options.maximized) {
|
||||
@@ -234,6 +238,12 @@ app.on('ready', function() {
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL('file://' + __dirname + '/browser/index.html');
|
||||
|
||||
// set up context menu for tray icon
|
||||
if (shouldShowTrayIcon()) {
|
||||
const tray_menu = require('./main/menus/tray').createDefault(mainWindow);
|
||||
trayIcon.setContextMenu(tray_menu);
|
||||
}
|
||||
|
||||
// Open the DevTools.
|
||||
// mainWindow.openDevTools();
|
||||
|
||||
|
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
|
||||
};
|
@@ -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 = {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "mattermost-desktop",
|
||||
"productName": "Mattermost",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "Mattermost Desktop application for Windows, Mac and Linux",
|
||||
"main": "main.js",
|
||||
"author": {
|
||||
|
Reference in New Issue
Block a user