some prep for api
This commit is contained in:
parent
f6c6e03564
commit
5576d2c150
12
js/main.js
12
js/main.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
70
src/bdApi.js
70
src/bdApi.js
|
@ -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 mainCore from "./core";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
import BDV2 from "./v2";
|
import BDV2 from "./v2";
|
||||||
import DataStore from "./dataStore";
|
import DataStore from "./dataStore";
|
||||||
|
import pluginModule from "./pluginModule";
|
||||||
|
import themeModule from "./themeModule";
|
||||||
|
import settingsPanel from "./settingsPanel";
|
||||||
|
|
||||||
const BdApi = {
|
const BdApi = {
|
||||||
get React() { return BDV2.react; },
|
get React() { return BDV2.React; },
|
||||||
get ReactDOM() { return BDV2.reactDom; },
|
get ReactDOM() { return BDV2.ReactDom; },
|
||||||
|
get ReactComponent() {return BDV2.ReactComponent;},
|
||||||
get WindowConfigFile() {
|
get WindowConfigFile() {
|
||||||
if (this._windowConfigFile) return this._windowConfigFile;
|
if (this._windowConfigFile) return this._windowConfigFile;
|
||||||
const electron = require("electron").remote.app;
|
const electron = require("electron").remote.app;
|
||||||
|
@ -19,7 +23,11 @@ const BdApi = {
|
||||||
const realLocation = fs.existsSync(location) ? location : fs.existsSync(roamingLocation) ? roamingLocation : null;
|
const realLocation = fs.existsSync(location) ? location : fs.existsSync(roamingLocation) ? roamingLocation : null;
|
||||||
if (!realLocation) return this._windowConfigFile = null;
|
if (!realLocation) return this._windowConfigFile = null;
|
||||||
return this._windowConfigFile = realLocation;
|
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() {
|
BdApi.getAllWindowPreferences = function() {
|
||||||
|
@ -221,6 +229,18 @@ BdApi.isSettingEnabled = function(id) {
|
||||||
return !!settingsCookie[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
|
// Gets data
|
||||||
BdApi.getBDData = function(key) {
|
BdApi.getBDData = function(key) {
|
||||||
return DataStore.getBDData(key);
|
return DataStore.getBDData(key);
|
||||||
|
@ -231,4 +251,46 @@ BdApi.setBDData = function(key, data) {
|
||||||
return DataStore.setBDData(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;
|
export default BdApi;
|
|
@ -43,10 +43,6 @@ deprecateGlobal("ContentManager", ContentManager);
|
||||||
deprecateGlobal("ClassNormalizer", ClassNormalizer);
|
deprecateGlobal("ClassNormalizer", ClassNormalizer);
|
||||||
|
|
||||||
window.BdApi = BdApi;
|
window.BdApi = BdApi;
|
||||||
// DataStore
|
|
||||||
// emoteModule
|
|
||||||
// ContentManager
|
|
||||||
// ClassNormalizer
|
|
||||||
|
|
||||||
import Core from "./core";
|
import Core from "./core";
|
||||||
export default class CoreWrapper {
|
export default class CoreWrapper {
|
||||||
|
|
|
@ -78,6 +78,10 @@ PluginModule.prototype.enablePlugin = function (plugin, reload = false) {
|
||||||
this.startPlugin(plugin, reload);
|
this.startPlugin(plugin, reload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PluginModule.prototype.enable = function (plugin, reload = false) {
|
||||||
|
return this.enablePlugin(plugin, reload);
|
||||||
|
};
|
||||||
|
|
||||||
PluginModule.prototype.disablePlugin = function (plugin, reload = false) {
|
PluginModule.prototype.disablePlugin = function (plugin, reload = false) {
|
||||||
if (!pluginCookie[plugin]) return;
|
if (!pluginCookie[plugin]) return;
|
||||||
pluginCookie[plugin] = false;
|
pluginCookie[plugin] = false;
|
||||||
|
@ -85,6 +89,10 @@ PluginModule.prototype.disablePlugin = function (plugin, reload = false) {
|
||||||
this.stopPlugin(plugin, reload);
|
this.stopPlugin(plugin, reload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PluginModule.prototype.disable = function (plugin, reload = false) {
|
||||||
|
return this.disablePlugin(plugin, reload);
|
||||||
|
};
|
||||||
|
|
||||||
PluginModule.prototype.togglePlugin = function (plugin) {
|
PluginModule.prototype.togglePlugin = function (plugin) {
|
||||||
if (pluginCookie[plugin]) this.disablePlugin(plugin);
|
if (pluginCookie[plugin]) this.disablePlugin(plugin);
|
||||||
else this.enablePlugin(plugin);
|
else this.enablePlugin(plugin);
|
||||||
|
|
|
@ -5,6 +5,8 @@ export default class V2C_ContentColumn extends BDV2.reactComponent {
|
||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get displayName() {return "ContentColumn";}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return BDV2.react.createElement(
|
return BDV2.react.createElement(
|
||||||
"div",
|
"div",
|
||||||
|
|
|
@ -126,8 +126,14 @@ export default new class V2_SettingsPanel {
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const configPath = path.join(DiscordNative.process.remote.resourcesPath, "app", "betterdiscord", "config.json");
|
const configPath = path.join(DiscordNative.process.remote.resourcesPath, "app", "betterdiscord", "config.json");
|
||||||
const config = __non_webpack_require__(configPath);
|
const config = __non_webpack_require__(configPath);
|
||||||
if (enabled) config.branch = "modularize";
|
if (enabled) {
|
||||||
else config.branch = "master";
|
config.branch = "modularize";
|
||||||
|
config.minified = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
config.branch = "master";
|
||||||
|
config.minified = true;
|
||||||
|
}
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 4));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 4));
|
||||||
}
|
}
|
||||||
catch (err) {console.error(err);}
|
catch (err) {console.error(err);}
|
||||||
|
|
|
@ -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.`);
|
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) {
|
ThemeModule.prototype.disableTheme = function(name, reload = false) {
|
||||||
themeCookie[name] = false;
|
themeCookie[name] = false;
|
||||||
this.saveThemeData();
|
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.`);
|
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) {
|
ThemeModule.prototype.toggleTheme = function(theme) {
|
||||||
if (themeCookie[theme]) this.disableTheme(theme);
|
if (themeCookie[theme]) this.disableTheme(theme);
|
||||||
else this.enableTheme(theme);
|
else this.enableTheme(theme);
|
||||||
|
|
Loading…
Reference in New Issue