Skip to content

Commit fdd7a84

Browse files
author
Christopher Willis-Ford
committed
fix makeFullUrl for file:// on Windows
1 parent 33a1787 commit fdd7a84

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/main/index.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {BrowserWindow, Menu, app, dialog, ipcMain, systemPreferences} from 'electron';
22
import fs from 'fs';
33
import path from 'path';
4-
import {format as formatUrl} from 'url';
4+
import {URL} from 'url';
55

66
import {getFilterForExtension} from './FileFilters';
77
import telemetry from './ScratchDesktopTelemetry';
@@ -58,22 +58,17 @@ const displayPermissionDeniedWarning = (browserWindow, permissionType) => {
5858
* @param {*} search - the optional "search" parameters (the part of the URL after '?'), like "route=about"
5959
* @returns {string} - an absolute URL as a string
6060
*/
61-
const makeFullUrl = (url, search = null) =>
62-
encodeURI(formatUrl(isDevelopment ?
63-
{ // Webpack Dev Server
64-
hostname: 'localhost',
65-
pathname: url,
66-
port: process.env.ELECTRON_WEBPACK_WDS_PORT,
67-
protocol: 'http',
68-
search,
69-
slashes: true
70-
} : { // production / bundled
71-
pathname: path.join(__dirname, url),
72-
protocol: 'file',
73-
search,
74-
slashes: true
75-
}
76-
));
61+
const makeFullUrl = (url, search = null) => {
62+
const baseUrl = (isDevelopment ?
63+
`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}/` :
64+
`file://${__dirname}/`
65+
);
66+
const fullUrl = new URL(url, baseUrl);
67+
if (search) {
68+
fullUrl.search = search; // automatically percent-encodes anything that needs it
69+
}
70+
return fullUrl.toString();
71+
};
7772

7873
/**
7974
* Prompt in a platform-specific way for permission to access the microphone or camera, if Electron supports doing so.
@@ -105,7 +100,7 @@ const handlePermissionRequest = async (webContents, permission, callback, detail
105100
// deny: request is for some other kind of access like notifications or pointerLock
106101
return callback(false);
107102
}
108-
const requiredBase = makeFullUrl('/');
103+
const requiredBase = makeFullUrl('');
109104
if (details.requestingUrl.indexOf(requiredBase) !== 0) {
110105
// deny: request came from a URL outside of our "sandbox"
111106
return callback(false);

0 commit comments

Comments
 (0)