rudimentary preload script support

This commit is contained in:
Astra 2018-05-03 13:28:57 -04:00
parent f430a4159f
commit a8aca55ed5
2 changed files with 12 additions and 7 deletions

View file

@ -40,14 +40,19 @@
win.webContents.executeJavaScript(stage2);
});
function load() {
var branch = require('path').basename(electron.app.getPath("userData")).substr(7);
win.loadURL('https://' + (branch ? branch + '.' : '') + 'discordapp.com/channels/@me');
}
// get the data path
var data = electron.app.getPath('userData');
function load() {
var branch = require('path').basename(data).substr(7);
var preload = '';
if (fs.existsSync(data + '/preload.js')) {
preload = fs.readFileSync(data + '/preload.js').toString();
}
win.loadURL('https://' + (branch ? branch + '.' : '') + 'discordapp.com/channels/@me');
win.webContents.executeJavaScript(preload);
}
// dont update EPAPI if DONTUPDATE exists
if (!fs.existsSync(data + '/DONTUPDATE')) {

View file

@ -25,11 +25,11 @@
var fs = electron.require('original-fs');
// get the data path (where epapi.js should be)
var data = electron.app.getPath('userData').replace(/\\\\/g, "/") + '/';
var ___data = electron.app.getPath('userData').replace(/\\\\/g, "/") + '/';
// shakily reimplemented of require() intended for loading plugins and EPAPI itself
function __krequire(path) {
return eval('(()=>{var exports={};' + fs.readFileSync(data + path, 'utf8').toString() + ';return exports})()');
return eval('(()=>{var exports={};' + fs.readFileSync(___data + path, 'utf8').toString() + ';return exports})()');
}
// load EPAPI