Use built-in url parsing in preload script

Latest electron allows acces to the url module in a preload script.
Also add a wrapper to shield global scope and use strict inside.

// FREEBIE
This commit is contained in:
lilia 2017-04-19 15:39:21 -07:00 committed by Scott Nonnenberg
parent 878b15c288
commit 4d11e257fe
No known key found for this signature in database
GPG key ID: A4931C09644C654B

View file

@ -1,15 +1,11 @@
/*
* Pending electron 1.6.x
* const env = require('url').parse(window.location, true).query;
*/
(function () {
'use strict';
console.log('preload');
const electron = require('electron')
console.log('preload');
window.config = require('url').parse(window.location.toString(), true).query;
window.config = {};
window.location.search.substring(1).split('&').forEach(function(variable) {
var pair = variable.split('=');
config[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
});
const ipc = electron.ipcRenderer
window.config.locale_json = ipc.sendSync('locale-data');
const ipc = require('electron').ipcRenderer
window.config.locale_json = ipc.sendSync('locale-data');
})();