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

feat(electron): Remove injectCapacitor function #2415

Merged
Merged
Show file tree
Hide file tree
Changes from all 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/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function createWindow () {

if(useSplashScreen) {
splashScreen = new CapacitorSplashScreen(mainWindow);
splashScreen.init(false);
splashScreen.init();
} else {
mainWindow.loadURL(`file://${__dirname}/app/index.html`);
mainWindow.webContents.on('dom-ready', () => {
Expand Down
22 changes: 2 additions & 20 deletions electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ function getURLFileContents(path) {
});
}

const injectCapacitor = async function (url) {
console.warn('\nWARNING: injectCapacitor method is deprecated and will be removed in next major release. Check release notes for migration instructions\n')
try {
let urlFileContents = await getURLFileContents(url.substr(url.indexOf('://') + 3));
let pathing = path.join(url.substr(url.indexOf('://') + 3), '../../node_modules/@capacitor/electron/dist/electron-bridge.js');
urlFileContents = urlFileContents.replace('<body>', `<body><script>window.require('${pathing.replace(/\\/g, '\\\\')}')</script>`);
return 'data:text/html;charset=UTF-8,' + urlFileContents;
} catch (e) {
console.error(e);
return url;
}
};

const configCapacitor = async function(mainWindow) {
let capConfigJson = JSON.parse(fs.readFileSync(`./capacitor.config.json`, 'utf-8'));
const appendUserAgent = capConfigJson.electron && capConfigJson.electron.appendUserAgent ? capConfigJson.electron.appendUserAgent : capConfigJson.appendUserAgent;
Expand Down Expand Up @@ -103,7 +90,7 @@ class CapacitorSplashScreen {
});
}

init(inject = true) {
init() {
let rootPath = app.getAppPath();

this.splashWindow = new BrowserWindow({
Expand Down Expand Up @@ -152,11 +139,7 @@ class CapacitorSplashScreen {
this.splashWindow.webContents.on('dom-ready', async () => {
this.splashWindow.show();
setTimeout(async () => {
if (inject) {
this.mainWindowRef.loadURL(await injectCapacitor(`file://${rootPath}/app/index.html`), { baseURLForDataURL: `file://${rootPath}/app/` });
} else {
this.mainWindowRef.loadURL(`file://${rootPath}/app/index.html`);
}
this.mainWindowRef.loadURL(`file://${rootPath}/app/index.html`);
}, 4500);
});

Expand All @@ -181,7 +164,6 @@ class CapacitorSplashScreen {
}

module.exports = {
injectCapacitor,
configCapacitor,
CapacitorSplashScreen
};