2022-03-16 16:32:41 +05:30
const { app , Menu , BrowserWindow , dialog , shell } = require ( "electron" ) ;
const { autoUpdater } = require ( "electron-updater" ) ;
const openAboutWindow = require ( "about-window" ) . default ;
2022-08-20 23:47:35 +05:30
const checkInternetConnected = require ( "check-internet-connected" ) ;
2022-03-16 16:32:41 +05:30
const axios = require ( "axios" ) ;
const ElectronDl = require ( "electron-dl" ) ;
const contextMenu = require ( "electron-context-menu" ) ;
const path = require ( "path" ) ;
const Store = require ( "electron-store" ) ;
2022-10-07 17:24:25 +05:30
const log = require ( "electron-log" ) ;
2022-03-16 16:32:41 +05:30
const store = new Store ( ) ;
const RPC = require ( "discord-rpc" ) ;
const clientId = "942637872530460742" ;
const rpc = new RPC . Client ( { transport : "ipc" } ) ;
2022-03-31 14:54:54 +05:30
const windowsuseragent =
2023-02-16 17:59:59 +05:30
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" ;
2022-03-31 14:54:54 +05:30
const macuseragent =
2023-02-16 17:59:59 +05:30
"Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" ;
2022-03-31 14:54:54 +05:30
const linuxuseragent =
2023-02-16 17:59:59 +05:30
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" ;
2022-03-31 14:54:54 +05:30
2022-03-16 16:32:41 +05:30
log . transports . file . level = "verbose" ;
console . log = log . log ;
2022-05-10 12:46:26 +05:30
Object . assign ( console , log . functions ) ;
2022-03-16 16:32:41 +05:30
ElectronDl ( {
dlPath : "./downloads" ,
onStarted : ( item ) => {
2022-03-20 18:50:58 +05:30
BrowserWindow . getAllWindows ( ) . forEach ( ( window ) => {
window . setOverlayIcon (
_ _dirname + "/assets/icons/download.png" ,
"Downloading"
) ;
} ) ;
2022-03-16 16:32:41 +05:30
dialog . showMessageBox ( {
type : "info" ,
title : "Downloading File" ,
message : ` Downloading " ${ item . getFilename ( ) } " to " ${ item . getSavePath ( ) } " ` ,
buttons : [ "OK" ] ,
} ) ;
} ,
onCompleted : ( ) => {
2022-03-20 18:50:58 +05:30
BrowserWindow . getAllWindows ( ) . forEach ( ( window ) => {
window . setOverlayIcon (
_ _dirname + "/assets/icons/download-success.png" ,
"Download Successful"
) ;
} ) ;
2022-03-16 16:32:41 +05:30
dialog . showMessageBox ( {
type : "info" ,
title : "Download Completed" ,
message : ` Downloading Completed! Please check your "Downloads" folder. ` ,
buttons : [ "OK" ] ,
} ) ;
2022-03-20 18:50:58 +05:30
setTimeout ( ( ) => {
BrowserWindow . getAllWindows ( ) . forEach ( ( window ) => {
window . setOverlayIcon ( null , "" ) ;
} ) ;
} , 7000 ) ;
2022-03-16 16:32:41 +05:30
} ,
onError : ( item ) => {
dialog . showMessageBox ( {
type : "error" ,
title : "Download failed" ,
message : ` Downloading " ${ item . getFilename ( ) } " failed :( ` ,
buttons : [ "OK" ] ,
} ) ;
2022-03-20 18:50:58 +05:30
BrowserWindow . getAllWindows ( ) . forEach ( ( window ) => {
window . setOverlayIcon (
_ _dirname + "/download-fail.png" ,
"Download Failed"
) ;
} ) ;
setTimeout ( ( ) => {
BrowserWindow . getAllWindows ( ) . forEach ( ( window ) => {
window . setOverlayIcon ( null , "" ) ;
} ) ;
} , 7000 ) ;
2022-03-16 16:32:41 +05:30
} ,
} ) ;
contextMenu ( {
showInspectElement : false ,
showServices : false ,
} ) ;
const menulayout = [
2023-02-16 18:43:51 +05:30
... ( process . platform === "darwin"
2022-03-16 16:32:41 +05:30
? [
{
label : app . name ,
submenu : [
{ role : "about" } ,
{ type : "separator" } ,
{ role : "services" } ,
{ type : "separator" } ,
{ role : "hide" } ,
{ role : "hideothers" } ,
{ role : "unhide" } ,
{ type : "separator" } ,
{ role : "quit" } ,
] ,
} ,
]
: [ ] ) ,
{
label : "Application" ,
submenu : [
{
2022-11-22 18:25:54 +05:30
label : "About MS-365-Electron" ,
2022-03-16 16:32:41 +05:30
click : ( ) =>
openAboutWindow ( {
icon _path :
2022-11-22 18:25:54 +05:30
"https://raw.githubusercontent.com/agam778/MS-365-Electron/main/assets/icon.png" ,
product _name : "MS-365-Electron" ,
2022-03-20 18:50:58 +05:30
copyright :
2023-02-16 16:37:17 +05:30
"Copyright (c) 2021-2023 Agampreet Singh\nOffice, the name, website, images/icons\nare the intellectual properties of Microsoft." ,
2022-03-16 16:32:41 +05:30
package _json _dir : _ _dirname ,
bug _report _url :
2022-11-22 18:25:54 +05:30
"https://github.com/agam778/MS-365-Electron/issues/" ,
2022-03-16 16:32:41 +05:30
bug _link _text : "Report an issue" ,
adjust _window _size : "2" ,
show _close _button : "Close" ,
} ) ,
} ,
{
label : "Check for Updates" ,
click : async ( ) => {
axios
. get (
2022-11-22 18:25:54 +05:30
"https://api.github.com/repos/agam778/MS-365-Electron/releases/latest"
2022-03-16 16:32:41 +05:30
)
. then ( ( res ) => {
let data = res . data ;
let currentVersion = "v" + app . getVersion ( ) ;
let latestVersion = data . tag _name ;
if ( currentVersion !== latestVersion ) {
const updatedialog = dialog . showMessageBoxSync ( {
type : "info" ,
title : "Update Available" ,
message : ` Your App's version: ${ currentVersion } \n Latest version: ${ latestVersion } \n \n Please update to the latest version. ` ,
buttons : [ "Download" , "Close" ] ,
} ) ;
if ( updatedialog === 0 ) {
shell . openExternal (
2022-11-22 18:25:54 +05:30
"https://github.com/agam778/MS-365-Electron/releases/latest"
2022-03-16 16:32:41 +05:30
) ;
}
} else {
dialog . showMessageBoxSync ( {
type : "info" ,
title : "No Update Available" ,
message : ` Your App's version: ${ currentVersion } \n Latest version: ${ latestVersion } \n \n You are already using the latest version. ` ,
buttons : [ "OK" ] ,
} ) ;
}
} ) ;
} ,
} ,
{
label : "Learn More" ,
click : async ( ) => {
const { shell } = require ( "electron" ) ;
await shell . openExternal (
2022-11-22 18:25:54 +05:30
"https://github.com/agam778/MS-365-Electron"
2022-03-16 16:32:41 +05:30
) ;
} ,
} ,
{
label : "Open Logs Folder" ,
click : async ( ) => {
const { shell } = require ( "electron" ) ;
2023-02-16 18:43:51 +05:30
if ( process . platform === "win32" ) {
2022-03-16 16:32:41 +05:30
await shell . openPath (
"C:\\Users\\" +
process . env . USERNAME +
2022-11-22 18:25:54 +05:30
"\\AppData\\Roaming\\ms-365-electron\\logs\\"
2022-03-16 16:32:41 +05:30
) ;
} else if ( process . platform === "darwin" ) {
await shell . openPath (
2022-11-22 18:25:54 +05:30
"/Users/" + process . env . USER + "/Library/Logs/ms-365-electron/"
2022-03-16 16:32:41 +05:30
) ;
2023-02-16 18:43:51 +05:30
} else if ( process . platform === "linux" ) {
2022-03-16 16:32:41 +05:30
await shell . openPath (
2022-11-22 18:25:54 +05:30
"/home/" + process . env . USER + "/.config/ms-365-electron/logs/"
2022-03-16 16:32:41 +05:30
) ;
}
} ,
} ,
{ type : "separator" } ,
2022-03-31 05:16:42 -04:00
{
2022-11-22 18:25:54 +05:30
label : "Open Normal version of MS 365" ,
2022-03-31 05:16:42 -04:00
type : "radio" ,
click ( ) {
2022-11-21 20:12:47 +05:30
store . set ( "enterprise-or-normal" , "https://microsoft365.com/?auth=1" ) ;
2022-03-31 14:54:54 +05:30
dialog . showMessageBoxSync ( {
type : "info" ,
2022-11-22 18:25:54 +05:30
title : "Normal version of MS 365" ,
2022-03-31 14:54:54 +05:30
message :
2022-11-22 18:25:54 +05:30
"The normal version of MS 365 will be opened.\n\nPlease restart the app to apply the changes." ,
2022-03-31 14:54:54 +05:30
buttons : [ "OK" ] ,
} ) ;
2022-03-31 05:16:42 -04:00
} ,
checked :
2022-11-21 20:12:47 +05:30
store . get ( "enterprise-or-normal" ) ===
"https://microsoft365.com/?auth=1" ,
2022-03-31 05:16:42 -04:00
} ,
{
2022-11-22 18:25:54 +05:30
label : "Open Enterprise version of MS 365" ,
2022-03-31 05:16:42 -04:00
type : "radio" ,
click ( ) {
2022-11-21 20:12:47 +05:30
store . set ( "enterprise-or-normal" , "https://microsoft365.com/?auth=2" ) ;
2022-03-31 14:54:54 +05:30
dialog . showMessageBoxSync ( {
type : "info" ,
2022-11-22 18:25:54 +05:30
title : "Enterprise version of MS 365" ,
2022-03-31 14:54:54 +05:30
message :
2022-11-22 18:25:54 +05:30
"The enterprise version of MS 365 will be opened.\n\nPlease restart the app to apply the changes." ,
2022-03-31 14:54:54 +05:30
buttons : [ "OK" ] ,
} ) ;
2022-03-31 05:16:42 -04:00
} ,
checked :
2022-11-21 20:12:47 +05:30
store . get ( "enterprise-or-normal" ) ===
"https://microsoft365.com/?auth=2" ,
2022-03-31 05:16:42 -04:00
} ,
{ type : "separator" } ,
2022-03-16 16:32:41 +05:30
{
label : "Open Websites in New Windows (Recommended)" ,
type : "radio" ,
click : ( ) => {
store . set ( "websites-in-new-window" , "true" ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "Websites in New Windows" ,
message :
"Websites which are targeted to open in new tabs will now open in new windows." ,
buttons : [ "OK" ] ,
} ) ;
} ,
checked : store . get ( "websites-in-new-window" )
? store . get ( "websites-in-new-window" ) === "true"
: true ,
} ,
{
label : "Open Websites in the Same Window" ,
type : "radio" ,
click : ( ) => {
store . set ( "websites-in-new-window" , "false" ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "Websites in New Windows" ,
message :
2022-11-22 18:25:54 +05:30
"Websites which are targeted to open in new tabs will now open in the same window.\n\nNote: This will be buggy in some cases if you are using Enterprise version of MS 365." ,
2022-03-16 16:32:41 +05:30
buttons : [ "OK" ] ,
} ) ;
} ,
checked : store . get ( "websites-in-new-window" )
? store . get ( "websites-in-new-window" ) === "false"
: false ,
} ,
{ type : "separator" } ,
{
label : "Enable Discord Rich Presence" ,
2023-02-16 15:53:56 +05:30
type : "checkbox" ,
2022-03-16 16:32:41 +05:30
click : ( ) => {
2023-02-16 15:53:56 +05:30
if ( store . get ( "discordrpcstatus" ) === "true" ) {
store . set ( "discordrpcstatus" , "false" ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "Discord Rich Presence" ,
message : "Discord Rich Presence is now disabled." ,
buttons : [ "OK" ] ,
} ) ;
2023-02-16 15:57:36 +05:30
rpc . clearActivity ( ) ;
2023-02-16 15:53:56 +05:30
return ;
} else if (
store . get ( "discordrpcstatus" ) === "false" ||
2023-02-16 16:16:37 +05:30
store . get ( "discordrpcstatus" ) === undefined
2023-02-16 15:53:56 +05:30
) {
store . set ( "discordrpcstatus" , "true" ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "Discord Rich Presence" ,
message : "Discord Rich Presence is now enabled." ,
buttons : [ "OK" ] ,
} ) ;
discordrpcupdate (
` On " ${ BrowserWindow . getFocusedWindow ( ) . webContents . getTitle ( ) } " `
) ;
return ;
}
2022-03-16 16:32:41 +05:30
} ,
2023-02-16 16:16:37 +05:30
checked : store . get ( "discordrpcstatus" ) === "true" ? true : false ,
2022-03-16 16:32:41 +05:30
} ,
{ type : "separator" } ,
2022-03-31 14:54:54 +05:30
{
label : "Windows Useragent" ,
type : "radio" ,
click : ( ) => {
store . set ( "useragentstring" , windowsuseragent ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "User agent switcher" ,
message :
"You have switched to Windows Useragent.\n\nPlease restart the app to apply the changes." ,
buttons : [ "OK" ] ,
} ) ;
} ,
checked :
store . get ( "useragentstring" ) === windowsuseragent ? true : false ,
} ,
{
label : "Mac os Useragent" ,
type : "radio" ,
click : ( ) => {
store . set ( "useragentstring" , macuseragent ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "User agent switcher" ,
message :
"You have switched to Mac OS Useragent.\n\nPlease restart the app to apply the changes." ,
buttons : [ "OK" ] ,
} ) ;
} ,
checked : store . get ( "useragentstring" ) === macuseragent ? true : false ,
} ,
{
label : "Linux Useragent" ,
type : "radio" ,
click : ( ) => {
store . set ( "useragentstring" , linuxuseragent ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "User agent switcher" ,
message :
"You have switched to Linux Useragent.\n\nPlease restart the app to apply the changes." ,
buttons : [ "OK" ] ,
} ) ;
} ,
checked : store . get ( "useragentstring" ) === linuxuseragent ? true : false ,
} ,
{ type : "separator" } ,
2022-03-16 16:32:41 +05:30
{
role : "quit" ,
accelerator : process . platform === "darwin" ? "Ctrl+Q" : "Ctrl+Q" ,
} ,
] ,
} ,
{
label : "Navigation" ,
submenu : [
{
label : "Back" ,
click : ( ) => {
BrowserWindow . getFocusedWindow ( ) . webContents . goBack ( ) ;
} ,
} ,
{
label : "Forward" ,
click : ( ) => {
BrowserWindow . getFocusedWindow ( ) . webContents . goForward ( ) ;
} ,
} ,
{
label : "Reload" ,
click : ( ) => {
BrowserWindow . getFocusedWindow ( ) . webContents . reload ( ) ;
} ,
} ,
{
label : "Home" ,
click : ( ) => {
BrowserWindow . getFocusedWindow ( ) . loadURL (
2022-03-31 05:16:42 -04:00
` ${ store . get ( "enterprise-or-normal" ) } `
2022-03-16 16:32:41 +05:30
) ;
} ,
} ,
] ,
} ,
{
label : "Edit" ,
submenu : [
{ role : "undo" } ,
{ role : "redo" } ,
{ type : "separator" } ,
{ role : "cut" } ,
{ role : "copy" } ,
{ role : "paste" } ,
2023-02-16 18:43:51 +05:30
... ( process . platform === "darwin"
2022-03-16 16:32:41 +05:30
? [
{ role : "pasteAndMatchStyle" } ,
{ role : "delete" } ,
{ role : "selectAll" } ,
{ type : "separator" } ,
{
label : "Speech" ,
submenu : [ { role : "startSpeaking" } , { role : "stopSpeaking" } ] ,
} ,
]
: [ { role : "delete" } , { type : "separator" } , { role : "selectAll" } ] ) ,
] ,
} ,
{
label : "View" ,
submenu : [
{ role : "reload" } ,
{ role : "forceReload" } ,
{ type : "separator" } ,
{ role : "resetZoom" } ,
{
role : "zoomIn" ,
accelerator : process . platform === "darwin" ? "Control+=" : "Control+=" ,
} ,
{ role : "zoomOut" } ,
{ type : "separator" } ,
{ role : "togglefullscreen" } ,
] ,
} ,
{
label : "Window" ,
submenu : [
{ role : "minimize" } ,
{ role : "zoom" } ,
2023-02-16 18:43:51 +05:30
... ( process . platform === "darwin"
2022-03-16 16:32:41 +05:30
? [
{ type : "separator" } ,
{ role : "front" } ,
{ type : "separator" } ,
{ role : "window" } ,
]
: [ { role : "close" } ] ) ,
{
label : "Show Menu Bar" ,
type : "radio" ,
click : ( ) => {
store . set ( "autohide-menubar" , "false" ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "Menu Bar Settings" ,
message :
"Menu will be visible now. Please restart the app for changes to take effect." ,
buttons : [ "OK" ] ,
} ) ;
} ,
checked : store . get ( "autohide-menubar" ) === "false" ,
} ,
{
label : "Hide Menu Bar (Press ALT To show for some time)" ,
type : "radio" ,
click : ( ) => {
store . set ( "autohide-menubar" , "true" ) ;
dialog . showMessageBoxSync ( {
type : "info" ,
title : "Menu Bar Settings" ,
message :
"Menu bar will be automatically hidden now. Please restart the app for changes to take effect." ,
buttons : [ "OK" ] ,
} ) ;
} ,
checked : store . get ( "autohide-menubar" ) === "true" ,
} ,
] ,
} ,
] ;
const menu = Menu . buildFromTemplate ( menulayout ) ;
Menu . setApplicationMenu ( menu ) ;
function discordrpc ( title ) {
if ( store . get ( "discordrpcstatus" ) === "true" ) {
2022-03-20 18:50:58 +05:30
rpc
. setActivity ( {
details : ` ${ title } ` ,
largeImageKey : "logo" ,
2022-11-22 18:25:54 +05:30
largeImageText : "MS-365-Electron" ,
2022-03-20 18:50:58 +05:30
startTimestamp : Date . now ( ) ,
instance : false ,
} )
. catch ( ( err ) => {
console . log ( err ) ;
} ) ;
2022-03-16 16:32:41 +05:30
}
}
function discordrpcupdate ( title ) {
rpc . clearActivity ( ) ;
2022-03-20 18:50:58 +05:30
rpc
. setActivity ( {
details : ` ${ title } ` ,
largeImageKey : "logo" ,
2022-11-22 18:25:54 +05:30
largeImageText : "MS-365-Electron" ,
2022-03-20 18:50:58 +05:30
startTimestamp : Date . now ( ) ,
instance : false ,
} )
. catch ( ( err ) => {
console . log ( err ) ;
} ) ;
2022-03-16 16:32:41 +05:30
}
function createWindow ( ) {
const win = new BrowserWindow ( {
width : 1181 ,
height : 670 ,
2022-10-07 17:31:10 +05:30
icon : path . join ( _ _dirname , "/assets/icons/png/1024x1024.png" ) ,
2022-03-16 16:32:41 +05:30
show : false ,
webPreferences : {
nodeIntegration : true ,
2022-03-31 05:16:42 -04:00
devTools : true ,
2022-03-16 16:32:41 +05:30
} ,
} ) ;
if ( store . get ( "autohide-menubar" ) === "true" ) {
win . setAutoHideMenuBar ( true ) ;
} else {
win . setAutoHideMenuBar ( false ) ;
}
const splash = new BrowserWindow ( {
width : 810 ,
height : 610 ,
transparent : true ,
frame : false ,
alwaysOnTop : true ,
2022-10-07 17:31:10 +05:30
icon : path . join ( _ _dirname , "/assets/icons/png/1024x1024.png" ) ,
2022-03-16 16:32:41 +05:30
} ) ;
2022-11-22 18:25:54 +05:30
splash . loadURL ( ` https://agam778.github.io/MS-365-Electron/loading ` ) ;
2022-03-31 14:54:54 +05:30
win . loadURL (
2022-11-21 20:12:47 +05:30
` ${
store . get ( "enterprise-or-normal" ) || "https://microsoft365.com/?auth=1"
} ` ,
2022-03-31 14:54:54 +05:30
{
userAgent : store . get ( "useragentstring" ) || windowsuseragent ,
}
) ;
2022-03-16 16:32:41 +05:30
win . webContents . on ( "did-finish-load" , ( ) => {
splash . destroy ( ) ;
win . show ( ) ;
2023-02-16 15:38:22 +05:30
if ( store . get ( "discordrpcstatus" ) === "true" ) {
discordrpc ( ` On " ${ win . webContents . getTitle ( ) } " ` ) ;
}
2022-03-16 16:32:41 +05:30
} ) ;
}
app . on ( "ready" , ( ) => {
createWindow ( ) ;
} ) ;
app . on ( "web-contents-created" , ( event , contents ) => {
2023-02-16 16:30:20 +05:30
contents . setWindowOpenHandler ( ( { url } ) => {
2022-03-16 16:32:41 +05:30
if ( store . get ( "websites-in-new-window" ) === "false" ) {
BrowserWindow . getFocusedWindow ( ) . loadURL ( url ) ;
2023-02-16 16:30:20 +05:30
return { action : "deny" } ;
} else {
return { action : "allow" } ;
2022-03-16 16:32:41 +05:30
}
} ) ;
} ) ;
app . on ( "window-all-closed" , ( ) => {
2023-02-16 15:38:22 +05:30
if ( store . get ( "discordrpcstatus" ) === "true" ) {
rpc . clearActivity ( ) ;
}
2022-03-16 16:32:41 +05:30
if ( process . platform !== "darwin" ) {
app . quit ( ) ;
}
} ) ;
app . on ( "activate" , ( ) => {
if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
createWindow ( ) ;
}
} ) ;
app . on ( "ready" , function ( ) {
2022-08-20 23:47:35 +05:30
checkInternetConnected ( )
2022-09-24 22:58:52 +05:30
. then ( ( ) => {
2022-03-16 16:32:41 +05:30
console . log ( "You are connected to the internet!" ) ;
2022-08-20 23:47:35 +05:30
} )
2022-09-24 22:58:52 +05:30
. catch ( ( ) => {
2022-03-16 16:32:41 +05:30
const options = {
type : "warning" ,
2022-09-24 22:58:52 +05:30
buttons : [ "Ok" ] ,
2022-03-16 16:32:41 +05:30
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 ) ;
} ) ;
2022-08-20 23:47:35 +05:30
} ) ;
2022-03-16 16:32:41 +05:30
autoUpdater . checkForUpdatesAndNotify ( ) ;
2022-09-24 23:21:53 +05:30
if ( store . get ( "discordrpcstatus" ) === "true" ) {
rpc . login ( { clientId } ) . catch ( ( ) =>
dialog . showMessageBox ( BrowserWindow . getFocusedWindow ( ) , {
type : "error" ,
title : "Discord RPC Error" ,
message :
"Oops! An Error occured while connecting to Discord RPC. Probably discord isn't installed or opened?" ,
buttons : [ "OK" ] ,
} )
2022-05-10 12:46:26 +05:30
) ;
2022-09-24 23:21:53 +05:30
}
2022-03-16 16:32:41 +05:30
} ) ;