Make sonar happier

This commit is contained in:
Michael Telatynski 2023-05-24 12:36:20 +01:00
parent 84ffc7e2e6
commit 4bc6f4dafa
No known key found for this signature in database
GPG key ID: A2B008A5F49F5D0D

View file

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. 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 pngToIco from "png-to-ico";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
@ -50,6 +50,12 @@ interface IConfig {
brand: string; 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 { export function create(config: IConfig): void {
// no trays on darwin // no trays on darwin
if (process.platform === "darwin" || trayIcon) return; if (process.platform === "darwin" || trayIcon) return;
@ -80,9 +86,7 @@ export function create(config: IConfig): void {
// Windows likes ico's too much. // Windows likes ico's too much.
if (process.platform === "win32") { if (process.platform === "win32") {
try { try {
const icoPath = path.join(app.getPath("temp"), "win32_element_icon.ico"); newFavicon = await convertToIco(newFavicon);
fs.writeFileSync(icoPath, await pngToIco(newFavicon.toPNG()));
newFavicon = nativeImage.createFromPath(icoPath);
} catch (e) { } catch (e) {
console.error("Failed to make win32 ico", e); console.error("Failed to make win32 ico", e);
} }