BetterDiscordApp-rauenzi/src/modules/core.js

116 lines
4.3 KiB
JavaScript
Raw Normal View History

2019-05-28 23:27:25 +02:00
import BDV2 from "./bdv2";
2019-06-19 21:24:05 +02:00
import Logger from "./logger";
2019-06-04 21:17:23 +02:00
import {Config} from "data";
2019-06-03 22:25:08 +02:00
// import EmoteModule from "./emotes";
2019-05-31 07:53:11 +02:00
// import QuickEmoteMenu from "../builtins/emotemenu";
2019-06-19 05:09:49 +02:00
import DOMManager from "./dommanager";
2019-06-08 08:35:43 +02:00
import PluginManager from "./pluginmanager";
import ThemeManager from "./thememanager";
2019-06-06 21:57:25 +02:00
import Settings from "./settingsmanager";
2019-05-30 23:18:52 +02:00
import * as Builtins from "builtins";
2019-05-31 07:53:11 +02:00
import {Modals} from "ui";
2019-05-28 23:27:25 +02:00
2019-05-29 05:48:41 +02:00
function Core() {
2019-05-28 20:19:48 +02:00
}
2019-05-29 05:48:41 +02:00
Core.prototype.setConfig = function(config) {
Object.assign(Config, config);
};
2019-05-28 20:19:48 +02:00
Core.prototype.init = async function() {
2019-05-28 23:27:25 +02:00
if (Config.version < Config.minSupportedVersion) {
2019-05-31 07:53:11 +02:00
Modals.alert("Not Supported", "BetterDiscord v" + Config.version + " (your version)" + " is not supported by the latest js (" + Config.bbdVersion + ").<br><br> Please download the latest version from <a href='https://github.com/rauenzi/BetterDiscordApp/releases/latest' target='_blank'>GitHub</a>");
2019-05-28 20:19:48 +02:00
return;
}
2019-05-29 05:48:41 +02:00
const latestLocalVersion = Config.updater ? Config.updater.LatestVersion : Config.latestVersion;
if (latestLocalVersion > Config.version) {
2019-05-31 07:53:11 +02:00
Modals.alert("Update Available", `
2019-05-29 05:48:41 +02:00
An update for BandagedBD is available (${latestLocalVersion})! Please Reinstall!<br /><br />
2019-05-28 20:19:48 +02:00
<a href='https://github.com/rauenzi/BetterDiscordApp/releases/latest' target='_blank'>Download Installer</a>
`);
}
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Initializing Settings");
2019-06-06 21:57:25 +02:00
Settings.initialize();
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Initializing EmoteModule");
2019-06-03 22:25:08 +02:00
// window.emotePromise = EmoteModule.init().then(() => {
// EmoteModule.initialized = true;
2019-06-19 21:24:05 +02:00
// Logger.log("Startup", "Initializing QuickEmoteMenu");
2019-06-03 22:25:08 +02:00
// Events.dispatch("emotes-loaded");
// // QuickEmoteMenu.init();
// });
2019-05-28 20:19:48 +02:00
2019-06-11 04:33:45 +02:00
// this.injectExternals();
2019-05-28 20:19:48 +02:00
2019-06-19 05:09:49 +02:00
DOMManager.initialize();
2019-05-28 20:19:48 +02:00
await this.checkForGuilds();
BDV2.initialize();
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Updating Settings");
2019-05-30 23:18:52 +02:00
for (const module in Builtins) Builtins[module].initialize();
2019-05-28 20:19:48 +02:00
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Loading Plugins");
2019-06-08 08:35:43 +02:00
const pluginErrors = PluginManager.loadAllPlugins();
2019-05-28 20:19:48 +02:00
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Loading Themes");
2019-06-08 08:35:43 +02:00
const themeErrors = ThemeManager.loadAllThemes();
2019-05-28 20:19:48 +02:00
2019-05-30 23:18:52 +02:00
// PublicServers.initialize();
2019-06-03 22:25:08 +02:00
// EmoteModule.autoCapitalize();
2019-05-28 20:19:48 +02:00
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Removing Loading Icon");
2019-05-28 20:19:48 +02:00
document.getElementsByClassName("bd-loaderv2")[0].remove();
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Initializing Main Observer");
2019-05-28 20:19:48 +02:00
this.initObserver();
// Show loading errors
2019-06-19 21:24:05 +02:00
Logger.log("Startup", "Collecting Startup Errors");
2019-06-03 22:25:08 +02:00
Modals.showContentErrors({plugins: pluginErrors, themes: themeErrors});
2019-05-28 20:19:48 +02:00
};
Core.prototype.checkForGuilds = function() {
return new Promise(resolve => {
const checkForGuilds = function() {
2019-06-19 21:24:05 +02:00
if (document.readyState != "complete") setTimeout(checkForGuilds, 100);
2019-05-28 20:19:48 +02:00
const wrapper = BDV2.guildClasses.wrapper.split(" ")[0];
const guild = BDV2.guildClasses.listItem.split(" ")[0];
const blob = BDV2.guildClasses.blobContainer.split(" ")[0];
2019-05-28 23:27:25 +02:00
if (document.querySelectorAll(`.${wrapper} .${guild} .${blob}`).length > 0) return resolve(Config.deferLoaded = true);
2019-05-28 20:19:48 +02:00
setTimeout(checkForGuilds, 100);
};
2019-06-19 21:24:05 +02:00
checkForGuilds();
2019-05-28 20:19:48 +02:00
});
};
Core.prototype.initObserver = function () {
const mainObserver = new MutationObserver((mutations) => {
for (let i = 0, mlen = mutations.length; i < mlen; i++) {
const mutation = mutations[i];
2019-05-28 20:19:48 +02:00
// if there was nothing added, skip
if (!mutation.addedNodes.length || !(mutation.addedNodes[0] instanceof Element)) continue;
const node = mutation.addedNodes[0];
2019-05-28 20:19:48 +02:00
if (node.classList.contains("layer-3QrUeG")) {
if (node.getElementsByClassName("guild-settings-base-section").length) node.setAttribute("layer-id", "server-settings");
2019-06-04 06:18:15 +02:00
// if (node.getElementsByClassName("socialLinks-3jqNFy").length) {
// node.setAttribute("layer-id", "user-settings");
// node.setAttribute("id", "user-settings");
2019-06-06 21:57:25 +02:00
// if (!document.getElementById("bd-settings-sidebar")) Settings.renderSidebar();
2019-06-04 06:18:15 +02:00
// }
2019-05-28 20:19:48 +02:00
}
}
});
mainObserver.observe(document, {
childList: true,
subtree: true
});
};
2019-05-28 23:27:25 +02:00
2019-05-29 05:48:41 +02:00
export default new Core();