Merge branch 'feature/osx-menu-icon' into dev

Close #45
This commit is contained in:
Yuya Ochiai
2016-04-11 22:46:50 +09:00
13 changed files with 262 additions and 13 deletions

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -373,7 +373,7 @@ var showUnreadBadgeWindows = function(unreadCount, mentionCount) {
const sendBadge = function(dataURL, description) { const sendBadge = function(dataURL, description) {
// window.setOverlayIcon() does't work with NativeImage across remote boundaries. // window.setOverlayIcon() does't work with NativeImage across remote boundaries.
// https://github.com/atom/electron/issues/4011 // https://github.com/atom/electron/issues/4011
electron.ipcRenderer.send('win32-overlay', { electron.ipcRenderer.send('update-unread', {
overlayDataURL: dataURL, overlayDataURL: dataURL,
description: description, description: description,
unreadCount: unreadCount, unreadCount: unreadCount,
@@ -400,6 +400,11 @@ var showUnreadBadgeOSX = function(unreadCount, mentionCount) {
} else { } else {
remote.app.dock.setBadge(''); remote.app.dock.setBadge('');
} }
electron.ipcRenderer.send('update-unread', {
unreadCount: unreadCount,
mentionCount: mentionCount
});
} }
var showUnreadBadge = function(unreadCount, mentionCount) { var showUnreadBadge = function(unreadCount, mentionCount) {

View File

@@ -30,7 +30,8 @@ var SettingsPage = React.createClass({
} }
return { return {
teams: config.teams, teams: config.teams,
hideMenuBar: config.hideMenuBar hideMenuBar: config.hideMenuBar,
showTrayIcon: config.showTrayIcon
}; };
}, },
handleTeamsChange: function(teams) { handleTeamsChange: function(teams) {
@@ -42,6 +43,7 @@ var SettingsPage = React.createClass({
var config = { var config = {
teams: this.state.teams, teams: this.state.teams,
hideMenuBar: this.state.hideMenuBar, hideMenuBar: this.state.hideMenuBar,
showTrayIcon: this.state.showTrayIcon,
version: settings.version version: settings.version
}; };
settings.writeFileSync(this.props.configFile, config); settings.writeFileSync(this.props.configFile, config);
@@ -60,6 +62,11 @@ var SettingsPage = React.createClass({
hideMenuBar: this.refs.hideMenuBar.getChecked() hideMenuBar: this.refs.hideMenuBar.getChecked()
}); });
}, },
handleChangeShowTrayIcon: function() {
this.setState({
showTrayIcon: this.refs.showTrayIcon.getChecked()
});
},
render: function() { render: function() {
var teams_row = ( var teams_row = (
<Row> <Row>
@@ -74,6 +81,10 @@ var SettingsPage = React.createClass({
if (process.platform === 'win32' || process.platform === 'linux') { if (process.platform === 'win32' || process.platform === 'linux') {
options.push(<Input ref="hideMenuBar" type="checkbox" label="Hide Menu Bar (Press Alt to show Menu Bar)" checked={ this.state.hideMenuBar } onChange={ this.handleChangeHideMenuBar } />); options.push(<Input ref="hideMenuBar" type="checkbox" label="Hide Menu Bar (Press Alt to show Menu Bar)" checked={ this.state.hideMenuBar } onChange={ this.handleChangeHideMenuBar } />);
} }
if (process.platform === 'darwin') {
options.push(<Input ref="showTrayIcon" type="checkbox" label="Show Icon on Menu Bar (Need to restart the application)" checked={ this.state.showTrayIcon } onChange={ this.handleChangeShowTrayIcon }
/>);
}
var options_row = (options.length > 0) ? ( var options_row = (options.length > 0) ? (
<Row> <Row>
<Col md={ 12 }> <Col md={ 12 }>

View File

@@ -23,6 +23,7 @@ var loadDefault = function(version) {
return { return {
teams: [], teams: [],
hideMenuBar: false, hideMenuBar: false,
showTrayIcon: false,
version: 1 version: 1
}; };
} }

View File

@@ -6,6 +6,7 @@ const BrowserWindow = electron.BrowserWindow; // Module to create native browser
const Menu = electron.Menu; const Menu = electron.Menu;
const Tray = electron.Tray; const Tray = electron.Tray;
const ipc = electron.ipcMain; const ipc = electron.ipcMain;
const nativeImage = electron.nativeImage;
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@@ -48,8 +49,36 @@ catch (e) {
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null; var mainWindow = null;
var trayIcon = null; var trayIcon = null;
const trayImages = function() {
switch (process.platform) {
case 'win32':
return {
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/tray.png')),
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/tray_unread.png')),
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/tray_mention.png'))
};
case 'darwin':
return {
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconTemplate.png')),
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconUnreadTemplate.png')),
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconMentionTemplate.png'))
};
default:
return {};
}
}();
var willAppQuit = false; var willAppQuit = false;
function shouldShowTrayIcon() {
if (process.platform === 'win32') {
return true;
}
if (process.platform === 'darwin' && config.showTrayIcon === true) {
return true;
}
return false;
}
app.on('login', function(event, webContents, request, authInfo, callback) { app.on('login', function(event, webContents, request, authInfo, callback) {
event.preventDefault(); event.preventDefault();
var readlineSync = require('readline-sync'); var readlineSync = require('readline-sync');
@@ -125,9 +154,9 @@ app.on('certificate-error', function(event, webContents, url, error, certificate
// 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() {
if (process.platform === 'win32') { if (shouldShowTrayIcon()) {
// set up tray icon to show balloon // set up tray icon
trayIcon = new Tray(path.resolve(__dirname, 'resources/tray.png')); trayIcon = new Tray(trayImages.normal);
trayIcon.setToolTip(app.getName()); trayIcon.setToolTip(app.getName());
var tray_menu = require('./main/menus/tray').createDefault(); var tray_menu = require('./main/menus/tray').createDefault();
trayIcon.setContextMenu(tray_menu); trayIcon.setContextMenu(tray_menu);
@@ -147,21 +176,21 @@ app.on('ready', function() {
// Set overlay icon from dataURL // Set overlay icon from dataURL
// Set trayicon to show "dot" // Set trayicon to show "dot"
ipc.on('win32-overlay', function(event, arg) { ipc.on('update-unread', function(event, arg) {
if (process.platform === 'win32') {
const overlay = arg.overlayDataURL ? electron.nativeImage.createFromDataURL(arg.overlayDataURL) : null; const overlay = arg.overlayDataURL ? electron.nativeImage.createFromDataURL(arg.overlayDataURL) : null;
mainWindow.setOverlayIcon(overlay, arg.description); mainWindow.setOverlayIcon(overlay, arg.description);
}
var tray_image = null;
if (arg.mentionCount > 0) { if (arg.mentionCount > 0) {
tray_image = 'tray_mention.png'; trayIcon.setImage(trayImages.mention);
} }
else if (arg.unreadCount > 0) { else if (arg.unreadCount > 0) {
tray_image = 'tray_unread.png'; trayIcon.setImage(trayImages.unread);
} }
else { else {
tray_image = 'tray.png'; trayIcon.setImage(trayImages.normal);
} }
trayIcon.setImage(path.resolve(__dirname, 'resources', tray_image));
}); });
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB