mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
explicit convert to nativeImage to stabilise on Windows
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
9f7cf463b9
commit
78068bfaa0
@ -54,33 +54,38 @@ exports.create = function(win, config) {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
trayIcon = new Tray(config.icon_path);
|
const defaultIcon = nativeImage.createFromPath(config.icon_path);
|
||||||
|
|
||||||
|
trayIcon = new Tray(defaultIcon);
|
||||||
trayIcon.setToolTip(config.brand);
|
trayIcon.setToolTip(config.brand);
|
||||||
trayIcon.setContextMenu(contextMenu);
|
trayIcon.setContextMenu(contextMenu);
|
||||||
trayIcon.on('click', toggleWin);
|
trayIcon.on('click', toggleWin);
|
||||||
|
|
||||||
let lastFavicon = null;
|
let lastFavicon = null;
|
||||||
win.webContents.on('page-favicon-updated', async 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:')) {
|
||||||
if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) {
|
if (lastFavicon !== null) {
|
||||||
newFavicon = favicons[0];
|
win.setIcon(defaultIcon);
|
||||||
|
trayIcon.setImage(defaultIcon);
|
||||||
|
lastFavicon = null;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No need to change, shortcut
|
// No need to change, shortcut
|
||||||
if (newFavicon === lastFavicon) return;
|
if (favicons[0] === lastFavicon) return;
|
||||||
lastFavicon = newFavicon;
|
lastFavicon = favicons[0];
|
||||||
|
|
||||||
// if its not default we have to construct into nativeImage
|
let newFavicon = nativeImage.createFromDataURL(favicons[0]);
|
||||||
if (newFavicon !== config.icon_path) {
|
|
||||||
newFavicon = nativeImage.createFromDataURL(favicons[0]);
|
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
// Windows likes ico's too much.
|
||||||
try {
|
if (process.platform === 'win32') {
|
||||||
const icoPath = path.join(app.getPath('temp'), 'win32_riot_icon.ico')
|
try {
|
||||||
const icoBuf = await pngToIco(newFavicon.toPNG());
|
const icoPath = path.join(app.getPath('temp'), 'win32_riot_icon.ico');
|
||||||
fs.writeFileSync(icoPath, icoBuf);
|
fs.writeFileSync(icoPath, await pngToIco(newFavicon.toPNG()));
|
||||||
newFavicon = icoPath;
|
newFavicon = nativeImage.createFromPath(icoPath);
|
||||||
} catch (e) {console.error(e);}
|
} catch (e) {
|
||||||
|
console.error("Failed to make win32 ico", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user