mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-05 22:43:17 +00:00
refactoring code for badge/taskbar icon [WIP]
This commit is contained in:
@@ -9,7 +9,6 @@ const { appUpdater } = require('./autoupdater');
|
|||||||
const { app, ipcMain } = electron;
|
const { app, ipcMain } = electron;
|
||||||
|
|
||||||
const BadgeSettings = require('./../renderer/js/pages/preference/badge-settings.js');
|
const BadgeSettings = require('./../renderer/js/pages/preference/badge-settings.js');
|
||||||
const ConfigUtil = require('./../renderer/js/utils/config-util.js');
|
|
||||||
|
|
||||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||||
require('electron-debug')();
|
require('electron-debug')();
|
||||||
@@ -196,27 +195,18 @@ app.on('ready', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('dock-unread-option', (event, showdock) => {
|
ipcMain.on('dock-unread-option', () => {
|
||||||
if (showdock || ConfigUtil.getConfigItem('dockOption')) {
|
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
||||||
BadgeSettings.showBadgeCount(badgeCount, mainWindow);
|
|
||||||
} else {
|
|
||||||
BadgeSettings.hideBadgeCount(mainWindow);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('update-badge', (event, messageCount) => {
|
ipcMain.on('update-badge', (event, messageCount) => {
|
||||||
badgeCount = messageCount;
|
badgeCount = messageCount;
|
||||||
if (ConfigUtil.getConfigItem('dockOption')) {
|
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
||||||
BadgeSettings.showBadgeCount(badgeCount, mainWindow);
|
|
||||||
} else {
|
|
||||||
BadgeSettings.hideBadgeCount(mainWindow);
|
|
||||||
}
|
|
||||||
page.send('tray', messageCount);
|
page.send('tray', messageCount);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('update-taskbar-icon', (event, data, text) => {
|
ipcMain.on('update-taskbar-icon', (event, data, text) => {
|
||||||
const img = electron.nativeImage.createFromDataURL(data);
|
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
|
||||||
mainWindow.setOverlayIcon(img, text);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('forward-message', (event, listener, ...params) => {
|
ipcMain.on('forward-message', (event, listener, ...params) => {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
const electron = require('electron');
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
|
|
||||||
|
const ConfigUtil = require(__dirname + '/../../utils/config-util.js');
|
||||||
|
|
||||||
class BadgeSettings {
|
class BadgeSettings {
|
||||||
constructor(messageCount, mainWindow) {
|
constructor(messageCount, mainWindow) {
|
||||||
this.messageCount = messageCount;
|
this.messageCount = messageCount;
|
||||||
@@ -18,7 +21,7 @@ class BadgeSettings {
|
|||||||
if (messageCount === 0) {
|
if (messageCount === 0) {
|
||||||
mainWindow.setOverlayIcon(null, '');
|
mainWindow.setOverlayIcon(null, '');
|
||||||
} else {
|
} else {
|
||||||
mainWindow.webContentssend('render-taskbar-icon', messageCount);
|
mainWindow.webContents.send('render-taskbar-icon', messageCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +34,19 @@ class BadgeSettings {
|
|||||||
mainWindow.setOverlayIcon(null, '');
|
mainWindow.setOverlayIcon(null, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBadge(badgeCount, mainWindow) {
|
||||||
|
if (ConfigUtil.getConfigItem('dockOption')) {
|
||||||
|
this.showBadgeCount(badgeCount, mainWindow);
|
||||||
|
} else {
|
||||||
|
this.hideBadgeCount(mainWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTaskbarIcon(data, text, mainWindow) {
|
||||||
|
const img = electron.nativeImage.createFromDataURL(data);
|
||||||
|
mainWindow.setOverlayIcon(img, text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new BadgeSettings();
|
module.exports = new BadgeSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user