-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from electron-protocol-serve to file: URLs #476
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 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,9 +1,30 @@ | ||
const { default: installExtension, EMBER_INSPECTOR } = require('electron-devtools-installer'); | ||
const path = require('path'); | ||
const { app } = require('electron'); | ||
const handleFileUrls = require('../src/handle-file-urls'); | ||
const { setupTestem, openTestWindow } = require('ember-electron/lib/test-support'); | ||
|
||
require('electron').app.on('ready', function onReady() { | ||
require('devtron').install(); | ||
installExtension(EMBER_INSPECTOR) | ||
.catch((err) => console.log('An error occurred: ', err)); | ||
const emberAppDir = path.resolve(__dirname, '..', 'ember-test'); | ||
|
||
app.on('ready', async function onReady() { | ||
try { | ||
require('devtron').install(); | ||
} catch (err) { | ||
console.log('Failed to install Devtron: ', err); | ||
} | ||
try { | ||
await installExtension(EMBER_INSPECTOR); | ||
} catch (err) { | ||
console.log('Failed to install Ember Inspector: ', err); | ||
} | ||
|
||
await handleFileUrls(emberAppDir); | ||
setupTestem(); | ||
openTestWindow(emberAppDir); | ||
}); | ||
|
||
require('ember-electron/lib/test-support/test-index'); | ||
app.on('window-all-closed', function onWindowAllClosed() { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me again why we can't use
fsPromises
... Need to support Node < 10.x?I see this in package.json:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, yeah, we kinda recently dropped node 8 support, so that's why we were avoiding it before. However, this is a different case, because this code runs in the Electron main process, not the user's Node environment, so the
engines
inpackage.json
isn't relevant here, just the version of Electron that the user is running.But Electron has been on Node 10+ since 3.x, and I'm quite confident that there are other reasons this code would break on Electron <=2, not the least of which is the usage of
fileURLToPath
in this same file, which wasn't introduced until Node 10.12/Electron 5 😆I don't think we have an official policy on which versions of Electron we do and don't target, but since:
I think we're fine keeping the usage of
fileURLToPath
and usingfs.promises
. I'll make the change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should maybe support Electron 5+ or whatever we had to update Electron Forge for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW the Electron team only supports the latest 3 stable branches. So now that 9.0.0 is out I think that means versions older than 7.x are no longer supported. I am fine with 5+, but my gut would be to target actively supported versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grumble grumble https://travis-ci.com/github/adopted-ember-addons/ember-electron/jobs/337264506#L610
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be fine with Electron 7+, and I would honestly also be fine with bumping node minimum to 12, but ember-cli supports 10 until April 2021.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is kinda silly because
eslint
is warning us about code that runs in Electron, not the environment that theengines
field is describing. So I don't think bumping our minimum required node version makes any sense because I don't think we use anyfs.promises
in code that actually runs in the user's node environment, so we'd be dropping support just to make the linter happy.That being said, I do think it makes sense to get more specific about what Electron versions we support, but haven't put any thought into really how to accomplish that -- I guess it would just be documentation and then testing against all supported (major) versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we would mainly list in the documentation that we don't support earlier Electron versions, but that it may still work.