Move loaders to same dom event and added a failsafe dom hook
This commit is contained in:
parent
105a04a000
commit
0fdfcaa3e8
|
@ -1,5 +1,5 @@
|
|||
/* BetterDiscordApp Entry
|
||||
* Version: 2.0
|
||||
* Version: 2.1
|
||||
* Author: Jiiks | http://jiiks.net
|
||||
* Date: 27/08/2015 - 15:51
|
||||
* Last Update: 30/11/2015 - 21:41
|
||||
|
@ -12,45 +12,16 @@ var _config = require("./config.json");
|
|||
var _utils = require("./utils");
|
||||
var _ipc = require('ipc');
|
||||
|
||||
//For IDE
|
||||
/*_config = {
|
||||
"Core": {
|
||||
"Version": "0.2.0"
|
||||
},
|
||||
"EmoteModule": {
|
||||
"Twitch":{
|
||||
"EmoteData": "emotedata_twitch.json",
|
||||
"EmoteUrlStart": "https://static-cdn.jtvnw.net/emoticons/v1/",
|
||||
"EmoteUrlEnd": "/1.0"
|
||||
},
|
||||
"FrankerFaceZ": {
|
||||
"EmoteData": "emotedata_ffz.json",
|
||||
"EmoteUrlStart": "https://cdn.frankerfacez.com/emoticon/",
|
||||
"EmoteUrlEnd": "/1"
|
||||
},
|
||||
"BetterTTV": {
|
||||
"EmoteData": "emotedata_bttv.json",
|
||||
"EmoteUrlStart": "",
|
||||
"EmoteUrlEnd": ""
|
||||
}
|
||||
}
|
||||
};*/
|
||||
|
||||
var _repo = "Jiiks";
|
||||
|
||||
//Beta flag
|
||||
var _beta = false;
|
||||
var _alerts = true;
|
||||
//Local flag
|
||||
var _local = false;
|
||||
var _localServer = "http://localhost";
|
||||
//Please note that you must either use https or set web-security to false when using local server
|
||||
//Everything is loaded from _localServer/BetterDiscordApp/
|
||||
//For css use: _localServer/BetterDiscordApp/css/main.css
|
||||
//For js use: _localServer/BetterDiscordApp/js/main.js
|
||||
|
||||
//Variables
|
||||
var _version
|
||||
var _version;
|
||||
var _mainWindow;
|
||||
var _updater;
|
||||
var _hash;
|
||||
|
@ -62,6 +33,13 @@ var _cacheDays = 0;
|
|||
|
||||
var _dataPath;
|
||||
|
||||
//IDE
|
||||
_config = {
|
||||
"Core": {
|
||||
"Version": "0.2.5"
|
||||
}
|
||||
};
|
||||
|
||||
//noinspection JSUnresolvedVariable;
|
||||
var _os = process.platform;
|
||||
var _userFile;
|
||||
|
@ -70,7 +48,6 @@ var _this;
|
|||
function BetterDiscord(mainWindow) {
|
||||
_this = this;
|
||||
_mainWindow = mainWindow;
|
||||
this.initLoaders();
|
||||
_version = _config.Core.Version;
|
||||
_utils = new _utils.Utils(mainWindow);
|
||||
|
||||
|
@ -82,7 +59,6 @@ BetterDiscord.prototype.initLoaders = function(){
|
|||
var _dataPath = os == "win32" ? process.env.APPDATA : os == 'darwin' ? process.env.HOME + '/Library/Preferences' : '/var/local';
|
||||
_dataPath += "/BetterDiscord/";
|
||||
|
||||
_mainWindow.webContents.on('dom-ready', function() {
|
||||
if (!_fs.existsSync(_dataPath)) {
|
||||
console.log('BetterDiscord: Creating BD Dir');
|
||||
_fs.mkdirSync(_dataPath);
|
||||
|
@ -148,12 +124,11 @@ BetterDiscord.prototype.initLoaders = function(){
|
|||
_mainWindow.webContents.executeJavaScript('(function() { bdthemes["' + themeName + '"] = { "enabled": false, "name": "' + themeName + '", "css": "' + escape(theme) + '", "description": "' + themeDescription + '", "author":"' + themeAuthor + '", "version":"' + themeVersion + '" } })();');
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
BetterDiscord.prototype.getUtils = function() {
|
||||
return _utils;
|
||||
}
|
||||
};
|
||||
|
||||
BetterDiscord.prototype.createAndCheckData = function(callback) {
|
||||
|
||||
|
@ -258,7 +233,9 @@ BetterDiscord.prototype.init = function() {
|
|||
|
||||
BetterDiscord.prototype.start = function() {
|
||||
_this.getUtils().log("Hooking dom-ready");
|
||||
_this.getUtils().getWebContents().on('dom-ready', function() { _this.domReady(); });
|
||||
var webContents = _this.getUtils().getWebContents();
|
||||
webContents.on('dom-ready', function() { _this.domReady(); });
|
||||
webContents.on("did-finish-loading", function() { if(!_domHooked) { _this.getUtils().log("Failsafe"); _this.domReady(); } });
|
||||
};
|
||||
|
||||
BetterDiscord.prototype.quit = function(reason) {
|
||||
|
@ -267,8 +244,12 @@ BetterDiscord.prototype.quit = function(reason) {
|
|||
|
||||
var ipcHooked = false;
|
||||
|
||||
var _domHooked = false;
|
||||
|
||||
BetterDiscord.prototype.domReady = function() {
|
||||
|
||||
_domHooked = true;
|
||||
|
||||
if(ipcHooked) {
|
||||
_this.load(true);
|
||||
return;
|
||||
|
@ -281,6 +262,8 @@ BetterDiscord.prototype.domReady = function() {
|
|||
BetterDiscord.prototype.load = function(reload) {
|
||||
_this.getUtils().log("Hooked dom-ready");
|
||||
|
||||
_this.initLoaders();
|
||||
|
||||
if(reload) {
|
||||
_this.getUtils().log("Reloading");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue