Skip to content
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

fix(electron): make apps work on electron 7 #2084

Merged
merged 5 commits into from
Dec 10, 2019

Conversation

walkingriver
Copy link
Contributor

@walkingriver walkingriver commented Oct 23, 2019

Given that Electron is now at v7, this PR is to support that in Capacitor, and also provides a minor fix in the SplashScreen that is a response to a recently-reported Electron bug.

I've been using the capacitor/electron project with Electron v6.0.12 for a few weeks now, and haven't seen any issues. Recommending we make it official.
@jcesarmobile
Copy link
Member

There is another PR already.
Also, just saw 7.0.0 was released a few days ago, can you try that version?

@walkingriver
Copy link
Contributor Author

You are correct. I will try 7 tonight, after reviewing the release notes. We can probably just close this PR for now.

@hatsantos
Copy link

hatsantos commented Oct 25, 2019

I'm also using Electron 6 and Ionic 4 without problems.
I think Electron 4 will be deprecated now that Electron 7 was released.

I tryed to update to Electron 7 but got some errors...

npx cap open electron

[email protected] electron:start D:\_GIT\ManagerWebApp\electron
> electron ./

 Cannot read property 'SplashScreen' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 2147483651
npm ERR! [email protected] electron:start: `electron ./`
npm ERR! Exit status 2147483651
npm ERR! Exit status 2147483651
npm ERR!
npm ERR! Failed at the [email protected] electron:start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\hats\AppData\Roaming\npm-cache\_logs\2019-10-25T09_34_46_041Z-debug.log

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  killed: false,
  code: 2147483651,
  signal: null,
  cmd: 'npm run electron:start'
}

npx cap open

? Please choose a platform to open: electron
[info] Opening Electron project at D:\_GIT\ManagerWebApp\electron
[error] Error: Command failed: npm run electron:start
npm ERR! code ELIFECYCLE
npm ERR! errno 2147483651
npm ERR! [email protected] electron:start: `electron ./`
npm ERR! Exit status 2147483651
npm ERR!
npm ERR! Failed at the [email protected] electron:start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\hats\AppData\Roaming\npm-cache\_logs\2019-10-25T09_48_37_683Z-debug.log

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  killed: false,
  code: 2147483651,
  signal: null,
  cmd: 'npm run electron:start'
}

@bcallaghan-fri
Copy link

@hatsantos I'm getting the same error you are. Are you using the SplashScreen plugin? If I remove the SplashScreen, and load my index.html file directly, I don't get this error. I recommend moving this conversation to a bug report for the SplashScreen.

@walkingriver
Copy link
Contributor Author

Ok, this isn't quite as awful as it seems. There is an issue with Electron 7, webview setting baseURLForDataURL crashes Electron #20700. This is how the CapacitorSplashScreen plugin works. Removing the baseURLForDataURL parameter causes the splash screen to load (without the image, though), and then the app continues to run properly from there.

@@ -67,7 +67,7 @@ class CapacitorSplashScreen {
let capConfigJson = JSON.parse(fs.readFileSync(`./capacitor.config.json`, 'utf-8'));
this.splashOptions = Object.assign(
this.splashOptions,
capConfigJson.plugins.SplashScreen
capConfigJson.plugins.SplashScreen || {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the error if the developer has not provided the options in capacitor.config.json. This option should be documented better. Very useful.

Comment on lines 103 to 106
webPreferences: {
// Required to load file:// splash screen
webSecurity: false
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure this is safe as long as we're only loading a splash screen. It might make more sense to base this value on whether or not the developer provided customHtml, which cannot be verified.

@@ -118,7 +124,7 @@ class CapacitorSplashScreen {
}
});

this.splashWindow.loadURL(`data:text/html;charset=UTF-8,${splashHtml}`, {baseURLForDataURL: `file://${rootPath}/splash_assets/`});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the response to Electron bug: electron/electron#20700

@walkingriver walkingriver changed the title Bump Electron to latest official version Bump Electron to official version 7.0.0 Oct 27, 2019
@walkingriver
Copy link
Contributor Author

@jcesarmobile, are you an official reviewer? This definitely fixes the issue with Electron 7. It may not be the right long-term fix, but it does solve the immediate problem.

electron/index.js Outdated Show resolved Hide resolved
The imagePath should now work on both macOS and Windows, by using the url object.
Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out pathToFileURL was included in node 10.12.0, but Electron 4 shiped with 10.11.0, so this changes will break existing apps using Electron 4, and since that was the pinned version before this PR could be a lot. Despite it's an easy fix, users just need to bump their Electron version to 5 or greater, I've pushed some changes to keep the old behaviour in case pathToFileURL is not available.
Will merge once the tests finish.
Thanks for the PR!

@jcesarmobile jcesarmobile changed the title Bump Electron to official version 7.0.0 fix(electron): make apps work on electron 7 Dec 10, 2019
@jcesarmobile jcesarmobile merged commit 046aad2 into ionic-team:master Dec 10, 2019
@walkingriver walkingriver deleted the patch-4 branch December 10, 2019 16:18
@bryplano bryplano mentioned this pull request Dec 11, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants