Add menu API
This commit is contained in:
parent
d2cbbd309b
commit
f28525129e
|
@ -8,7 +8,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DOM, BdUI, Modals, Reflection } from 'ui';
|
import { DOM, BdUI, BdMenu, Modals, Reflection } from 'ui';
|
||||||
import BdCss from './styles/index.scss';
|
import BdCss from './styles/index.scss';
|
||||||
import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactAutoPatcher, DiscordApi } from 'modules';
|
import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactAutoPatcher, DiscordApi } from 'modules';
|
||||||
import { ClientLogger as Logger, ClientIPC, Utils } from 'common';
|
import { ClientLogger as Logger, ClientIPC, Utils } from 'common';
|
||||||
|
@ -26,7 +26,7 @@ class BetterDiscord {
|
||||||
Logger.log('main', 'BetterDiscord starting');
|
Logger.log('main', 'BetterDiscord starting');
|
||||||
|
|
||||||
this._bd = {
|
this._bd = {
|
||||||
DOM, BdUI, Modals, Reflection,
|
DOM, BdUI, BdMenu, Modals, Reflection,
|
||||||
|
|
||||||
Events, CssEditor, Globals, Settings, Database, Updater,
|
Events, CssEditor, Globals, Settings, Database, Updater,
|
||||||
ModuleManager, PluginManager, ThemeManager, ExtModuleManager,
|
ModuleManager, PluginManager, ThemeManager, ExtModuleManager,
|
||||||
|
|
|
@ -17,7 +17,7 @@ import Events from './events';
|
||||||
import EventsWrapper from './eventswrapper';
|
import EventsWrapper from './eventswrapper';
|
||||||
import { WebpackModules } from './webpackmodules';
|
import { WebpackModules } from './webpackmodules';
|
||||||
import { SettingsSet, SettingsCategory, Setting, SettingsScheme } from 'structs';
|
import { SettingsSet, SettingsCategory, Setting, SettingsScheme } from 'structs';
|
||||||
import { BdMenuItems, Modals, DOM, Reflection } from 'ui';
|
import { BdMenu, Modals, DOM, Reflection } from 'ui';
|
||||||
import DiscordApi from './discordapi';
|
import DiscordApi from './discordapi';
|
||||||
import { ReactComponents } from './reactcomponents';
|
import { ReactComponents } from './reactcomponents';
|
||||||
import { Patcher, MonkeyPatch } from './patcher';
|
import { Patcher, MonkeyPatch } from './patcher';
|
||||||
|
@ -137,6 +137,9 @@ export default class PluginApi {
|
||||||
|
|
||||||
get BdMenu() {
|
get BdMenu() {
|
||||||
return {
|
return {
|
||||||
|
open: BdMenu.open.bind(BdMenu),
|
||||||
|
close: BdMenu.close.bind(BdMenu),
|
||||||
|
items: this.BdMenuItems,
|
||||||
BdMenuItems: this.BdMenuItems
|
BdMenuItems: this.BdMenuItems
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -149,23 +152,23 @@ export default class PluginApi {
|
||||||
return this._menuItems || (this._menuItems = []);
|
return this._menuItems || (this._menuItems = []);
|
||||||
}
|
}
|
||||||
addMenuItem(item) {
|
addMenuItem(item) {
|
||||||
return BdMenuItems.add(item);
|
return BdMenu.items.add(item);
|
||||||
}
|
}
|
||||||
addMenuSettingsSet(category, set, text) {
|
addMenuSettingsSet(category, set, text) {
|
||||||
const item = BdMenuItems.addSettingsSet(category, set, text);
|
const item = BdMenu.items.addSettingsSet(category, set, text);
|
||||||
return this.menuItems.push(item);
|
return this.menuItems.push(item);
|
||||||
}
|
}
|
||||||
addMenuVueComponent(category, text, component) {
|
addMenuVueComponent(category, text, component) {
|
||||||
const item = BdMenuItems.addVueComponent(category, text, component);
|
const item = BdMenu.items.addVueComponent(category, text, component);
|
||||||
return this.menuItems.push(item);
|
return this.menuItems.push(item);
|
||||||
}
|
}
|
||||||
removeMenuItem(item) {
|
removeMenuItem(item) {
|
||||||
BdMenuItems.remove(item);
|
BdMenu.items.remove(item);
|
||||||
Utils.removeFromArray(this.menuItems, item);
|
Utils.removeFromArray(this.menuItems, item);
|
||||||
}
|
}
|
||||||
removeAllMenuItems() {
|
removeAllMenuItems() {
|
||||||
for (let item of this.menuItems)
|
for (let item of this.menuItems)
|
||||||
BdMenuItems.remove(item);
|
BdMenu.items.remove(item);
|
||||||
}
|
}
|
||||||
get BdMenuItems() {
|
get BdMenuItems() {
|
||||||
return Object.defineProperty({
|
return Object.defineProperty({
|
||||||
|
|
|
@ -11,10 +11,25 @@
|
||||||
import { Events } from 'modules';
|
import { Events } from 'modules';
|
||||||
import { Utils } from 'common';
|
import { Utils } from 'common';
|
||||||
|
|
||||||
|
export default new class {
|
||||||
|
|
||||||
|
open(item) {
|
||||||
|
Events.emit('bd-open-menu', item);
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
Events.emit('bd-close-menu');
|
||||||
|
}
|
||||||
|
|
||||||
|
get items() {
|
||||||
|
return BdMenuItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
let items = 0;
|
let items = 0;
|
||||||
|
|
||||||
export const BdMenuItems = new class {
|
export const BdMenuItems = new class {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
window.bdmenu = this;
|
window.bdmenu = this;
|
||||||
|
|
||||||
|
@ -85,5 +100,4 @@ export const BdMenuItems = new class {
|
||||||
remove(item) {
|
remove(item) {
|
||||||
Utils.removeFromArray(this.items, item);
|
Utils.removeFromArray(this.items, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Events, WebpackModules, DiscordApi } from 'modules';
|
import { Events, WebpackModules, DiscordApi, MonkeyPatch } from 'modules';
|
||||||
import { Utils } from 'common';
|
import { Utils } from 'common';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import DOM from './dom';
|
import DOM from './dom';
|
||||||
|
@ -30,10 +30,10 @@ export default class {
|
||||||
if (!this.profilePopupModule) return;
|
if (!this.profilePopupModule) return;
|
||||||
clearInterval(defer);
|
clearInterval(defer);
|
||||||
|
|
||||||
/*Utils.monkeyPatch(this.profilePopupModule, 'open', 'after', (data, userid) => Events.emit('ui-event', {
|
MonkeyPatch('BdUI', this.profilePopupModule).after('open', (context, [userid]) => Events.emit('ui-event', {
|
||||||
event: 'profile-popup-open',
|
event: 'profile-popup-open',
|
||||||
data: { userid }
|
data: { userid }
|
||||||
}));*/
|
}));
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
const ehookInterval = setInterval(() => {
|
const ehookInterval = setInterval(() => {
|
||||||
|
|
|
@ -58,9 +58,9 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Imports
|
// Imports
|
||||||
import { shell } from 'electron';
|
import { Events, Settings } from 'modules';
|
||||||
import { Settings } from 'modules';
|
|
||||||
import { BdMenuItems } from 'ui';
|
import { BdMenuItems } from 'ui';
|
||||||
|
import { shell } from 'electron';
|
||||||
import { SidebarView, Sidebar, SidebarItem, ContentColumn } from './sidebar';
|
import { SidebarView, Sidebar, SidebarItem, ContentColumn } from './sidebar';
|
||||||
import { SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView, UpdaterView } from './bd';
|
import { SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView, UpdaterView } from './bd';
|
||||||
import { SvgX, MiGithubCircle, MiWeb, MiClose, MiTwitterCircle } from './common';
|
import { SvgX, MiGithubCircle, MiWeb, MiClose, MiTwitterCircle } from './common';
|
||||||
|
@ -151,6 +151,9 @@
|
||||||
if (active) return;
|
if (active) return;
|
||||||
this.closeContent();
|
this.closeContent();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
Events.on('bd-open-menu', item => item && this.itemOnClick(this.sidebarItems.find(i => i === item || i.id === item || i.contentid === item || i.set === item).id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -62,6 +62,8 @@
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
Events.on('ready', e => this.loaded = true);
|
Events.on('ready', e => this.loaded = true);
|
||||||
|
Events.on('bd-open-menu', item => this.active = true);
|
||||||
|
Events.on('bd-close-menu', () => this.active = false);
|
||||||
Events.on('update-check-start', e => this.updating = 0);
|
Events.on('update-check-start', e => this.updating = 0);
|
||||||
Events.on('update-check-end', e => this.updating = 1);
|
Events.on('update-check-end', e => this.updating = 1);
|
||||||
Events.on('updates-available', e => this.updating = 2);
|
Events.on('updates-available', e => this.updating = 2);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
export { default as DOM } from './dom';
|
export { default as DOM } from './dom';
|
||||||
export { default as BdUI } from './bdui';
|
export { default as BdUI } from './bdui';
|
||||||
export { default as VueInjector } from './vueinjector';
|
export { default as VueInjector } from './vueinjector';
|
||||||
export * from './bdmenu';
|
export { default as BdMenu, BdMenuItems } from './bdmenu';
|
||||||
export { default as Modals } from './modals';
|
export { default as Modals } from './modals';
|
||||||
export { default as ProfileBadges } from './profilebadges';
|
export { default as ProfileBadges } from './profilebadges';
|
||||||
export { default as Reflection } from './reflection';
|
export { default as Reflection } from './reflection';
|
||||||
|
|
Loading…
Reference in New Issue