2019-05-28 23:27:25 +02:00
import BDV2 from "./bdv2" ;
2019-05-30 23:18:52 +02:00
import Utilities from "./utilities" ;
2019-05-29 05:48:41 +02:00
import { Config , SettingsCookie } from "data" ;
2019-05-28 23:27:25 +02:00
import EmoteModule from "./emotes" ;
2019-05-31 07:53:11 +02:00
// import QuickEmoteMenu from "../builtins/emotemenu";
2019-05-29 05:48:41 +02:00
import PluginManager from "./pluginmanager" ;
import ThemeManager from "./thememanager" ;
import SettingsPanel from "./settingspanel" ;
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" ;
import Events from "./emitter" ;
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-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Initializing Settings" ) ;
2019-05-31 07:53:11 +02:00
SettingsPanel . initialize ( ) ;
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Initializing EmoteModule" ) ;
2019-05-29 05:48:41 +02:00
window . emotePromise = EmoteModule . init ( ) . then ( ( ) => {
EmoteModule . initialized = true ;
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Initializing QuickEmoteMenu" ) ;
2019-05-31 07:53:11 +02:00
Events . dispatch ( "emotes-loaded" ) ;
// QuickEmoteMenu.init();
2019-05-28 20:19:48 +02:00
} ) ;
this . injectExternals ( ) ;
await this . checkForGuilds ( ) ;
BDV2 . initialize ( ) ;
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Updating Settings" ) ;
2019-05-29 05:48:41 +02:00
SettingsPanel . initializeSettings ( ) ;
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-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Loading Plugins" ) ;
2019-05-29 05:48:41 +02:00
const pluginErrors = PluginManager . loadPlugins ( ) ;
2019-05-28 20:19:48 +02:00
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Loading Themes" ) ;
2019-05-29 05:48:41 +02:00
const themeErrors = ThemeManager . loadThemes ( ) ;
2019-05-28 20:19:48 +02:00
$ ( "#customcss" ) . detach ( ) . appendTo ( document . head ) ;
2019-05-30 23:18:52 +02:00
// PublicServers.initialize();
2019-05-29 05:48:41 +02:00
EmoteModule . autoCapitalize ( ) ;
2019-05-28 20:19:48 +02:00
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Removing Loading Icon" ) ;
2019-05-28 20:19:48 +02:00
document . getElementsByClassName ( "bd-loaderv2" ) [ 0 ] . remove ( ) ;
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Initializing Main Observer" ) ;
2019-05-28 20:19:48 +02:00
this . initObserver ( ) ;
// Show loading errors
2019-05-29 05:48:41 +02:00
if ( SettingsCookie [ "fork-ps-1" ] ) {
2019-05-30 23:18:52 +02:00
Utilities . log ( "Startup" , "Collecting Startup Errors" ) ;
2019-05-31 07:53:11 +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 ( ) {
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 ) ;
} ;
$ ( document ) . ready ( function ( ) {
setTimeout ( checkForGuilds , 100 ) ;
} ) ;
} ) ;
} ;
Core . prototype . injectExternals = async function ( ) {
2019-05-30 23:18:52 +02:00
await Utilities . injectJs ( "https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js" ) ;
2019-05-29 06:50:26 +02:00
if ( window . require . original ) window . require = window . require . original ;
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 ++ ) {
2019-05-29 06:29:15 +02:00
const mutation = mutations [ i ] ;
2019-05-29 05:48:41 +02:00
if ( typeof PluginManager !== "undefined" ) PluginManager . rawObserver ( mutation ) ;
2019-05-28 20:19:48 +02:00
// if there was nothing added, skip
if ( ! mutation . addedNodes . length || ! ( mutation . addedNodes [ 0 ] instanceof Element ) ) continue ;
2019-05-29 06:29:15 +02:00
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" ) ;
if ( node . getElementsByClassName ( "socialLinks-3jqNFy" ) . length ) {
node . setAttribute ( "layer-id" , "user-settings" ) ;
node . setAttribute ( "id" , "user-settings" ) ;
2019-05-29 05:48:41 +02:00
if ( ! document . getElementById ( "bd-settings-sidebar" ) ) SettingsPanel . renderSidebar ( ) ;
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 ( ) ;