Merge branch 'update-electron'
This commit is contained in:
@@ -42,7 +42,7 @@ function makePackage(platform, arch) {
|
||||
name: packageJson.name,
|
||||
platform: platform,
|
||||
arch: arch,
|
||||
version: '0.34.3',
|
||||
version: '0.35.1',
|
||||
out: './release',
|
||||
prune: true,
|
||||
overwrite: true,
|
||||
|
@@ -12,7 +12,7 @@
|
||||
"devDependencies": {
|
||||
"electron-connect": "^0.3.3",
|
||||
"electron-packager": "^5.1.0",
|
||||
"electron-prebuilt": "^0.34.3",
|
||||
"electron-prebuilt": "^0.35.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-jsbeautifier": "^1.0.1"
|
||||
}
|
||||
|
7
src/common/osVersion.js
Normal file
7
src/common/osVersion.js
Normal file
@@ -0,0 +1,7 @@
|
||||
var os = require('os');
|
||||
var release_split = os.release().split('.');
|
||||
|
||||
module.exports = {
|
||||
major: parseInt(release_split[0]),
|
||||
minor: parseInt(release_split[1])
|
||||
};
|
16
src/index.js
16
src/index.js
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var remote = require('remote');
|
||||
const electron = require('electron');
|
||||
const remote = electron.remote;
|
||||
var url = require('url');
|
||||
|
||||
var contextMenu = require('./menus/context');
|
||||
@@ -8,7 +9,7 @@ var contextMenu = require('./menus/context');
|
||||
var webView = document.getElementById('mainWebview');
|
||||
|
||||
try {
|
||||
var configFile = remote.require('app').getPath('userData') + '/config.json';
|
||||
var configFile = electron.remote.app.getPath('userData') + '/config.json';
|
||||
var config = require(configFile);
|
||||
if (config.url) {
|
||||
webView.setAttribute('src', config.url);
|
||||
@@ -32,10 +33,10 @@ webView.addEventListener('page-title-set', function(e) {
|
||||
|
||||
// Open external link in default browser.
|
||||
webView.addEventListener('new-window', function(e) {
|
||||
var currentUrl = url.parse(webView.getUrl());
|
||||
var destUrl = url.parse(e.url);
|
||||
var currentURL = url.parse(webView.getURL());
|
||||
var destURL = url.parse(e.url);
|
||||
// Open in browserWindow. for exmaple, attached files.
|
||||
if (currentUrl.host === destUrl.host) {
|
||||
if (currentURL.host === destURL.host) {
|
||||
window.open(e.url, 'Mattermost');
|
||||
}
|
||||
else {
|
||||
@@ -60,12 +61,11 @@ var showUnreadBadge = function(unreadCount) {
|
||||
}
|
||||
break;
|
||||
case 'darwin':
|
||||
var app = remote.require('app');
|
||||
if (unreadCount > 0) {
|
||||
app.dock.setBadge(unreadCount.toString());
|
||||
remote.app.dock.setBadge(unreadCount.toString());
|
||||
}
|
||||
else {
|
||||
app.dock.setBadge('');
|
||||
remote.app.dock.setBadge('');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
20
src/main.js
20
src/main.js
@@ -1,10 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var app = require('app'); // Module to control application life.
|
||||
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
||||
var Menu = require('menu');
|
||||
var Tray = require('tray');
|
||||
var ipc = require('ipc');
|
||||
const electron = require('electron');
|
||||
const app = electron.app; // Module to control application life.
|
||||
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
|
||||
const Menu = electron.Menu;
|
||||
const Tray = electron.Tray;
|
||||
const ipc = electron.ipcMain;
|
||||
var appMenu = require('./menus/app');
|
||||
|
||||
var client = null;
|
||||
@@ -21,6 +22,9 @@ var mainWindow = null;
|
||||
var trayIcon = null;
|
||||
var willAppQuit = false;
|
||||
|
||||
// For toast notification on windows
|
||||
app.setAppUserModelId('yuya-oc.electron-mattermost');
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function() {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
@@ -56,10 +60,10 @@ app.on('ready', function() {
|
||||
trayIcon.setToolTip(app.getName());
|
||||
var tray_menu = require('./menus/tray').createDefault();
|
||||
trayIcon.setContextMenu(tray_menu);
|
||||
trayIcon.on('clicked', function() {
|
||||
trayIcon.on('click', function() {
|
||||
mainWindow.focus();
|
||||
});
|
||||
trayIcon.on('balloon-clicked', function() {
|
||||
trayIcon.on('balloon-click', function() {
|
||||
mainWindow.focus();
|
||||
});
|
||||
ipc.on('notified', function(event, arg) {
|
||||
@@ -79,7 +83,7 @@ app.on('ready', function() {
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
||||
|
||||
// Open the DevTools.
|
||||
// mainWindow.openDevTools();
|
||||
|
@@ -1,9 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var Menu = require('menu');
|
||||
const electron = require('electron');
|
||||
const Menu = electron.Menu;
|
||||
|
||||
var createTemplate = function(mainWindow) {
|
||||
var app_name = require('app').getName()
|
||||
var app_name = electron.app.getName();
|
||||
var first_menu_name = (process.platform === 'darwin') ? app_name : 'File';
|
||||
var template = [];
|
||||
template.push({
|
||||
@@ -14,13 +15,13 @@ var createTemplate = function(mainWindow) {
|
||||
}, {
|
||||
label: 'Settings',
|
||||
click: function(item, focusedWindow) {
|
||||
mainWindow.loadUrl('file://' + __dirname + '/../settings.html');
|
||||
mainWindow.loadURL('file://' + __dirname + '/../settings.html');
|
||||
}
|
||||
}, {
|
||||
label: 'Quit',
|
||||
accelerator: 'CmdOrCtrl+Q',
|
||||
click: function(item, focusedWindow) {
|
||||
require('app').quit();
|
||||
electron.app.quit();
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var remote = require('remote');
|
||||
var Menu = remote.require('menu');
|
||||
var MenuItem = remote.require('menu-item');
|
||||
const remote = require('electron').remote;
|
||||
const Menu = remote.Menu;
|
||||
const MenuItem = remote.MenuItem;
|
||||
|
||||
var createDefault = function() {
|
||||
var menu = new Menu();
|
||||
|
@@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var Menu = require('menu');
|
||||
var MenuItem = require('menu-item');
|
||||
const electron = require('electron');
|
||||
const Menu = electron.Menu;
|
||||
const MenuItem = electron.MenuItem;
|
||||
|
||||
var createDefault = function() {
|
||||
var menu = new Menu();
|
||||
|
@@ -15,11 +15,11 @@
|
||||
<input type="button" value="Cancel" onclick="goBack()">
|
||||
|
||||
<script type="text/javascript">
|
||||
var remote = require('remote');
|
||||
const remote = require('electron').remote;
|
||||
var fs = require('fs');
|
||||
|
||||
var saveSettings = function() {
|
||||
var configFile = remote.require('app').getPath('userData') + '/config.json';
|
||||
var configFile = remote.app.getPath('userData') + '/config.json';
|
||||
var urlInput = document.getElementById('url');
|
||||
var config = {
|
||||
url: urlInput.value
|
||||
|
@@ -1,14 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var ipc = require('ipc');
|
||||
const electron = require('electron');
|
||||
const ipc = electron.ipcRenderer;
|
||||
const NativeNotification = Notification;
|
||||
|
||||
ipc.on('retrieveUnreadCount', function() {
|
||||
var unreadCount = document.getElementsByClassName('unread-title').length;
|
||||
ipc.sendToHost('retrieveUnreadCount', unreadCount);
|
||||
console.log(isLowerThanOrEqualWindows8_1());
|
||||
});
|
||||
|
||||
// On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
|
||||
// In current version, use tray balloon for notification
|
||||
function isLowerThanOrEqualWindows8_1() {
|
||||
if (process.platform != 'win32') {
|
||||
return false;
|
||||
}
|
||||
var osVersion = require('../common/osVersion');
|
||||
return (osVersion.major <= 6 && osVersion.minor <= 3);
|
||||
};
|
||||
|
||||
// Show balloon when notified.
|
||||
if (process.platform === 'win32') {
|
||||
function overrideNotificationWithBalloon() {
|
||||
Notification = function(title, options) {
|
||||
ipc.send('notified', {
|
||||
title: title,
|
||||
@@ -19,12 +32,10 @@ if (process.platform === 'win32') {
|
||||
callback('granted');
|
||||
};
|
||||
Notification.prototype.close = function() {};
|
||||
}
|
||||
};
|
||||
|
||||
// Show window even if it is hidden when notification is clicked.
|
||||
var NativeNotification = null;
|
||||
if (process.platform === 'darwin') {
|
||||
NativeNotification = Notification;
|
||||
// Show window even if it is hidden/minimized when notification is clicked.
|
||||
function overrideNotification() {
|
||||
Notification = function(title, options) {
|
||||
this.notification = new NativeNotification(title, options);
|
||||
};
|
||||
@@ -36,8 +47,15 @@ if (process.platform === 'darwin') {
|
||||
};
|
||||
Notification.prototype.__defineSetter__('onclick', function(callback) {
|
||||
this.notification.onclick = function() {
|
||||
require('remote').getCurrentWindow().show();
|
||||
electron.remote.getCurrentWindow().show();
|
||||
callback();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' && isLowerThanOrEqualWindows8_1()) {
|
||||
overrideNotificationWithBalloon();
|
||||
}
|
||||
else {
|
||||
overrideNotification();
|
||||
}
|
||||
|
Reference in New Issue
Block a user