diff --git a/client/src/ui/bdui.js b/client/src/ui/bdui.js index e00a3192..658019f6 100644 --- a/client/src/ui/bdui.js +++ b/client/src/ui/bdui.js @@ -24,25 +24,21 @@ export default class { channel: DiscordApi.currentChannel }; - const ehookInterval = setInterval(() => { - if (!remote.BrowserWindow.getFocusedWindow()) return; - clearInterval(ehookInterval); - remote.BrowserWindow.getFocusedWindow().webContents.on('did-navigate-in-page', (e, url, isMainFrame) => { - const { currentGuild, currentChannel } = DiscordApi; + remote.getCurrentWindow().webContents.on('did-navigate-in-page', (e, url, isMainFrame) => { + const { currentGuild, currentChannel } = DiscordApi; - if (!this.pathCache.server) - Events.emit('server-switch', { server: currentGuild, channel: currentChannel }); - else if (!this.pathCache.channel) - Events.emit('channel-switch', currentChannel); - else if (currentGuild && currentGuild.id && this.pathCache.server && this.pathCache.server.id !== currentGuild.id) - Events.emit('server-switch', { server: currentGuild, channel: currentChannel }); - else if (currentChannel && currentChannel.id && this.pathCache.channel && this.pathCache.channel.id !== currentChannel.id) - Events.emit('channel-switch', currentChannel); + if (!this.pathCache.server) + Events.emit('server-switch', { server: currentGuild, channel: currentChannel }); + else if (!this.pathCache.channel) + Events.emit('channel-switch', currentChannel); + else if (currentGuild && currentGuild.id && this.pathCache.server && this.pathCache.server.id !== currentGuild.id) + Events.emit('server-switch', { server: currentGuild, channel: currentChannel }); + else if (currentChannel && currentChannel.id && this.pathCache.channel && this.pathCache.channel.id !== currentChannel.id) + Events.emit('channel-switch', currentChannel); - this.pathCache.server = currentGuild; - this.pathCache.channel = currentChannel; - }); - }, 100); + this.pathCache.server = currentGuild; + this.pathCache.channel = currentChannel; + }); } static injectUi() { diff --git a/client/src/ui/components/BdSettings.vue b/client/src/ui/components/BdSettings.vue index 8c9c1794..1c190585 100644 --- a/client/src/ui/components/BdSettings.vue +++ b/client/src/ui/components/BdSettings.vue @@ -75,7 +75,8 @@ first: true, Settings, timeout: null, - SettingsWrapper + SettingsWrapper, + openMenuHandler: null }; }, props: ['active'], @@ -154,7 +155,10 @@ } }, 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)); + Events.on('bd-open-menu', this.openMenuHandler = item => item && this.itemOnClick(this.sidebarItems.find(i => i === item || i.id === item || i.contentid === item || i.set === item).id)); + }, + destroyed() { + if (this.openMenuHandler) Events.off('bd-open-menu', this.openMenuHandler); } } diff --git a/client/src/ui/components/BdSettingsWrapper.vue b/client/src/ui/components/BdSettingsWrapper.vue index 98b94c10..196639a4 100644 --- a/client/src/ui/components/BdSettingsWrapper.vue +++ b/client/src/ui/components/BdSettingsWrapper.vue @@ -34,7 +34,9 @@ active: false, animating: false, timeout: null, - platform: process.platform + platform: process.platform, + eventHandlers: {}, + keybindHandler: null }; }, components: { @@ -66,21 +68,29 @@ } }, 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); + Events.on('ready', this.eventHandlers.ready = e => this.loaded = true); + Events.on('bd-open-menu', this.eventHandlers['bd-open-menu'] = item => this.active = true); + Events.on('bd-close-menu', this.eventHandlers['bd-close-menu'] = () => this.active = false); + Events.on('update-check-start', this.eventHandlers['update-check-start'] = e => this.updating = 0); + Events.on('update-check-end', this.eventHandlers['update-check-end'] = e => this.updating = 1); + Events.on('updates-available', this.eventHandlers['updates-available'] = e => this.updating = 2); + window.addEventListener('keyup', this.keyupListener); window.addEventListener('keydown', this.prevent, true); const menuKeybind = Settings.getSetting('core', 'default', 'menu-keybind'); - menuKeybind.on('keybind-activated', () => this.active = !this.active); + menuKeybind.on('keybind-activated', this.keybindHandler = () => this.active = !this.active); }, destroyed() { + for (let event in this.eventHandlers) Events.off(event, this.eventHandlers[event]); + window.removeEventListener('keyup', this.keyupListener); window.removeEventListener('keydown', this.prevent); + + if (this.keybindHandler) { + const menuKeybind = Settings.getSetting('core', 'default', 'menu-keybind'); + menuKeybind.removeListener('keybind-activated', this.keybindHandler = () => this.active = !this.active); + } } } diff --git a/client/src/ui/components/bd/internal-settings/WindowPreferences.vue b/client/src/ui/components/bd/internal-settings/WindowPreferences.vue index 51336f9c..9330eac0 100644 --- a/client/src/ui/components/bd/internal-settings/WindowPreferences.vue +++ b/client/src/ui/components/bd/internal-settings/WindowPreferences.vue @@ -17,7 +17,7 @@
You must fully restart Discord for changes here to take effect.