Skip to content

Commit

Permalink
fix: #240 Merge branch 'micw-feature/opensafemailinbrowser'
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-alarcon committed Sep 15, 2023
2 parents a250513 + 7795bdf commit 877be80
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 152 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The Outlook desktop client for the
[new Outlook Interface](https://www.microsoft.com/en-us/microsoft-365/blog/2018/06/13/power-and-simplicity-updates-to-the-office-365-user-experience/)
from Microsoft 365.

Available for Linux , Windows and macOS.
Available for Linux, Windows (10+) and macOS.

## Download

Expand Down Expand Up @@ -72,10 +72,11 @@ For other distributions please follow your specific steps.

```json
{
"urlMainWindow": "https://customurl.example/",
"urlsInternal": ["customurl.example"],
"urlsExternal": ["externalurls.example"],
"showWindowFrame": true
"mainMailServiceUrl":"https://customurl.example/",
"deeplinkUrls":["customurl.example"],
"mailServicesUrls":["mailServicesUrls.example"],
"safelinksUrls": ["safelinksUrls.example"],
"showWindowFrame":true
}
```

Expand All @@ -87,9 +88,9 @@ Outlook.com account:
```json
{
"urlMainWindow": "https://outlook.live.com/mail",
"urlsInternal": ["outlook.com", "live.com"],
"urlsExternal": ["outlook.com", "live.com"]
"mainMailServiceUrl": "https://login.live.com/login.srf",
"deeplinkUrls": ["outlook.com", "live.com"],
"mailServicesUrls": ["outlook.com", "live.com"]
}
```

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"license": "MIT",
"engines": {
"node": "^20.5",
"node": "^20.6",
"yarn": "^1.22.19"
},
"scripts": {
Expand All @@ -49,8 +49,8 @@
"electron-settings": "^4.0.2"
},
"devDependencies": {
"electron": "^25.3",
"electron-builder": "^24.6.2"
"electron": "^25.0",
"electron-builder": "^24.6"
},
"build": {
"appId": "io.github.julian-alarcon.prospect-mail",
Expand Down
30 changes: 0 additions & 30 deletions public/child-window.js

This file was deleted.

125 changes: 67 additions & 58 deletions src/controller/mail-window-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const settings = require("electron-settings");
const getClientFile = require("./client-injector");
const path = require("path");

let outlookUrl;
let mainMailServiceUrl;
let deeplinkUrls;
let outlookUrls;
let safelinksUrls;
let mailServicesUrls;
let showWindowFrame;
let $this;

Expand All @@ -34,23 +35,41 @@ class MailWindowController {
settings.getSync("showWindowFrame") === undefined ||
settings.getSync("showWindowFrame") === true;

outlookUrl =
mainMailServiceUrl =
settings.getSync("urlMainWindow") || "https://outlook.office.com/mail";
deeplinkUrls = settings.getSync("urlsInternal") || [
"outlook.live.com/mail/deeplink",
"outlook.office365.com/mail/deeplink",
"outlook.office.com/mail/deeplink",
"outlook.office.com/calendar/deeplink",
"to-do.office.com/tasks"
];
outlookUrls = settings.getSync("urlsExternal") || [
mailServicesUrls = settings.getSync("urlsExternal") || [
"outlook.live.com",
"outlook.office365.com",
"outlook.office.com",
"outlook.office.com"
];
// // Outlook.com personal accounts tests values
// mainMailServiceUrl =
// settings.getSync("urlMainWindow") || "https://login.live.com/login.srf";
// deeplinkUrls = settings.getSync("urlsInternal") || [
// "outlook.com",
// "live.com",
// ];
// mailServicesUrls = settings.getSync("urlsExternal") || [
// "outlook.com",
// "live.com",
// ];
safelinksUrls = settings.getSync("safelinksUrls") || [
"outlook.office.com/mail/safelink.html",
"safelinks.protection.outlook.com",
];

console.log("Loaded settings", {
outlookUrl: outlookUrl,
mainMailServiceUrl: mainMailServiceUrl,
deeplinkUrls: deeplinkUrls,
outlookUrls: outlookUrls,
mailServicesUrls: mailServicesUrls,
safelinksUrls: safelinksUrls,
});
}
init() {
Expand All @@ -70,15 +89,14 @@ class MailWindowController {
icon: path.join(__dirname, "../../assets/outlook_linux_black.png"),
webPreferences: {
spellcheck: true,
nativeWindowOpen: true,
affinity: "main-window",
contextIsolation: false,
nodeIntegration: true,
},
});

// and load the index.html of the app.
this.win.loadURL(outlookUrl, { userAgent: "Chrome" });
this.win.loadURL(mainMailServiceUrl, { userAgent: "Chrome" });

// Show window handler
ipcMain.on("show", (event) => {
Expand All @@ -101,33 +119,46 @@ class MailWindowController {
}
});

this.win.webContents.on("did-create-window", (childWindow) => {
// insert styles
childWindow.webContents.on("dom-ready", () => {
childWindow.webContents.insertCSS(getClientFile("main.css"));

this.setupContextMenu(childWindow);

let that = this;
if (!showWindowFrame) {
let a = childWindow.webContents.insertCSS(
getClientFile("no-frame.css")
);
a.then(() => {
childWindow.webContents
.executeJavaScript(getClientFile("child-window.js"))
.then(() => {
childWindow.webContents.on("new-window", this.openInBrowser);
childWindow.show();
})
.catch((errJS) => {
console.log("Error JS Insertion:", errJS);
});
}).catch((err) => {
console.log("Error CSS Insertion:", err);
});
}
});
this.win.webContents.setWindowOpenHandler(({ url }) => {
console.log(url);
// If url is a detatch from outlook then open in small window
if (url === "about:blank") {
return {
action: "allow",
overrideBrowserWindowOptions: {
autoHideMenuBar: true,
},
};
}
// Open MS Safe Links in local browser
if (new RegExp(safelinksUrls.join("|")).test(url)) {
shell.openExternal(url);
return {
action: "deny",
};
}
// If deeplink is detected, open it in new detached window from app
if (new RegExp(deeplinkUrls.join("|")).test(url)) {
return {
action: "allow",
overrideBrowserWindowOptions: {
autoHideMenuBar: true,
},
};
}
// Check if the URL matches any mailServicesUrls for outlook.com
if (new RegExp(mailServicesUrls.join("|")).test(url)) {
// Open main MS365 apps the same window
safelinksUrls
this.win.loadURL(url)
return {
action: "deny",
};
}
shell.openExternal(url);
return {
action: "deny",
};
});

// prevent the app quit, hide the window instead.
Expand Down Expand Up @@ -166,9 +197,6 @@ class MailWindowController {
}
global.preventAutoCloseApp = false;
});

// Open the new window in external browser
this.win.webContents.on("new-window", this.openInBrowser);
}
addUnreadNumberObserver() {
this.win.webContents.executeJavaScript(
Expand All @@ -193,24 +221,6 @@ class MailWindowController {
this.win.reload();
}

openInBrowser(e, url, frameName, disposition, options) {
console.log("Open in browser: " + url); //frameName,disposition,options)
if (new RegExp(deeplinkUrls.join("|")).test(url)) {
// Default action - if the user wants to open mail in a new window - let them.
//e.preventDefault()
console.log("Is deeplink");
options.webPreferences.affinity = "main-window";
} else if (new RegExp(outlookUrls.join("|")).test(url)) {
// Open calendar, contacts and tasks in the same window
e.preventDefault();
this.loadURL(url);
} else {
// Send everything else to the browser
e.preventDefault();
shell.openExternal(url);
}
}

show() {
initialMinimization.domReady = false;
this.win.show();
Expand Down Expand Up @@ -253,7 +263,6 @@ class MailWindowController {
);
}
//console.log(params)

for (const flag in params.editFlags) {
let actionLabel = flag.substring(3); //remove "can"
if (flag == "canSelectAll") {
Expand Down
Loading

0 comments on commit 877be80

Please sign in to comment.