Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] Notification on app icon #760

Merged
merged 2 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/background.custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
// It doesn't have any windows which you can see on screen, but we can open
// window from here.

import { app, ipcMain, BrowserWindow } from 'electron';
import { app, BrowserWindow, ipcMain, nativeImage, } from 'electron';
import windowStateKeeper from './background/windowState';
import certificate from './background/certificate';
import idle from '@paulcbetts/system-idle-time';
import { checkForUpdates } from './background/autoUpdate';


process.env.GOOGLE_API_KEY = 'AIzaSyADqUh_c1Qhji3Cp1NE43YrcpuPkmhXD-c';

let screenshareEvent;
Expand Down Expand Up @@ -124,6 +123,11 @@ export function afterMainWindow (mainWindow) {
event.returnValue = idle.getIdleTime();
});

ipcMain.on('update-taskbar-icon', (event, data, text) => {
const img = nativeImage.createFromDataURL(data);
mainWindow.setOverlayIcon(img, text);
});

certificate.initWindow(mainWindow);

checkForUpdates();
Expand Down
40 changes: 39 additions & 1 deletion src/scripts/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals $ */

import { remote, ipcRenderer } from 'electron';
import { ipcRenderer, remote } from 'electron';
import i18n from '../i18n/index.js';
import servers from './servers';
import sidebar from './sidebar';
Expand All @@ -14,7 +14,21 @@ sidebar.on('badge-setted', function () {
if (process.platform === 'darwin' && badge.showAlert) {
remote.app.dock.setBadge(badge.count.toString());
}

if (process.platform === 'win32') {
const mainWindow = remote.getCurrentWindow();
if (badge.showAlert) {
if (!mainWindow.isFocused()) {
mainWindow.flashFrame(true);
}
mainWindow.webContents.send('render-taskbar-icon', badge.count);
} else {
mainWindow.setOverlayIcon(null, '');
}
}

tray.showTrayAlert(badge);

});

export const start = function () {
Expand Down Expand Up @@ -123,6 +137,30 @@ export const start = function () {
validateHost().then(function () {}, function () {});
});

ipcRenderer.on('render-taskbar-icon', (event, messageCount) => {
// Create a canvas from unread messages
function createOverlayIcon (messageCount) {
const canvas = document.createElement('canvas');
canvas.height = 128;
canvas.width = 128;

const ctx = canvas.getContext('2d');
ctx.beginPath();

ctx.fillStyle = 'red';
ctx.arc(64, 64, 64, 0, 2 * Math.PI);
ctx.fill();
ctx.fillStyle = '#ffffff';
ctx.textAlign = 'center';
canvas.style.letterSpacing = '-4px';
ctx.font = 'bold 92px sans-serif';
ctx.fillText(String(Math.min(99, messageCount)), 64, 98);

return canvas;
}
ipcRenderer.send('update-taskbar-icon', createOverlayIcon(messageCount).toDataURL(), String(messageCount));
});

const submit = function () {
validateHost().then(function () {
const input = form.querySelector('[name="host"]');
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ function showTrayAlert (badge, status = 'online') {
}

const imageTitle = getImageTitle(badge.title, badge.showAlert, badge.count);
const trayImagePath = getTrayIcon(process.platform, badge.showAlert, imageTitle, status);

mainWindow.flashFrame(badge.showAlert, imageTitle);
const trayImagePath = getTrayIcon(process.platform, badge.showAlert, imageTitle);
mainWindow.tray.setImage(trayImagePath);

if (process.platform === 'darwin') {
Expand Down