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