2018-01-29 18:56:48 +01:00
|
|
|
/**
|
|
|
|
* BetterDiscord Client UI Module
|
2018-01-29 19:15:58 +01:00
|
|
|
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
2018-01-29 18:56:48 +01:00
|
|
|
* All rights reserved.
|
2018-01-29 19:15:58 +01:00
|
|
|
* https://betterdiscord.net
|
2018-01-29 18:56:48 +01:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
2018-03-21 00:24:31 +01:00
|
|
|
import { Events, WebpackModules, DiscordApi } from 'modules';
|
|
|
|
import { Utils } from 'common';
|
|
|
|
import { remote } from 'electron';
|
2018-01-31 16:47:47 +01:00
|
|
|
import DOM from './dom';
|
2018-01-31 16:45:25 +01:00
|
|
|
import Vue from './vue';
|
2018-03-08 09:40:29 +01:00
|
|
|
import AutoManip from './automanip';
|
2018-03-21 00:24:31 +01:00
|
|
|
import { BdSettingsWrapper, BdModals } from './components';
|
2018-01-29 18:56:48 +01:00
|
|
|
|
|
|
|
export default class {
|
2018-01-31 16:45:25 +01:00
|
|
|
|
|
|
|
static initUiEvents() {
|
2018-03-08 22:40:38 +01:00
|
|
|
this.pathCache = {
|
|
|
|
isDm: null,
|
2018-03-21 00:24:31 +01:00
|
|
|
server: DiscordApi.currentGuild,
|
|
|
|
channel: DiscordApi.currentChannel
|
2018-03-08 22:40:38 +01:00
|
|
|
};
|
2018-03-10 04:29:04 +01:00
|
|
|
window.addEventListener('keyup', e => Events.emit('gkh:keyup', e));
|
2018-03-08 09:40:29 +01:00
|
|
|
this.autoManip = new AutoManip();
|
2018-01-31 16:45:25 +01:00
|
|
|
const defer = setInterval(() => {
|
|
|
|
if (!this.profilePopupModule) return;
|
|
|
|
clearInterval(defer);
|
2018-03-04 21:21:18 +01:00
|
|
|
|
2018-03-12 16:36:11 +01:00
|
|
|
/*Utils.monkeyPatch(this.profilePopupModule, 'open', 'after', (data, userid) => Events.emit('ui-event', {
|
2018-03-04 21:21:18 +01:00
|
|
|
event: 'profile-popup-open',
|
|
|
|
data: { userid }
|
2018-03-12 16:36:11 +01:00
|
|
|
}));*/
|
2018-01-31 16:45:25 +01:00
|
|
|
}, 100);
|
2018-03-08 22:40:38 +01:00
|
|
|
|
|
|
|
const ehookInterval = setInterval(() => {
|
|
|
|
if (!remote.BrowserWindow.getFocusedWindow()) return;
|
|
|
|
clearInterval(ehookInterval);
|
|
|
|
remote.BrowserWindow.getFocusedWindow().webContents.on('did-navigate-in-page', (e, url, isMainFrame) => {
|
2018-03-21 00:24:31 +01:00
|
|
|
const { currentGuild, currentChannel } = DiscordApi;
|
2018-03-08 22:40:38 +01:00
|
|
|
if (!this.pathCache.server) {
|
2018-03-21 00:24:31 +01:00
|
|
|
Events.emit('server-switch', { server: currentGuild, channel: currentChannel });
|
2018-03-08 22:40:38 +01:00
|
|
|
this.pathCache.server = currentGuild;
|
|
|
|
this.pathCache.channel = currentChannel;
|
2018-03-07 00:37:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-08 22:40:38 +01:00
|
|
|
if (!this.pathCache.channel) {
|
|
|
|
Events.emit('channel-switch', currentChannel);
|
|
|
|
this.pathCache.server = currentGuild;
|
|
|
|
this.pathCache.channel = currentChannel;
|
|
|
|
return;
|
2018-03-07 00:37:14 +01:00
|
|
|
}
|
2018-03-08 22:40:38 +01:00
|
|
|
if (currentGuild &&
|
|
|
|
currentGuild.id &&
|
|
|
|
this.pathCache.server &&
|
|
|
|
this.pathCache.server.id !== currentGuild.id) {
|
2018-03-21 00:24:31 +01:00
|
|
|
Events.emit('server-switch', { server: currentGuild, channel: currentChannel });
|
2018-03-08 22:40:38 +01:00
|
|
|
this.pathCache.server = currentGuild;
|
|
|
|
this.pathCache.channel = currentChannel;
|
|
|
|
return;
|
2018-03-07 00:37:14 +01:00
|
|
|
}
|
2018-03-08 22:40:38 +01:00
|
|
|
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;
|
|
|
|
});
|
2018-03-07 00:37:14 +01:00
|
|
|
}, 100);
|
2018-01-31 16:45:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static get profilePopupModule() {
|
|
|
|
return WebpackModules.getModuleByProps(['fetchMutualFriends', 'setSection']);
|
|
|
|
}
|
|
|
|
|
2018-01-29 18:56:48 +01:00
|
|
|
static injectUi() {
|
2018-01-31 16:47:47 +01:00
|
|
|
DOM.createElement('div', null, 'bd-settings').appendTo(DOM.bdBody);
|
2018-02-07 12:52:59 +01:00
|
|
|
DOM.createElement('div', null, 'bd-modals').appendTo(DOM.bdModals);
|
2018-02-13 18:09:50 +01:00
|
|
|
DOM.createElement('bd-tooltips').appendTo(DOM.bdBody);
|
2018-02-07 12:52:59 +01:00
|
|
|
|
2018-03-21 00:24:31 +01:00
|
|
|
this.modals = new Vue({
|
2018-02-07 12:52:59 +01:00
|
|
|
el: '#bd-modals',
|
|
|
|
components: { BdModals },
|
2018-03-21 00:24:31 +01:00
|
|
|
template: '<BdModals />'
|
2018-02-07 12:52:59 +01:00
|
|
|
});
|
|
|
|
|
2018-03-21 00:24:31 +01:00
|
|
|
this.vueInstance = new Vue({
|
2018-01-29 18:56:48 +01:00
|
|
|
el: '#bd-settings',
|
|
|
|
components: { BdSettingsWrapper },
|
2018-03-21 00:24:31 +01:00
|
|
|
template: '<BdSettingsWrapper />'
|
2018-01-29 18:56:48 +01:00
|
|
|
});
|
2018-01-29 19:00:31 +01:00
|
|
|
|
2018-03-21 00:24:31 +01:00
|
|
|
return this.vueInstance;
|
2018-01-29 18:56:48 +01:00
|
|
|
}
|
2018-03-07 21:19:02 +01:00
|
|
|
|
2018-01-29 19:15:58 +01:00
|
|
|
}
|