2024-08-09 18:24:35 +05:30
|
|
|
import { app, Menu, BrowserWindow, dialog, nativeImage, shell } from "electron";
|
2025-09-26 10:06:55 +02:00
|
|
|
import { ElectronBlocker } from "@ghostery/adblocker-electron";
|
2025-09-26 15:32:06 +02:00
|
|
|
import { getValue } from "./config/store.js";
|
2024-08-09 18:24:35 +05:30
|
|
|
import { dirname, join } from "path";
|
2024-07-21 17:04:59 +05:30
|
|
|
import { fileURLToPath } from "url";
|
2023-06-05 20:12:06 +05:30
|
|
|
|
2025-10-03 10:20:22 +02:00
|
|
|
app.commandLine.appendSwitch('in-process-gpu')
|
|
|
|
|
|
2024-07-22 13:21:44 +05:30
|
|
|
import { getScreenWidth, getScreenHeight } from "./config/dimensions.js";
|
2025-09-30 14:44:32 +02:00
|
|
|
import WindowsChrome from "./useragents.json" with { type: "json" }
|
2024-05-07 15:43:33 +05:30
|
|
|
import checkInternetConnected from "check-internet-connected";
|
2024-08-09 18:24:35 +05:30
|
|
|
import domains from "./domains.json" with { type: "json" };
|
2024-05-07 15:43:33 +05:30
|
|
|
import contextMenu from "electron-context-menu";
|
2024-07-22 13:21:44 +05:30
|
|
|
import menulayout from "./config/menu.js";
|
2024-07-21 17:04:59 +05:30
|
|
|
import logpkg from "electron-log";
|
2024-05-07 15:43:33 +05:30
|
|
|
|
|
|
|
|
const { transports, log: _log, functions } = logpkg;
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
2024-07-22 12:13:59 +05:30
|
|
|
const windowHeight = getValue("windowHeight");
|
|
|
|
|
const windowWidth = getValue("windowWidth");
|
2024-05-07 15:43:33 +05:30
|
|
|
const __dirname = dirname(__filename);
|
2025-10-20 15:25:50 +02:00
|
|
|
export const appUrl = `https://akartonbv.sharepoint.com/:x:/r/sites/Bedrijfsbureau/Gedeelde%20documenten/Productieplanning%20OneDrive.xlsx?d=w818e118382dd4d1cab1ddf4d505daa9e&csf=1&web=1&e=zE73Rr`
|
|
|
|
|
//https://akartonbv.sharepoint.com/:x:/r/sites/Bedrijfsbureau/Gedeelde%20documenten/Productieplanning%20OneDrive.xlsx?d=w818e118382dd4d1cab1ddf4d505daa9e&csf=1&web=1&e=zE73Rr
|
2024-05-07 15:43:33 +05:30
|
|
|
|
|
|
|
|
transports.file.level = "verbose";
|
|
|
|
|
console.log = _log;
|
|
|
|
|
Object.assign(console, functions);
|
2023-06-05 20:12:06 +05:30
|
|
|
|
2023-06-11 21:48:03 +05:30
|
|
|
function createWindow() {
|
2025-09-30 14:34:43 +02:00
|
|
|
const partition = "persist:work";
|
2024-07-21 17:04:59 +05:30
|
|
|
|
2024-05-08 00:59:05 +05:30
|
|
|
const win = new BrowserWindow({
|
2024-07-22 12:13:59 +05:30
|
|
|
width: Math.round(getScreenWidth() * getValue("windowWidth")),
|
|
|
|
|
height: Math.round(getScreenHeight() * getValue("windowHeight")),
|
2024-05-08 00:59:05 +05:30
|
|
|
icon: join(__dirname, "/assets/icons/png/1024x1024.png"),
|
|
|
|
|
show: false,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
nodeIntegration: true,
|
|
|
|
|
devTools: true,
|
|
|
|
|
partition: partition,
|
|
|
|
|
},
|
2024-07-21 17:04:59 +05:30
|
|
|
});
|
|
|
|
|
|
2025-09-30 14:34:43 +02:00
|
|
|
win.webContents.session.on('will-download', (event, item) => {
|
|
|
|
|
event.preventDefault(); // Blocks the download entirely
|
|
|
|
|
console.log(`Blocked download attempt: ${item.getURL()}`);
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-08 00:59:05 +05:30
|
|
|
win.setAutoHideMenuBar(getValue("autohide-menubar") === "true");
|
2023-06-11 21:48:03 +05:30
|
|
|
|
|
|
|
|
const splash = new BrowserWindow({
|
2024-07-22 12:13:59 +05:30
|
|
|
width: Math.round(getScreenWidth() * 0.49),
|
|
|
|
|
height: Math.round(getScreenHeight() * 0.65),
|
2023-06-11 21:48:03 +05:30
|
|
|
transparent: true,
|
|
|
|
|
frame: false,
|
2024-05-07 15:43:33 +05:30
|
|
|
icon: join(__dirname, "/assets/icons/png/1024x1024.png"),
|
2023-06-11 21:48:03 +05:30
|
|
|
});
|
|
|
|
|
|
2025-09-30 14:34:43 +02:00
|
|
|
// Careful, this loading animation relies fully on that page.
|
2023-06-11 21:48:03 +05:30
|
|
|
splash.loadURL(`https://agam778.github.io/MS-365-Electron/loading`);
|
2024-05-08 21:32:17 +05:30
|
|
|
|
2025-09-30 11:55:20 +02:00
|
|
|
//The following line is regarding the starting page.
|
|
|
|
|
//The default is: https://microsoft365.com/${custompage}/${enterpriseOrNormal}
|
2025-09-30 14:44:32 +02:00
|
|
|
win.loadURL(appUrl, {
|
|
|
|
|
userAgent: getValue("useragentstring") || WindowsChrome,
|
2024-05-08 21:32:17 +05:30
|
|
|
});
|
2023-06-11 21:48:03 +05:30
|
|
|
|
|
|
|
|
win.webContents.on("did-finish-load", () => {
|
|
|
|
|
splash.destroy();
|
|
|
|
|
win.show();
|
|
|
|
|
if (getValue("blockadsandtrackers") === "true") {
|
|
|
|
|
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
|
2025-09-30 14:34:43 +02:00
|
|
|
try { // Only enable if not already enabled
|
2025-09-26 15:32:06 +02:00
|
|
|
blocker.enableBlockingInSession(win.webContents.session);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn("Adblocker already enabled for this session");
|
|
|
|
|
}
|
|
|
|
|
}).catch(console.error);
|
2023-06-11 21:48:03 +05:30
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 20:12:06 +05:30
|
|
|
app.on("web-contents-created", (event, contents) => {
|
|
|
|
|
contents.setWindowOpenHandler(({ url }) => {
|
2024-08-09 18:24:35 +05:30
|
|
|
const urlObject = new URL(url);
|
|
|
|
|
const domain = urlObject.hostname;
|
|
|
|
|
const protocol = urlObject.protocol;
|
|
|
|
|
|
|
|
|
|
if (getValue("externalLinks") === "true") {
|
|
|
|
|
if (protocol === "http:" || protocol === "https:") {
|
|
|
|
|
const isAllowedDomain = domains.domains.some((allowedDomain) =>
|
|
|
|
|
new RegExp(`^${allowedDomain.replace("*.", ".*")}$`).test(domain)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isAllowedDomain) {
|
|
|
|
|
if (getValue("websites-in-new-window") === "false") {
|
|
|
|
|
if (url.includes("page=Download")) return { action: "allow" };
|
|
|
|
|
BrowserWindow.getFocusedWindow().loadURL(url).catch();
|
|
|
|
|
return { action: "deny" };
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
action: "allow",
|
|
|
|
|
overrideBrowserWindowOptions: {
|
|
|
|
|
width: Math.round(getScreenWidth() * (windowWidth - 0.07)),
|
|
|
|
|
height: Math.round(getScreenHeight() * (windowHeight - 0.07)),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
shell.openExternal(url);
|
|
|
|
|
return { action: "deny" };
|
|
|
|
|
}
|
2023-06-05 20:12:06 +05:30
|
|
|
} else {
|
2024-08-09 18:24:35 +05:30
|
|
|
return { action: "deny" };
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (getValue("websites-in-new-window") === "false") {
|
|
|
|
|
if (url.includes("page=Download")) return { action: "allow" };
|
2024-07-22 13:21:44 +05:30
|
|
|
BrowserWindow.getFocusedWindow().loadURL(url).catch();
|
2023-06-05 20:12:06 +05:30
|
|
|
return { action: "deny" };
|
2024-08-09 18:24:35 +05:30
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
action: "allow",
|
|
|
|
|
overrideBrowserWindowOptions: {
|
|
|
|
|
width: Math.round(getScreenWidth() * (windowWidth - 0.07)),
|
|
|
|
|
height: Math.round(getScreenHeight() * (windowHeight - 0.07)),
|
|
|
|
|
},
|
|
|
|
|
};
|
2023-06-05 20:12:06 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-06-09 22:37:07 +05:30
|
|
|
contents.on("did-finish-load", () => {
|
2023-06-11 23:20:17 +05:30
|
|
|
if (getValue("dynamicicons") === "true") {
|
|
|
|
|
if (BrowserWindow.getFocusedWindow()) {
|
|
|
|
|
if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("&ithint=file%2cpptx") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow().webContents.getTitle().includes(".pptx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/powerpoint-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/powerpoint.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "PowerPoint");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("&ithint=file%2cdocx") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow().webContents.getTitle().includes(".docx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/word-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/word.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "Word");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("&ithint=file%2cxlsx") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow().webContents.getTitle().includes(".xlsx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/excel-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/excel.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "Excel");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("outlook.live.com") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("outlook.office.com")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/outlook-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/outlook.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "Outlook");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("onedrive.live.com") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("onedrive.aspx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/onedrive-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/onedrive.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "OneDrive");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("teams.live.com")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/teams-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/teams.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "Teams");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2024-07-21 17:04:59 +05:30
|
|
|
BrowserWindow.getFocusedWindow().webContents.getURL().includes("&ithint=onenote")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
if (process.platform === "darwin") {
|
2024-07-21 17:04:59 +05:30
|
|
|
app.dock.setIcon(join(__dirname, "../assets/icons/apps/onenote-mac.png"));
|
2023-06-11 23:20:17 +05:30
|
|
|
} else if (process.platform === "win32") {
|
|
|
|
|
let nimage = nativeImage.createFromPath(
|
2024-05-07 15:43:33 +05:30
|
|
|
join(__dirname, "../assets/icons/apps/onenote.png")
|
2023-06-11 23:20:17 +05:30
|
|
|
);
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(nimage, "OneNote");
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-11 17:39:53 +05:30
|
|
|
} else {
|
2023-06-11 23:20:17 +05:30
|
|
|
if (process.platform === "darwin") {
|
|
|
|
|
app.dock.setIcon(null);
|
|
|
|
|
} else {
|
|
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
window.setOverlayIcon(null, "");
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-11 17:39:53 +05:30
|
|
|
}
|
2023-06-09 22:37:07 +05:30
|
|
|
}
|
2023-06-10 17:47:49 +05:30
|
|
|
}
|
2024-08-09 19:07:33 +05:30
|
|
|
BrowserWindow.getAllWindows().forEach((window) => {
|
|
|
|
|
if (window.webContents.getURL().includes("outlook.live.com")) {
|
|
|
|
|
window.webContents
|
|
|
|
|
.executeJavaScript(
|
|
|
|
|
`
|
|
|
|
|
const observer = new MutationObserver((mutationsList) => {
|
|
|
|
|
let adElementFound = false;
|
|
|
|
|
for (const mutation of mutationsList) {
|
|
|
|
|
if (mutation.type === 'childList') {
|
|
|
|
|
const adElement = document.querySelector('div.GssDD');
|
|
|
|
|
if (adElement) {
|
|
|
|
|
adElement.remove();
|
|
|
|
|
adElementFound = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (adElementFound) {
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
|
|
|
|
|
|
|
|
const adElement = document.querySelector('div.GssDD');
|
|
|
|
|
if (adElement) {
|
|
|
|
|
adElement.remove();
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
.catch();
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-05-08 12:28:25 +05:30
|
|
|
contents.insertCSS(
|
|
|
|
|
`
|
|
|
|
|
::-webkit-scrollbar {
|
|
|
|
|
width: 8px;
|
|
|
|
|
height: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::-webkit-scrollbar-track {
|
|
|
|
|
background: transparent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
|
|
|
background: transparent;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb:hover {
|
|
|
|
|
background: #555;
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
);
|
2023-06-09 22:37:07 +05:30
|
|
|
});
|
2023-06-05 20:12:06 +05:30
|
|
|
});
|
|
|
|
|
|
2023-06-10 01:24:08 +05:30
|
|
|
app.on("browser-window-created", (event, window) => {
|
2023-12-23 13:42:53 +05:30
|
|
|
if (getValue("autohide-menubar") === "true") {
|
|
|
|
|
window.setAutoHideMenuBar(true);
|
|
|
|
|
} else {
|
|
|
|
|
window.setAutoHideMenuBar(false);
|
|
|
|
|
}
|
2023-06-11 21:15:36 +05:30
|
|
|
if (getValue("blockadsandtrackers") === "true") {
|
2023-06-10 01:24:08 +05:30
|
|
|
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
|
2025-09-26 15:32:06 +02:00
|
|
|
// Only enable if not already enabled
|
|
|
|
|
try {
|
|
|
|
|
blocker.enableBlockingInSession(win.webContents.session);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn("Adblocker already enabled for this session");
|
|
|
|
|
}
|
|
|
|
|
}).catch(console.error);
|
2023-06-10 01:24:08 +05:30
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-05 20:12:06 +05:30
|
|
|
app.on("window-all-closed", () => {
|
|
|
|
|
if (process.platform !== "darwin") {
|
|
|
|
|
app.quit();
|
|
|
|
|
}
|
2023-06-09 22:37:07 +05:30
|
|
|
if (process.platform === "darwin") {
|
|
|
|
|
app.dock.setIcon(null);
|
|
|
|
|
}
|
2023-06-05 20:12:06 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on("activate", () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on("ready", function () {
|
2023-06-11 21:49:09 +05:30
|
|
|
checkInternetConnected().catch(() => {
|
|
|
|
|
const options = {
|
|
|
|
|
type: "warning",
|
|
|
|
|
buttons: ["Ok"],
|
|
|
|
|
defaultId: 2,
|
|
|
|
|
title: "Warning",
|
|
|
|
|
message: "You appear to be offline!",
|
|
|
|
|
detail:
|
|
|
|
|
"Please check your Internet Connectivity. This app cannot run without an Internet Connection!",
|
|
|
|
|
};
|
|
|
|
|
dialog.showMessageBox(null, options, (response) => {
|
|
|
|
|
console.log(response);
|
2023-06-05 20:12:06 +05:30
|
|
|
});
|
2023-06-11 21:49:09 +05:30
|
|
|
});
|
2023-06-05 20:12:06 +05:30
|
|
|
});
|
2025-09-30 14:34:43 +02:00
|
|
|
|
|
|
|
|
contextMenu({
|
|
|
|
|
showInspectElement: false,
|
|
|
|
|
showServices: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(menulayout));
|
|
|
|
|
|
|
|
|
|
app.on("ready", () => {
|
|
|
|
|
createWindow();
|
2025-10-20 15:25:50 +02:00
|
|
|
});
|