35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import * as electronRemote from '@electron/remote';
|
|
const electronConsole = electronRemote.getGlobal('console') as Console;
|
|
import Logger from '../../../logger/logger';
|
|
const LOG = Logger.create(__filename, electronConsole);
|
|
|
|
import BaseElements from './require/base-elements.js';
|
|
|
|
import Q from '../q-module';
|
|
import UI from '../ui';
|
|
import GuildsManager from '../guilds-manager';
|
|
import CombinedGuild from '../guild-combined';
|
|
|
|
export default function createServerContextMenu(document: Document, q: Q, ui: UI, guildsManager: GuildsManager, guild: CombinedGuild) {
|
|
let element = BaseElements.createContextMenu(document, {
|
|
class: 'server-context', content: [
|
|
{ class: 'item red leave-server', content: 'Leave Server' }
|
|
]
|
|
});
|
|
|
|
q.$$$(element, '.leave-server').addEventListener('click', async () => {
|
|
element.removeSelf();
|
|
guild.disconnect();
|
|
await guildsManager.removeServer(guild);
|
|
await ui.removeGuild(guild);
|
|
let firstServerElement = q.$_('#server-list .server');
|
|
if (firstServerElement) {
|
|
firstServerElement.click();
|
|
} else {
|
|
LOG.warn('no first server element to click on');
|
|
}
|
|
});
|
|
|
|
return element;
|
|
}
|