From 848e93ae099b3bae0fb7db1ef762f25c3f5e018e Mon Sep 17 00:00:00 2001 From: Agampreet Singh <68941022+agam778@users.noreply.github.com> Date: Sun, 11 Jun 2023 23:20:17 +0530 Subject: [PATCH] Let user enable/disable "Dynamic Icons" - Auto Icon Changer will be called "Dynamic Icons" from now on --- app/main.js | 254 ++++++++++++++++++++++++++-------------------------- app/menu.js | 31 +++++++ 2 files changed, 159 insertions(+), 126 deletions(-) diff --git a/app/main.js b/app/main.js index 38c03ad..1b3d6c6 100644 --- a/app/main.js +++ b/app/main.js @@ -155,133 +155,135 @@ app.on("web-contents-created", (event, contents) => { } }); contents.on("did-finish-load", () => { - if (BrowserWindow.getFocusedWindow()) { - if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("&ithint=file%2cpptx") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/powerpoint-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/powerpoint.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "PowerPoint"); - }); - } - } else if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("&ithint=file%2cdocx") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/word-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/word.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "Word"); - }); - } - } else if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("&ithint=file%2cxlsx") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/excel-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/excel.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "Excel"); - }); - } - } else if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("outlook.live.com") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/outlook-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/outlook.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "Outlook"); - }); - } - } else if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("onedrive.live.com") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/onedrive-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/onedrive.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "OneDrive"); - }); - } - } else if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("teams.live.com") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/teams-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/teams.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "Teams"); - }); - } - } else if ( - BrowserWindow.getFocusedWindow() - .webContents.getURL() - .includes("&ithint=onenote") - ) { - if (process.platform === "darwin") { - app.dock.setIcon( - path.join(__dirname, "../assets/icons/apps/onenote-mac.png") - ); - } else if (process.platform === "win32") { - let nimage = nativeImage.createFromPath( - path.join(__dirname, "../assets/icons/apps/onenote.png") - ); - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(nimage, "OneNote"); - }); - } - } else { - if (process.platform === "darwin") { - app.dock.setIcon(null); + if (getValue("dynamicicons") === "true") { + if (BrowserWindow.getFocusedWindow()) { + if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("&ithint=file%2cpptx") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/powerpoint-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/powerpoint.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "PowerPoint"); + }); + } + } else if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("&ithint=file%2cdocx") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/word-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/word.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "Word"); + }); + } + } else if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("&ithint=file%2cxlsx") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/excel-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/excel.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "Excel"); + }); + } + } else if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("outlook.live.com") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/outlook-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/outlook.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "Outlook"); + }); + } + } else if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("onedrive.live.com") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/onedrive-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/onedrive.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "OneDrive"); + }); + } + } else if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("teams.live.com") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/teams-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/teams.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "Teams"); + }); + } + } else if ( + BrowserWindow.getFocusedWindow() + .webContents.getURL() + .includes("&ithint=onenote") + ) { + if (process.platform === "darwin") { + app.dock.setIcon( + path.join(__dirname, "../assets/icons/apps/onenote-mac.png") + ); + } else if (process.platform === "win32") { + let nimage = nativeImage.createFromPath( + path.join(__dirname, "../assets/icons/apps/onenote.png") + ); + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(nimage, "OneNote"); + }); + } } else { - BrowserWindow.getAllWindows().forEach((window) => { - window.setOverlayIcon(null, ""); - }); + if (process.platform === "darwin") { + app.dock.setIcon(null); + } else { + BrowserWindow.getAllWindows().forEach((window) => { + window.setOverlayIcon(null, ""); + }); + } } } } diff --git a/app/menu.js b/app/menu.js index c9e25de..aceb601 100644 --- a/app/menu.js +++ b/app/menu.js @@ -101,6 +101,7 @@ getValueOrDefault("autohide-menubar", "false"); getValueOrDefault("useragentstring", useragents.Windows); getValueOrDefault("discordrpcstatus", "false"); getValueOrDefault("blockadsandtrackers", "false"); +getValueOrDefault("dynamicicons", "true"); const menulayout = [ ...(process.platform === "darwin" @@ -320,6 +321,36 @@ const menulayout = [ checked: getValue("discordrpcstatus") === "true", }, { type: "separator" }, + { + label: "Enable Dynamic Icons", + type: "checkbox", + click: () => { + if (getValue("dynamicicons") === "true") { + setValue("dynamicicons", "false"); + dialog.showMessageBoxSync({ + type: "info", + title: "Dynamic Icons", + message: "Dynamic icons have been disabled.", + buttons: ["OK"], + }); + return; + } else if ( + getValue("dynamicicons") === "false" || + getValue("dynamicicons") === undefined + ) { + setValue("dynamicicons", "true"); + dialog.showMessageBoxSync({ + type: "info", + title: "Dynamic Icons", + message: "Dynamic icons have been enabled.", + buttons: ["OK"], + }); + return; + } + }, + checked: getValue("dynamicicons") === "true", + }, + { type: "separator" }, { label: "Block Ads and Trackers", type: "checkbox",