2019-06-27 06:21:51 +02:00
import LocaleManager from "./localemanager" ;
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-06-23 06:11:50 +02:00
import Modals from "../ui/modals" ;
2019-06-22 06:37:19 +02:00
import ReactComponents from "./reactcomponents" ;
2019-06-23 06:11:50 +02:00
import DataStore from "./datastore" ;
import DiscordModules from "./discordmodules" ;
2019-06-27 06:21:51 +02:00
import ComponentPatcher from "./componentpatcher" ;
2019-06-23 06:11:50 +02:00
const GuildClasses = DiscordModules . GuildClasses ;
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-06-23 06:11:50 +02:00
// const latestLocalVersion = Config.updater ? Config.updater.LatestVersion : Config.latestVersion;
// if (latestLocalVersion > Config.version) {
// Modals.alert("Update Available", `
// An update for BandagedBD is available (${latestLocalVersion})! Please Reinstall!<br /><br />
// <a href='https://github.com/rauenzi/BetterDiscordApp/releases/latest' target='_blank'>Download Installer</a>
// `);
// }
2019-06-27 06:21:51 +02:00
DataStore . initialize ( ) ;
await LocaleManager . initialize ( ) ;
2019-05-28 20:19:48 +02:00
2019-06-19 21:24:05 +02:00
Logger . log ( "Startup" , "Initializing Settings" ) ;
2019-06-06 21:57:25 +02:00
Settings . initialize ( ) ;
2019-05-28 20:19:48 +02:00
2019-06-19 05:09:49 +02:00
DOMManager . initialize ( ) ;
2019-06-23 06:11:50 +02:00
await this . waitForGuilds ( ) ;
2019-06-27 06:21:51 +02:00
ReactComponents . initialize ( ) ;
2019-06-24 21:47:24 +02:00
ComponentPatcher . initialize ( ) ;
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-24 21:47:24 +02:00
const pluginErrors = PluginManager . initialize ( ) ;
2019-05-28 20:19:48 +02:00
2019-06-19 21:24:05 +02:00
Logger . log ( "Startup" , "Loading Themes" ) ;
2019-06-24 21:47:24 +02:00
const themeErrors = ThemeManager . initialize ( ) ;
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 ( ) ;
// 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
} ;
2019-06-23 06:11:50 +02:00
Core . prototype . waitForGuilds = function ( ) {
2019-05-28 20:19:48 +02:00
return new Promise ( resolve => {
const checkForGuilds = function ( ) {
2019-06-19 21:24:05 +02:00
if ( document . readyState != "complete" ) setTimeout ( checkForGuilds , 100 ) ;
2019-06-23 06:11:50 +02:00
const wrapper = GuildClasses . wrapper . split ( " " ) [ 0 ] ;
const guild = GuildClasses . listItem . split ( " " ) [ 0 ] ;
const blob = 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
} ) ;
} ;
2019-05-29 05:48:41 +02:00
export default new Core ( ) ;