import BDV2 from "./bdv2";
import Utilties from "./utilities";
import {Config, SettingsCookie} from "data";
import EmoteModule from "./emotes";
import QuickEmoteMenu from "./emotemenu";
// import VoiceMode from "./voicemode";
// import DevMode from "./devmode";
import PluginManager from "./pluginmanager";
import ThemeManager from "./thememanager";
import DataStore from "./datastore";
import PublicServers from "./publicservers";
import SettingsPanel from "./settingspanel";
function Core() {
}
Core.prototype.setConfig = function(config) {
Object.assign(Config, config);
};
Core.prototype.init = async function() {
if (Config.version < Config.minSupportedVersion) {
this.alert("Not Supported", "BetterDiscord v" + Config.version + " (your version)" + " is not supported by the latest js (" + Config.bbdVersion + ").
Please download the latest version from GitHub");
return;
}
const latestLocalVersion = Config.updater ? Config.updater.LatestVersion : Config.latestVersion;
if (latestLocalVersion > Config.version) {
this.alert("Update Available", `
An update for BandagedBD is available (${latestLocalVersion})! Please Reinstall!
Download Installer
`);
}
Utilties.log("Startup", "Initializing Settings");
this.initSettings();
Utilties.log("Startup", "Initializing EmoteModule");
window.emotePromise = EmoteModule.init().then(() => {
EmoteModule.initialized = true;
Utilties.log("Startup", "Initializing QuickEmoteMenu");
QuickEmoteMenu.init();
});
this.injectExternals();
await this.checkForGuilds();
BDV2.initialize();
Utilties.log("Startup", "Updating Settings");
SettingsPanel.initializeSettings();
Utilties.log("Startup", "Loading Plugins");
const pluginErrors = PluginManager.loadPlugins();
Utilties.log("Startup", "Loading Themes");
const themeErrors = ThemeManager.loadThemes();
$("#customcss").detach().appendTo(document.head);
window.addEventListener("beforeunload", function() {
if (SettingsCookie["bda-dc-0"]) document.querySelector(".btn.btn-disconnect").click();
});
PublicServers.initialize();
EmoteModule.autoCapitalize();
Utilties.log("Startup", "Removing Loading Icon");
document.getElementsByClassName("bd-loaderv2")[0].remove();
Utilties.log("Startup", "Initializing Main Observer");
this.initObserver();
// Show loading errors
if (SettingsCookie["fork-ps-1"]) {
Utilties.log("Startup", "Collecting Startup Errors");
this.showContentErrors({plugins: pluginErrors, themes: themeErrors});
}
// if (!DataStore.getBDData(bbdVersion)) {
// BdApi.alert("BBD Updated!", ["Lots of things were fixed in this update like Public Servers, Minimal Mode, Dark Mode and 24 Hour Timestamps.", BdApi.React.createElement("br"), BdApi.React.createElement("br"), "Feel free to test them all out!"]);
// DataStore.setBDData(bbdVersion, true);
// }
};
Core.prototype.checkForGuilds = function() {
return new Promise(resolve => {
const checkForGuilds = function() {
const wrapper = BDV2.guildClasses.wrapper.split(" ")[0];
const guild = BDV2.guildClasses.listItem.split(" ")[0];
const blob = BDV2.guildClasses.blobContainer.split(" ")[0];
if (document.querySelectorAll(`.${wrapper} .${guild} .${blob}`).length > 0) return resolve(Config.deferLoaded = true);
setTimeout(checkForGuilds, 100);
};
$(document).ready(function () {
setTimeout(checkForGuilds, 100);
});
});
};
Core.prototype.injectExternals = async function() {
await Utilties.injectJs("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js");
if (window.__non_webpack_require__.original) window.require = window.require.original;
};
Core.prototype.initSettings = function () {
DataStore.initialize();
if (!DataStore.getSettingGroup("settings")) return this.saveSettings();
const savedSettings = this.loadSettings();
$("