Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`electron-protocol-serve` seems to have taken us too far off the beaten path, so this changes `ember-electron` to set up projects to load from file: URLs instead of the custom protocol. This requires a couple of workarounds to make Ember apps work properly when loaded from file: URLs -- all explained in detail in the new FAQ page. This gets us sourcemaps back in Electron 7+, and also removes the need for a variety of minor workarounds for security/sandboxing issues caused by our use of a custom protocol. Fixes #442
- Loading branch information
1 parent
05f16f8
commit f2bba3f
Showing
20 changed files
with
416 additions
and
166 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
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,29 @@ | ||
const { protocol } = require('electron'); | ||
const { fileURLToPath } = require('url'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { promisify } = require('util'); | ||
|
||
const access = promisify(fs.access); | ||
|
||
// | ||
// Patch asset loading -- Ember apps use absolute paths to reference their | ||
// assets, e.g. `<img src="/images/foo.jpg">`. When the current URL is a `file:` | ||
// URL, that ends up resolving to the absolute filesystem path `/images/foo.jpg` | ||
// rather than being relative to the root of the Ember app. So, we intercept | ||
// `file:` URL request and look to see if they point to an asset when | ||
// interpreted as being relative to the root of the Ember app. If so, we return | ||
// that path, and if not we leave them as-is, as their absolute path. | ||
// | ||
module.exports = function handleFileURLs(emberAppDir) { | ||
protocol.interceptFileProtocol('file', async ({ url }, callback) => { | ||
let urlPath = fileURLToPath(url); | ||
let appPath = path.join(emberAppDir, urlPath); | ||
try { | ||
await access(appPath); | ||
callback(appPath); | ||
} catch (e) { | ||
callback(urlPath); | ||
} | ||
}); | ||
}; |
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
This file was deleted.
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
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
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
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
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
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
Oops, something went wrong.