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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion electron-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"electron-is-dev": "^1.1.0"
},
"devDependencies": {
"electron": "^4.0.0"
"electron": "^7.0.0"
},
"keywords": [
"capacitor",
Expand Down
12 changes: 9 additions & 3 deletions electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

);
} catch (e) {
console.error(e.message);
Expand Down Expand Up @@ -100,11 +100,17 @@ class CapacitorSplashScreen {
frame: false,
show: false,
transparent: this.splashOptions.transparentWindow,
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.

});

let imagePath = path.join(rootPath,'splash_assets', this.splashOptions.imageFileName);
walkingriver marked this conversation as resolved.
Show resolved Hide resolved

let splashHtml = this.splashOptions.customHtml || `
<html style="width: 100%; height: 100%; margin: 0; overflow: hidden;">
<body style="background-image: url('./${this.splashOptions.imageFileName}'); background-position: center center; background-repeat: no-repeat; width: 100%; height: 100%; margin: 0; overflow: hidden;">
<body style="background-image: url('file://${imagePath}'); background-position: center center; background-repeat: no-repeat; width: 100%; height: 100%; margin: 0; overflow: hidden;">
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: ${this.splashOptions.textColor}; position: absolute; top: ${this.splashOptions.textPercentageFromTop}%; text-align: center; font-size: 10vw; width: 100vw;">
${this.splashOptions.loadingText}
</div>
Expand All @@ -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

this.splashWindow.loadURL(`data:text/html;charset=UTF-8,${splashHtml}`);

this.splashWindow.webContents.on('dom-ready', async () => {
this.splashWindow.show();
Expand Down