From 4d11e257fe0823c1f8ecacf7cbc82b878e834808 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 19 Apr 2017 15:39:21 -0700 Subject: [PATCH] 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 --- preload.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/preload.js b/preload.js index 840b9c5e0..2ba77f103 100644 --- a/preload.js +++ b/preload.js @@ -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'); +})();