Let user enable/disable "Dynamic Icons"

- Auto Icon Changer will be called "Dynamic Icons" from now on
This commit is contained in:
Agampreet Singh
2023-06-11 23:20:17 +05:30
parent 1625a46529
commit 848e93ae09
2 changed files with 159 additions and 126 deletions

View File

@@ -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, "");
});
}
}
}
}

View File

@@ -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",