Support dark mode
This commit is contained in:
parent
eb8036fdf0
commit
bea3b59168
30
src/main.js
30
src/main.js
|
@ -7,7 +7,8 @@ const {
|
||||||
Tray,
|
Tray,
|
||||||
ipcMain,
|
ipcMain,
|
||||||
nativeImage,
|
nativeImage,
|
||||||
dialog
|
dialog,
|
||||||
|
systemPreferences
|
||||||
} = require('electron');
|
} = require('electron');
|
||||||
|
|
||||||
if (require('electron-squirrel-startup')) app.quit();
|
if (require('electron-squirrel-startup')) app.quit();
|
||||||
|
@ -51,6 +52,20 @@ catch (e) {
|
||||||
console.log('Failed to read or upgrade config.json');
|
console.log('Failed to read or upgrade config.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only for OS X
|
||||||
|
const switchMenuIconImages = function(icons, isDarkMode) {
|
||||||
|
if (isDarkMode) {
|
||||||
|
icons.normal = icons.clicked.normal;
|
||||||
|
icons.unread = icons.clicked.unread;
|
||||||
|
icons.mention = icons.clicked.mention;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
icons.normal = icons.light.normal;
|
||||||
|
icons.unread = icons.light.unread;
|
||||||
|
icons.mention = icons.light.mention;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// 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;
|
||||||
|
@ -64,16 +79,20 @@ const trayImages = function() {
|
||||||
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_mention.ico'))
|
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_mention.ico'))
|
||||||
};
|
};
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return {
|
const icons = {
|
||||||
|
light: {
|
||||||
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIcon.png')),
|
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIcon.png')),
|
||||||
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconUnread.png')),
|
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconUnread.png')),
|
||||||
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconMention.png')),
|
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconMention.png'))
|
||||||
|
},
|
||||||
clicked: {
|
clicked: {
|
||||||
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIcon.png')),
|
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIcon.png')),
|
||||||
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconUnread.png')),
|
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconUnread.png')),
|
||||||
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconMention.png'))
|
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconMention.png'))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
switchMenuIconImages(icons, systemPreferences.isDarkMode());
|
||||||
|
return icons;
|
||||||
case 'linux':
|
case 'linux':
|
||||||
var resourcesDir = 'resources/linux/' + (config.trayIconTheme || 'light') + '/';
|
var resourcesDir = 'resources/linux/' + (config.trayIconTheme || 'light') + '/';
|
||||||
return {
|
return {
|
||||||
|
@ -181,6 +200,11 @@ app.on('ready', function() {
|
||||||
// set up tray icon
|
// set up tray icon
|
||||||
trayIcon = new Tray(trayImages.normal);
|
trayIcon = new Tray(trayImages.normal);
|
||||||
trayIcon.setPressedImage(trayImages.clicked.normal);
|
trayIcon.setPressedImage(trayImages.clicked.normal);
|
||||||
|
systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', (event, userInfo) => {
|
||||||
|
switchMenuIconImages(trayImages, systemPreferences.isDarkMode());
|
||||||
|
trayIcon.setImage(trayImages.normal);
|
||||||
|
});
|
||||||
|
|
||||||
trayIcon.setToolTip(app.getName());
|
trayIcon.setToolTip(app.getName());
|
||||||
trayIcon.on('click', function() {
|
trayIcon.on('click', function() {
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
|
|
Loading…
Reference in a new issue