Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Handle Windows file urls, fixes #419
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Oct 28, 2019
1 parent 1f24a54 commit 9bac186
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 7 additions & 5 deletions app/index.js
Expand Up @@ -156,13 +156,15 @@ function createWindow () {
return url.startsWith("http") || url.startsWith("https");
}

// Check urls for equality by decoding components
// Check file urls for equality by decoding components
// In packaged app, spaces in navigation events urls can contain %20 but not in windowUrl.
const safeUrlCompare = (a, b) => {
const safeFileUrlCompare = (a, b) => {
// Catch exceptions in case of malformed urls.
try {
let equal = decodeURIComponent(a) === decodeURIComponent(b);
return equal;
// Craft URL objects to eliminate production URL values that can contain "#!/" suffixes (on Windows)
let aPath = new URL(decodeURIComponent(a)).pathname;
let bPath = new URL(decodeURIComponent(b)).pathname;
return aPath === bPath;
} catch (error) {
return false;
}
Expand All @@ -180,7 +182,7 @@ function createWindow () {
// 'new-window' when target is not set to _blank)
win.webContents.on('will-navigate', function(event, url) {
// Check for windowUrl equality in the case of window.reload() calls.
if(safeUrlCompare(url, windowUrl) === true) {
if(safeFileUrlCompare(url, windowUrl) === true) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/javascripts/renderer/preload.js
Expand Up @@ -80,7 +80,7 @@ function loadTransmitter() {

function listenForIpcEvents() {

const sendMessage = (message, payload) => {
const sendMessage = (message, payload = {}) => {
window.postMessage(JSON.stringify({message, data: payload}), rendererPath);
}

Expand Down
6 changes: 4 additions & 2 deletions app/javascripts/renderer/renderer.js
Expand Up @@ -138,8 +138,10 @@ async function registerIpcMessageListener() {
controllerScope.onUpdateAvailable();
} else if(message === "download-backup") {
desktopManager.desktop_didBeginBackup();
let data = desktopManager.desktop_requestBackupFile((data) => {
bridge.sendIpcMessage('data-archive', data);
desktopManager.desktop_requestBackupFile((data) => {
if(data) {
bridge.sendIpcMessage('data-archive', data);
}
});
} else if(message === "finished-saving-backup") {
desktopManager.desktop_didFinishBackup(data.success);
Expand Down

0 comments on commit 9bac186

Please sign in to comment.