From 25a0af6ddbee0df6fb907aab3c7d9aa33ecd530c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 4 Jun 2017 11:03:12 +0100 Subject: [PATCH 1/2] to make the windows volume mixer not explode as it can't resize icons. I hate Windows. Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/src/tray.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/electron_app/src/tray.js b/electron_app/src/tray.js index 9df1a0fb6..52f298003 100644 --- a/electron_app/src/tray.js +++ b/electron_app/src/tray.js @@ -70,10 +70,19 @@ exports.create = function(win, config) { // if its not default we have to construct into nativeImage if (newFavicon !== config.icon_path) { newFavicon = nativeImage.createFromDataURL(favicons[0]); - } + trayIcon.setImage(newFavicon); - trayIcon.setImage(newFavicon); - win.setIcon(newFavicon); + if (process.platform === 'win32') { + newFavicon = newFavicon.resize({ + height: 40, + width: 40, + }); + } + win.setIcon(newFavicon); + } else { + trayIcon.setImage(newFavicon); + win.setIcon(newFavicon); + } }); win.webContents.on('page-title-updated', function(ev, title) { From 1e5a7426025d8cdf6d7242a738a3b98da388fc8f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 4 Jun 2017 14:24:22 +0100 Subject: [PATCH 2/2] this actually fixes things, still not happy with it, introduces more delay (not noticeably more than the existing delay) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/package.json | 5 +++-- electron_app/src/tray.js | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/electron_app/package.json b/electron_app/package.json index 096c1e96e..5d2571d2d 100644 --- a/electron_app/package.json +++ b/electron_app/package.json @@ -6,8 +6,9 @@ "description": "A feature-rich client for Matrix.org", "author": "Vector Creations Ltd.", "dependencies": { - "electron-window-state": "^4.1.0", "auto-launch": "^5.0.1", - "minimist": "^1.2.0" + "electron-window-state": "^4.1.0", + "minimist": "^1.2.0", + "png-to-ico": "^1.0.2" } } diff --git a/electron_app/src/tray.js b/electron_app/src/tray.js index 52f298003..039e7133f 100644 --- a/electron_app/src/tray.js +++ b/electron_app/src/tray.js @@ -16,6 +16,9 @@ limitations under the License. */ const {app, Tray, Menu, nativeImage} = require('electron'); +const pngToIco = require('png-to-ico'); +const path = require('path'); +const fs = require('fs'); let trayIcon = null; @@ -57,7 +60,7 @@ exports.create = function(win, config) { trayIcon.on('click', toggleWin); let lastFavicon = null; - win.webContents.on('page-favicon-updated', function(ev, favicons) { + win.webContents.on('page-favicon-updated', async function(ev, favicons) { let newFavicon = config.icon_path; if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) { newFavicon = favicons[0]; @@ -70,19 +73,19 @@ exports.create = function(win, config) { // if its not default we have to construct into nativeImage if (newFavicon !== config.icon_path) { newFavicon = nativeImage.createFromDataURL(favicons[0]); - trayIcon.setImage(newFavicon); if (process.platform === 'win32') { - newFavicon = newFavicon.resize({ - height: 40, - width: 40, - }); + try { + const icoPath = path.join(app.getPath('temp'), 'win32_riot_icon.ico') + const icoBuf = await pngToIco(newFavicon.toPNG()); + fs.writeFileSync(icoPath, icoBuf); + newFavicon = icoPath; + } catch (e) {console.error(e);} } - win.setIcon(newFavicon); - } else { - trayIcon.setImage(newFavicon); - win.setIcon(newFavicon); } + + trayIcon.setImage(newFavicon); + win.setIcon(newFavicon); }); win.webContents.on('page-title-updated', function(ev, title) {