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>
This commit is contained in:
Michael Telatynski 2017-06-04 14:24:22 +01:00
parent 25a0af6ddb
commit 1e5a742602
2 changed files with 16 additions and 12 deletions

View File

@ -6,8 +6,9 @@
"description": "A feature-rich client for Matrix.org", "description": "A feature-rich client for Matrix.org",
"author": "Vector Creations Ltd.", "author": "Vector Creations Ltd.",
"dependencies": { "dependencies": {
"electron-window-state": "^4.1.0",
"auto-launch": "^5.0.1", "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"
} }
} }

View File

@ -16,6 +16,9 @@ limitations under the License.
*/ */
const {app, Tray, Menu, nativeImage} = require('electron'); const {app, Tray, Menu, nativeImage} = require('electron');
const pngToIco = require('png-to-ico');
const path = require('path');
const fs = require('fs');
let trayIcon = null; let trayIcon = null;
@ -57,7 +60,7 @@ exports.create = function(win, config) {
trayIcon.on('click', toggleWin); trayIcon.on('click', toggleWin);
let lastFavicon = null; 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; let newFavicon = config.icon_path;
if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) { if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) {
newFavicon = favicons[0]; newFavicon = favicons[0];
@ -70,19 +73,19 @@ exports.create = function(win, config) {
// if its not default we have to construct into nativeImage // if its not default we have to construct into nativeImage
if (newFavicon !== config.icon_path) { if (newFavicon !== config.icon_path) {
newFavicon = nativeImage.createFromDataURL(favicons[0]); newFavicon = nativeImage.createFromDataURL(favicons[0]);
trayIcon.setImage(newFavicon);
if (process.platform === 'win32') { if (process.platform === 'win32') {
newFavicon = newFavicon.resize({ try {
height: 40, const icoPath = path.join(app.getPath('temp'), 'win32_riot_icon.ico')
width: 40, const icoBuf = await pngToIco(newFavicon.toPNG());
}); fs.writeFileSync(icoPath, icoBuf);
newFavicon = icoPath;
} catch (e) {console.error(e);}
} }
win.setIcon(newFavicon); }
} else {
trayIcon.setImage(newFavicon); trayIcon.setImage(newFavicon);
win.setIcon(newFavicon); win.setIcon(newFavicon);
}
}); });
win.webContents.on('page-title-updated', function(ev, title) { win.webContents.on('page-title-updated', function(ev, title) {