-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
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.
There is another PR already. |
You are correct. I will try 7 tonight, after reviewing the release notes. We can probably just close this PR for now. |
I'm also using Electron 6 and Ionic 4 without problems. I tryed to update to Electron 7 but got some errors...
|
@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. |
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 || {} |
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.
This removes the error if the developer has not provided the options in capacitor.config.json
. This option should be documented better. Very useful.
electron/index.js
Outdated
webPreferences: { | ||
// Required to load file:// splash screen | ||
webSecurity: false | ||
} |
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 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/`}); |
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.
This is the response to Electron bug: electron/electron#20700
@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. |
The imagePath should now work on both macOS and Windows, by using the url object.
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.
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!
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.