2023-06-10 17:47:49 +05:30
|
|
|
const { app, Menu, BrowserWindow, dialog, nativeImage } = require("electron");
|
2023-06-05 20:12:06 +05:30
|
|
|
const { autoUpdater } = require("electron-updater");
|
|
|
|
|
const checkInternetConnected = require("check-internet-connected");
|
|
|
|
|
const ElectronDl = require("electron-dl");
|
|
|
|
|
const contextMenu = require("electron-context-menu");
|
|
|
|
|
const path = require("path");
|
|
|
|
|
const log = require("electron-log");
|
2023-06-09 17:04:37 +05:30
|
|
|
const { setActivity, loginToRPC, clearActivity } = require("./rpc");
|
2023-06-05 20:12:06 +05:30
|
|
|
const useragents = require("./useragents.json");
|
2023-06-10 01:24:08 +05:30
|
|
|
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
2023-06-11 21:15:36 +05:30
|
|
|
const { getValue } = require("./store");
|
2023-06-11 21:48:03 +05:30
|
|
|
const { menulayout } = require("./menu");
|
2023-06-05 20:12:06 +05:30
|
|
|
|
|
|
|
|
log.transports.file.level = "verbose";
|
|
|
|
|
console.log = log.log;
|
|
|
|
|
Object.assign(console, log.functions);
|
|
|
|
|
|
2023-06-11 21:48:03 +05:30
|
|
|
function createWindow() {
|
2023-12-24 19:52:25 +05:30
|
|
|
if (getValue("enterprise-or-normal") === "https://microsoft365.com/?auth=1") {
|
|
|
|
|
var win = new BrowserWindow({
|
|
|
|
|
width: 1181,
|
|
|
|
|
height: 670,
|
|
|
|
|
icon: path.join(__dirname, "/assets/icons/png/1024x1024.png"),
|
|
|
|
|
show: false,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
nodeIntegration: true,
|
|
|
|
|
devTools: true,
|
|
|
|
|
partition: "persist:personal",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else if (
|
|
|
|
|
getValue("enterprise-or-normal") === "https://microsoft365.com/?auth=2"
|
|
|
|
|
) {
|
|
|
|
|
var win = new BrowserWindow({
|
|
|
|
|
width: 1181,
|
|
|
|
|
height: 670,
|
|
|
|
|
icon: path.join(__dirname, "/assets/icons/png/1024x1024.png"),
|
|
|
|
|
show: false,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
nodeIntegration: true,
|
|
|
|
|
devTools: true,
|
|
|
|
|
partition: "persist:work",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-11 21:48:03 +05:30
|
|
|
|
|
|
|
|
if (getValue("autohide-menubar") === "true") {
|
|
|
|
|
win.setAutoHideMenuBar(true);
|
|
|
|
|
} else {
|
|
|
|
|
win.setAutoHideMenuBar(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const splash = new BrowserWindow({
|
|
|
|
|
width: 810,
|
|
|
|
|
height: 610,
|
|
|
|
|
transparent: true,
|
|
|
|
|
frame: false,
|
|
|
|
|
icon: path.join(__dirname, "/assets/icons/png/1024x1024.png"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
splash.loadURL(`https://agam778.github.io/MS-365-Electron/loading`);
|
|
|
|
|
win.loadURL(
|
|
|
|
|
`${getValue("enterprise-or-normal") || "https://microsoft365.com/?auth=1"}`,
|
|
|
|
|
{
|
|
|
|
|
userAgent: getValue("useragentstring") || useragents.Windows,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
win.webContents.on("did-finish-load", () => {
|
|
|
|
|
splash.destroy();
|
|
|
|
|
win.show();
|
|
|
|
|
if (getValue("discordrpcstatus") === "true") {
|
|
|
|
|
setActivity(`On "${win.webContents.getTitle()}"`);
|
|
|
|
|
}
|
|
|
|
|
if (getValue("blockadsandtrackers") === "true") {
|
|
|
|
|
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
|
|
|
|
|
blocker.enableBlockingInSession(win.webContents.session);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 20:12:06 +05:30
|
|
|
ElectronDl({
|
|
|
|
|
dlPath: "./downloads",
|
|
|
|
|
onStarted: (item) => {
|
|
|
|
|
dialog.showMessageBox({
|
|
|
|
|
type: "info",
|
|
|
|
|
title: "Downloading File",
|
|
|
|
|
message: `Downloading "${item.getFilename()}" to "${item.getSavePath()}"`,
|
|
|
|
|
buttons: ["OK"],
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onCompleted: () => {
|
|
|
|
|
dialog.showMessageBox({
|
|
|
|
|
type: "info",
|
|
|
|
|
title: "Download Completed",
|
|
|
|
|
message: `Downloading Completed! Please check your "Downloads" folder.`,
|
|
|
|
|
buttons: ["OK"],
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onError: (item) => {
|
|
|
|
|
dialog.showMessageBox({
|
|
|
|
|
type: "error",
|
|
|
|
|
title: "Download failed",
|
|
|
|
|
message: `Downloading "${item.getFilename()}" failed :(`,
|
|
|
|
|
buttons: ["OK"],
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
contextMenu({
|
|
|
|
|
showInspectElement: false,
|
|
|
|
|
showServices: false,
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-11 21:48:03 +05:30
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(menulayout));
|
2023-06-05 20:12:06 +05:30
|
|
|
|
|
|
|
|
app.on("ready", () => {
|
|
|
|
|
createWindow();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on("web-contents-created", (event, contents) => {
|
|
|
|
|
contents.setWindowOpenHandler(({ url }) => {
|
2023-06-11 21:15:36 +05:30
|
|
|
if (getValue("websites-in-new-window") === "false") {
|
2023-06-05 20:12:06 +05:30
|
|
|
if (url.includes("page=Download")) {
|
|
|
|
|
return { action: "allow" };
|
|
|
|
|
} else {
|
2023-07-26 17:56:44 +05:30
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.loadURL(url)
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
// do not show error
|
|
|
|
|
});
|
2023-06-11 21:15:36 +05:30
|
|
|
if (getValue("discordrpcstatus") === "true") {
|
2023-06-09 17:04:37 +05:30
|
|
|
setActivity(
|
|
|
|
|
`On "${BrowserWindow.getFocusedWindow().webContents.getTitle()}"`
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-06-05 20:12:06 +05:30
|
|
|
return { action: "deny" };
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2023-06-11 21:15:36 +05:30
|
|
|
if (getValue("discordrpcstatus") === "true") {
|
2023-06-09 17:04:37 +05:30
|
|
|
setActivity(
|
|
|
|
|
`On "${BrowserWindow.getFocusedWindow().webContents.getTitle()}"`
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-06-05 20:12:06 +05:30
|
|
|
return { action: "allow" };
|
|
|
|
|
}
|
|
|
|
|
});
|
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 (
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.webContents.getURL()
|
2023-07-26 22:16:34 +05:30
|
|
|
.includes("&ithint=file%2cpptx") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.webContents.getTitle()
|
|
|
|
|
.includes(".pptx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
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()
|
2023-07-26 22:16:34 +05:30
|
|
|
.includes("&ithint=file%2cdocx") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.webContents.getTitle()
|
|
|
|
|
.includes(".docx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
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()
|
2023-07-26 22:16:34 +05:30
|
|
|
.includes("&ithint=file%2cxlsx") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.webContents.getTitle()
|
|
|
|
|
.includes(".xlsx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
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()
|
2023-07-26 22:16:34 +05:30
|
|
|
.includes("outlook.live.com") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.webContents.getURL()
|
|
|
|
|
.includes("outlook.office.com")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
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()
|
2023-07-26 22:16:34 +05:30
|
|
|
.includes("onedrive.live.com") ||
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
.webContents.getURL()
|
|
|
|
|
.includes("onedrive.aspx")
|
2023-06-11 23:20:17 +05:30
|
|
|
) {
|
|
|
|
|
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");
|
|
|
|
|
});
|
|
|
|
|
}
|
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
|
|
|
}
|
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-10 01:24:26 +05:30
|
|
|
window.webContents.on("did-finish-load", () => {
|
2023-06-11 21:15:36 +05:30
|
|
|
if (getValue("discordrpcstatus") === "true") {
|
2023-06-10 01:24:26 +05:30
|
|
|
setActivity(`On "${window.webContents.getTitle()}"`);
|
|
|
|
|
}
|
|
|
|
|
});
|
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) => {
|
|
|
|
|
blocker.enableBlockingInSession(window.webContents.session);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
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-09 17:04:37 +05:30
|
|
|
clearActivity();
|
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-12 00:49:47 +05:30
|
|
|
if (getValue("autoupdater") === "true") {
|
|
|
|
|
autoUpdater.checkForUpdatesAndNotify();
|
|
|
|
|
}
|
2023-06-11 21:15:36 +05:30
|
|
|
if (getValue("discordrpcstatus") === "true") {
|
2023-06-09 17:04:37 +05:30
|
|
|
loginToRPC();
|
|
|
|
|
setActivity(`Opening Microsoft 365...`);
|
|
|
|
|
}
|
2023-06-05 20:12:06 +05:30
|
|
|
});
|