From 4bc6f4dafa73f036539eeabaa3aea104a97ee42b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 24 May 2023 12:36:20 +0100 Subject: [PATCH] Make sonar happier --- src/tray.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tray.ts b/src/tray.ts index e95a43f..d52cdc8 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -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 { + 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; @@ -80,9 +86,7 @@ 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); }