mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2025-01-09 14:12:05 -05:00
fix makeFullUrl for file:// on Windows
This commit is contained in:
parent
33a17879b2
commit
fdd7a8463f
1 changed files with 13 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
||||||
import {BrowserWindow, Menu, app, dialog, ipcMain, systemPreferences} from 'electron';
|
import {BrowserWindow, Menu, app, dialog, ipcMain, systemPreferences} from 'electron';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {format as formatUrl} from 'url';
|
import {URL} from 'url';
|
||||||
|
|
||||||
import {getFilterForExtension} from './FileFilters';
|
import {getFilterForExtension} from './FileFilters';
|
||||||
import telemetry from './ScratchDesktopTelemetry';
|
import telemetry from './ScratchDesktopTelemetry';
|
||||||
|
@ -58,22 +58,17 @@ const displayPermissionDeniedWarning = (browserWindow, permissionType) => {
|
||||||
* @param {*} search - the optional "search" parameters (the part of the URL after '?'), like "route=about"
|
* @param {*} search - the optional "search" parameters (the part of the URL after '?'), like "route=about"
|
||||||
* @returns {string} - an absolute URL as a string
|
* @returns {string} - an absolute URL as a string
|
||||||
*/
|
*/
|
||||||
const makeFullUrl = (url, search = null) =>
|
const makeFullUrl = (url, search = null) => {
|
||||||
encodeURI(formatUrl(isDevelopment ?
|
const baseUrl = (isDevelopment ?
|
||||||
{ // Webpack Dev Server
|
`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}/` :
|
||||||
hostname: 'localhost',
|
`file://${__dirname}/`
|
||||||
pathname: url,
|
);
|
||||||
port: process.env.ELECTRON_WEBPACK_WDS_PORT,
|
const fullUrl = new URL(url, baseUrl);
|
||||||
protocol: 'http',
|
if (search) {
|
||||||
search,
|
fullUrl.search = search; // automatically percent-encodes anything that needs it
|
||||||
slashes: true
|
}
|
||||||
} : { // production / bundled
|
return fullUrl.toString();
|
||||||
pathname: path.join(__dirname, url),
|
};
|
||||||
protocol: 'file',
|
|
||||||
search,
|
|
||||||
slashes: true
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompt in a platform-specific way for permission to access the microphone or camera, if Electron supports doing so.
|
* 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
|
||||||
// deny: request is for some other kind of access like notifications or pointerLock
|
// deny: request is for some other kind of access like notifications or pointerLock
|
||||||
return callback(false);
|
return callback(false);
|
||||||
}
|
}
|
||||||
const requiredBase = makeFullUrl('/');
|
const requiredBase = makeFullUrl('');
|
||||||
if (details.requestingUrl.indexOf(requiredBase) !== 0) {
|
if (details.requestingUrl.indexOf(requiredBase) !== 0) {
|
||||||
// deny: request came from a URL outside of our "sandbox"
|
// deny: request came from a URL outside of our "sandbox"
|
||||||
return callback(false);
|
return callback(false);
|
||||||
|
|
Loading…
Reference in a new issue