BetterDiscordApp-v2/client/src/ui/bdui.js

89 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-01-29 18:56:48 +01:00
/**
* BetterDiscord Client UI Module
* 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.
* 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.
*/
import { Events, DiscordApi, Settings } from 'modules';
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-08-21 23:23:08 +02:00
import { BdSettingsWrapper, BdModals, BdToasts, BdNotifications, BdContextMenu } from './components';
2018-01-29 18:56:48 +01:00
export default class {
2018-01-31 16:45:25 +01:00
static initUiEvents() {
2018-08-15 05:41:44 +02:00
document.body.classList.add('bd-v2');
const hideButtonSetting = Settings.getSetting('ui', 'default', 'hide-button');
hideButtonSetting.on('setting-updated', event => {
2018-08-15 04:03:56 +02:00
if (event.value) document.body.classList.add('bd-hideButton');
else document.body.classList.remove('bd-hideButton');
});
2018-08-15 04:03:56 +02:00
if (hideButtonSetting.value) document.body.classList.add('bd-hideButton');
const currentWindow = remote.getCurrentWindow();
const windowOptions = currentWindow.__bd_options;
if (!windowOptions.hasOwnProperty('frame') || windowOptions.frame) document.body.classList.add('bd-windowHasFrame');
if (windowOptions.transparent) document.body.classList.add('bd-windowIsTransparent');
2018-03-08 22:40:38 +01:00
this.pathCache = {
isDm: null,
server: DiscordApi.currentGuild,
channel: DiscordApi.currentChannel
2018-03-08 22:40:38 +01:00
};
2018-04-01 23:44:01 +02:00
currentWindow.webContents.on('did-navigate-in-page', (e, url, isMainFrame) => {
const { currentGuild, currentChannel } = DiscordApi;
2018-04-01 23:44:01 +02:00
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);
2018-03-08 22:40:38 +01:00
this.pathCache.server = currentGuild;
this.pathCache.channel = currentChannel;
});
2018-01-31 16:45:25 +01:00
}
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);
DOM.createElement('div', null, 'bd-toasts').appendTo(DOM.bdToasts);
DOM.createElement('div', null, 'bd-notifications').appendTo(DOM.bdNotifications);
2018-08-21 23:23:08 +02:00
DOM.createElement('div', null, 'bd-contextmenu').appendTo(DOM.bdContextMenu);
DOM.createElement('bd-tooltips').appendTo(DOM.bdBody);
2018-05-13 05:17:04 +02:00
this.toasts = new (Vue.extend(BdToasts))({
el: '#bd-toasts'
2018-05-13 05:17:04 +02:00
});
2018-02-07 12:52:59 +01:00
this.modals = new (Vue.extend(BdModals))({
el: '#bd-modals'
2018-02-07 12:52:59 +01:00
});
this.vueInstance = new (Vue.extend(BdSettingsWrapper))({
el: '#bd-settings'
2018-01-29 18:56:48 +01:00
});
2018-01-29 19:00:31 +01:00
this.notifications = new (Vue.extend(BdNotifications))({
el: '#bd-notifications'
});
2018-08-21 23:23:08 +02:00
this.contextmenu = new (Vue.extend(BdContextMenu))({
el: '#bd-contextmenu'
});
return this.vueInstance;
2018-01-29 18:56:48 +01:00
}
}