Add menu API

This commit is contained in:
Samuel Elliott 2018-03-31 01:03:13 +01:00
parent d2cbbd309b
commit f28525129e
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
7 changed files with 38 additions and 16 deletions

View File

@ -8,7 +8,7 @@
* 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 { 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';
@ -26,7 +26,7 @@ class BetterDiscord {
Logger.log('main', 'BetterDiscord starting');
this._bd = {
DOM, BdUI, Modals, Reflection,
DOM, BdUI, BdMenu, Modals, Reflection,
Events, CssEditor, Globals, Settings, Database, Updater,
ModuleManager, PluginManager, ThemeManager, ExtModuleManager,

View File

@ -17,7 +17,7 @@ import Events from './events';
import EventsWrapper from './eventswrapper';
import { WebpackModules } from './webpackmodules';
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 { ReactComponents } from './reactcomponents';
import { Patcher, MonkeyPatch } from './patcher';
@ -137,6 +137,9 @@ export default class PluginApi {
get BdMenu() {
return {
open: BdMenu.open.bind(BdMenu),
close: BdMenu.close.bind(BdMenu),
items: this.BdMenuItems,
BdMenuItems: this.BdMenuItems
};
}
@ -149,23 +152,23 @@ export default class PluginApi {
return this._menuItems || (this._menuItems = []);
}
addMenuItem(item) {
return BdMenuItems.add(item);
return BdMenu.items.add(item);
}
addMenuSettingsSet(category, set, text) {
const item = BdMenuItems.addSettingsSet(category, set, text);
const item = BdMenu.items.addSettingsSet(category, set, text);
return this.menuItems.push(item);
}
addMenuVueComponent(category, text, component) {
const item = BdMenuItems.addVueComponent(category, text, component);
const item = BdMenu.items.addVueComponent(category, text, component);
return this.menuItems.push(item);
}
removeMenuItem(item) {
BdMenuItems.remove(item);
BdMenu.items.remove(item);
Utils.removeFromArray(this.menuItems, item);
}
removeAllMenuItems() {
for (let item of this.menuItems)
BdMenuItems.remove(item);
BdMenu.items.remove(item);
}
get BdMenuItems() {
return Object.defineProperty({

View File

@ -11,10 +11,25 @@
import { Events } from 'modules';
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;
export const BdMenuItems = new class {
constructor() {
window.bdmenu = this;
@ -85,5 +100,4 @@ export const BdMenuItems = new class {
remove(item) {
Utils.removeFromArray(this.items, item);
}
};

View File

@ -8,7 +8,7 @@
* 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 { remote } from 'electron';
import DOM from './dom';
@ -30,10 +30,10 @@ export default class {
if (!this.profilePopupModule) return;
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',
data: { userid }
}));*/
}));
}, 100);
const ehookInterval = setInterval(() => {

View File

@ -58,9 +58,9 @@
<script>
// Imports
import { shell } from 'electron';
import { Settings } from 'modules';
import { Events, Settings } from 'modules';
import { BdMenuItems } from 'ui';
import { shell } from 'electron';
import { SidebarView, Sidebar, SidebarItem, ContentColumn } from './sidebar';
import { SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView, UpdaterView } from './bd';
import { SvgX, MiGithubCircle, MiWeb, MiClose, MiTwitterCircle } from './common';
@ -151,6 +151,9 @@
if (active) return;
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>

View File

@ -62,6 +62,8 @@
},
created() {
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-end', e => this.updating = 1);
Events.on('updates-available', e => this.updating = 2);

View File

@ -1,7 +1,7 @@
export { default as DOM } from './dom';
export { default as BdUI } from './bdui';
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 ProfileBadges } from './profilebadges';
export { default as Reflection } from './reflection';