some prep for api

This commit is contained in:
Zack Rauen 2020-03-14 19:47:37 -04:00
parent f6c6e03564
commit 5576d2c150
8 changed files with 99 additions and 17 deletions

File diff suppressed because one or more lines are too long

2
js/main.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,16 @@
import {pluginCookie, themeCookie, settingsCookie, bdplugins} from "./0globals";
import {pluginCookie, themeCookie, bdplugins, bdthemes, settingsCookie, settings, bdEmotes} from "./0globals";
import mainCore from "./core";
import Utils from "./utils";
import BDV2 from "./v2";
import DataStore from "./dataStore";
import pluginModule from "./pluginModule";
import themeModule from "./themeModule";
import settingsPanel from "./settingsPanel";
const BdApi = {
get React() { return BDV2.react; },
get ReactDOM() { return BDV2.reactDom; },
get React() { return BDV2.React; },
get ReactDOM() { return BDV2.ReactDom; },
get ReactComponent() {return BDV2.ReactComponent;},
get WindowConfigFile() {
if (this._windowConfigFile) return this._windowConfigFile;
const electron = require("electron").remote.app;
@ -19,7 +23,11 @@ const BdApi = {
const realLocation = fs.existsSync(location) ? location : fs.existsSync(roamingLocation) ? roamingLocation : null;
if (!realLocation) return this._windowConfigFile = null;
return this._windowConfigFile = realLocation;
}
},
get bdSettings() {return settings;},
get emotes() {return bdEmotes;},
get screenWidth() { return Math.max(document.documentElement.clientWidth, window.innerWidth || 0); },
get screenHeight() { return Math.max(document.documentElement.clientHeight, window.innerHeight || 0); }
};
BdApi.getAllWindowPreferences = function() {
@ -221,6 +229,18 @@ BdApi.isSettingEnabled = function(id) {
return !!settingsCookie[id];
};
BdApi.enableSetting = function(id) {
return settingsPanel.onChange(id, true);
};
BdApi.disableSetting = function(id) {
return settingsPanel.onChange(id, false);
};
BdApi.toggleSetting = function(id) {
return settingsPanel.onChange(id, !settingsCookie[id]);
};
// Gets data
BdApi.getBDData = function(key) {
return DataStore.getBDData(key);
@ -231,4 +251,46 @@ BdApi.setBDData = function(key, data) {
return DataStore.setBDData(key, data);
};
class AddonAPI {
constructor(cookie, list, manager) {
this.manager = manager;
this.cookie = cookie;
this.list = list;
}
isEnabled(name) {
return !!this.cookie[name];
}
enable(name) {
return this.manager.enable(name);
}
disable(name) {
return this.manager.disable(name);
}
toggle(name) {
if (this.cookie[name]) this.disable(name);
else this.enable(name);
}
get(name) {
if (this.list.hasOwnProperty(name)) {
if (this.list[name].plugin) return this.list[name].plugin;
return this.list[name];
}
return null;
}
getAll() {
return Object.keys(this.list).map(k => this.get(k)).filter(a => a);
}
}
BdApi.Plugins = new AddonAPI(pluginCookie, bdplugins, pluginModule);
BdApi.Themes = new AddonAPI(themeCookie, bdthemes, themeModule);
export default BdApi;

View File

@ -43,10 +43,6 @@ deprecateGlobal("ContentManager", ContentManager);
deprecateGlobal("ClassNormalizer", ClassNormalizer);
window.BdApi = BdApi;
// DataStore
// emoteModule
// ContentManager
// ClassNormalizer
import Core from "./core";
export default class CoreWrapper {

View File

@ -78,6 +78,10 @@ PluginModule.prototype.enablePlugin = function (plugin, reload = false) {
this.startPlugin(plugin, reload);
};
PluginModule.prototype.enable = function (plugin, reload = false) {
return this.enablePlugin(plugin, reload);
};
PluginModule.prototype.disablePlugin = function (plugin, reload = false) {
if (!pluginCookie[plugin]) return;
pluginCookie[plugin] = false;
@ -85,6 +89,10 @@ PluginModule.prototype.disablePlugin = function (plugin, reload = false) {
this.stopPlugin(plugin, reload);
};
PluginModule.prototype.disable = function (plugin, reload = false) {
return this.disablePlugin(plugin, reload);
};
PluginModule.prototype.togglePlugin = function (plugin) {
if (pluginCookie[plugin]) this.disablePlugin(plugin);
else this.enablePlugin(plugin);

View File

@ -5,6 +5,8 @@ export default class V2C_ContentColumn extends BDV2.reactComponent {
super(props);
}
static get displayName() {return "ContentColumn";}
render() {
return BDV2.react.createElement(
"div",

View File

@ -126,8 +126,14 @@ export default new class V2_SettingsPanel {
const path = require("path");
const configPath = path.join(DiscordNative.process.remote.resourcesPath, "app", "betterdiscord", "config.json");
const config = __non_webpack_require__(configPath);
if (enabled) config.branch = "modularize";
else config.branch = "master";
if (enabled) {
config.branch = "modularize";
config.minified = false;
}
else {
config.branch = "master";
config.minified = true;
}
fs.writeFileSync(configPath, JSON.stringify(config, null, 4));
}
catch (err) {console.error(err);}

View File

@ -33,6 +33,10 @@ ThemeModule.prototype.enableTheme = function(name, reload = false) {
if (settingsCookie["fork-ps-2"] && !reload) Utils.showToast(`${theme.name} v${theme.version} has been applied.`);
};
ThemeModule.prototype.enable = function (name, reload = false) {
return this.enableTheme(name, reload);
};
ThemeModule.prototype.disableTheme = function(name, reload = false) {
themeCookie[name] = false;
this.saveThemeData();
@ -41,6 +45,10 @@ ThemeModule.prototype.disableTheme = function(name, reload = false) {
if (settingsCookie["fork-ps-2"] && !reload) Utils.showToast(`${theme.name} v${theme.version} has been disabled.`);
};
ThemeModule.prototype.disable = function (name, reload = false) {
return this.disableTheme(name, reload);
};
ThemeModule.prototype.toggleTheme = function(theme) {
if (themeCookie[theme]) this.disableTheme(theme);
else this.enableTheme(theme);