Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"indent_with_tabs": true, | ||
"wrap_line_length": 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,72 @@ | ||
let {app, protocol, BrowserWindow} = require("electron"); | ||
let {readFile} = require("fs"); | ||
let {extname} = require("path"); | ||
let {URL} = require("url"); | ||
let { | ||
app, | ||
protocol, | ||
BrowserWindow | ||
} = require("electron"); | ||
let { | ||
readFile | ||
} = require("fs"); | ||
let { | ||
extname | ||
} = require("path"); | ||
let { | ||
URL | ||
} = require("url"); | ||
|
||
let createProtocol = (scheme, normalize = true) => { | ||
protocol.registerBufferProtocol(scheme, | ||
(request, respond) => { | ||
let pathName = new URL(request.url).pathname; | ||
pathName = decodeURI(pathName); // Needed in case URL contains spaces | ||
|
||
readFile(__dirname + "/" + pathName, (error, data) => { | ||
let extension = extname(pathName).toLowerCase(); | ||
let mimeType = ""; | ||
protocol.registerBufferProtocol(scheme, | ||
(request, respond) => { | ||
let pathName = new URL(request.url).pathname; | ||
|
||
if (extension === ".js") { | ||
mimeType = "text/javascript"; | ||
} | ||
else if (extension === ".html") { | ||
mimeType = "text/html"; | ||
} | ||
else if (extension === ".css") { | ||
mimeType = "text/css"; | ||
} | ||
else if (extension === ".svg" || extension === ".svgz") { | ||
mimeType = "image/svg+xml"; | ||
} | ||
else if (extension === ".json") { | ||
mimeType = "application/json"; | ||
} | ||
// Needed in case URL contains spaces | ||
pathName = decodeURI(pathName); | ||
|
||
respond({mimeType, data}); | ||
}); | ||
}, | ||
(error) => { | ||
if (error) { | ||
console.error(`Failed to register ${scheme} protocol`, error); | ||
} | ||
} | ||
); | ||
readFile(__dirname + "/" + pathName, (error, data) => { | ||
let extension = extname(pathName).toLowerCase(); | ||
let mimeType = ""; | ||
|
||
if (extension === ".js") { | ||
mimeType = "text/javascript"; | ||
} else if (extension === ".html") { | ||
mimeType = "text/html"; | ||
} else if (extension === ".css") { | ||
mimeType = "text/css"; | ||
} else if (extension === ".svg" || extension === | ||
".svgz") { | ||
mimeType = "image/svg+xml"; | ||
} else if (extension === ".json") { | ||
mimeType = "application/json"; | ||
} | ||
|
||
respond({ | ||
mimeType, | ||
data | ||
}); | ||
}); | ||
}, | ||
(error) => { | ||
if (error) { | ||
console.error(`Failed to register ${scheme} protocol`, | ||
error); | ||
} | ||
} | ||
); | ||
} | ||
|
||
// Standard scheme must be registered before the app is ready | ||
protocol.registerStandardSchemes(["app"], { secure: true }); | ||
protocol.registerStandardSchemes(["app"], { | ||
secure: true | ||
}); | ||
|
||
app.on("ready", () => { | ||
createProtocol("app"); | ||
let browserWindow = new BrowserWindow({ | ||
webPreferences: { | ||
preload: `${__dirname}/preload.js`, | ||
nodeIntegration: false, | ||
contextIsolation: true | ||
} | ||
}); | ||
|
||
//browserWindow.webContents.openDevTools(); | ||
browserWindow.loadFile("index.html"); | ||
}); | ||
createProtocol("app"); | ||
let browserWindow = new BrowserWindow({ | ||
webPreferences: { | ||
preload: `${__dirname}/preload.js`, | ||
nodeIntegration: false, | ||
contextIsolation: true | ||
} | ||
}); | ||
//browserWindow.webContents.openDevTools(); | ||
browserWindow.loadFile("index.html"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
let {webFrame} = require("electron"); | ||
let { | ||
webFrame | ||
} = require("electron"); | ||
|
||
process.once("loaded", () => { | ||
// Allow window.fetch() to access app files | ||
webFrame.registerURLSchemeAsPrivileged("app", { | ||
secure: true, | ||
bypassCSP: false, | ||
allowServiceWorkers: true, | ||
supportFetchAPI: true, | ||
corsEnabled: false | ||
}); | ||
// Allow window.fetch() to access app files | ||
webFrame.registerURLSchemeAsPrivileged("app", { | ||
secure: true, | ||
bypassCSP: false, | ||
allowServiceWorkers: true, | ||
supportFetchAPI: true, | ||
corsEnabled: false | ||
}); | ||
}); |