Skip to content

Commit

Permalink
feat(electron): Remove injectCapacitor function (ionic-team#2415)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored and priyankpat committed Feb 13, 2020
1 parent 5c6d6aa commit 64a02ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
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
};

0 comments on commit 64a02ae

Please sign in to comment.