Compare commits

...

3 Commits

Author SHA1 Message Date
Michael Telatynski
4bc6f4dafa
Make sonar happier 2023-05-24 12:36:20 +01:00
Michael Telatynski
84ffc7e2e6
Iterate 2023-05-24 12:01:56 +01:00
Michael Telatynski
344d473e9b
Don't double up app badge on Windows 2023-05-24 11:35:09 +01:00

View File

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { app, Tray, Menu, nativeImage } from "electron";
import { app, Tray, Menu, nativeImage, NativeImage } from "electron";
import pngToIco from "png-to-ico";
import path from "path";
import fs from "fs";
@ -50,6 +50,12 @@ interface IConfig {
brand: string;
}
async function convertToIco(img: NativeImage): Promise<NativeImage> {
const icoPath = path.join(app.getPath("temp"), "win32_element_icon.ico");
fs.writeFileSync(icoPath, await pngToIco(img.toPNG()));
return nativeImage.createFromPath(icoPath);
}
export function create(config: IConfig): void {
// no trays on darwin
if (process.platform === "darwin" || trayIcon) return;
@ -62,7 +68,7 @@ export function create(config: IConfig): void {
let lastFavicon: string | null = null;
global.mainWindow?.webContents.on("page-favicon-updated", async function (ev, favicons) {
if (!favicons || favicons.length <= 0 || !favicons[0].startsWith("data:")) {
if (!favicons?.[0]?.startsWith("data:")) {
if (lastFavicon !== null) {
global.mainWindow?.setIcon(defaultIcon);
trayIcon?.setImage(defaultIcon);
@ -80,16 +86,18 @@ export function create(config: IConfig): void {
// Windows likes ico's too much.
if (process.platform === "win32") {
try {
const icoPath = path.join(app.getPath("temp"), "win32_element_icon.ico");
fs.writeFileSync(icoPath, await pngToIco(newFavicon.toPNG()));
newFavicon = nativeImage.createFromPath(icoPath);
newFavicon = await convertToIco(newFavicon);
} catch (e) {
console.error("Failed to make win32 ico", e);
}
}
trayIcon?.setImage(newFavicon);
global.mainWindow?.setIcon(newFavicon);
// Don't set the main window icon on Windows as we call Navigator::setAppBadge to do it for us
if (process.platform !== "win32") {
global.mainWindow?.setIcon(newFavicon);
}
});
global.mainWindow?.webContents.on("page-title-updated", function (ev, title) {