|
|
|
@ -20,26 +20,26 @@ export default class Dashboard extends Builtin {
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
*/
|
|
|
|
|
async start () {
|
|
|
|
|
this.injectStyles('styles/main.scss');
|
|
|
|
|
super.injectStyles('styles/main.scss');
|
|
|
|
|
this._injectPrivateTab();
|
|
|
|
|
// this.injectGuildHomeButton();
|
|
|
|
|
|
|
|
|
|
vizality.api.routes.registerRoute({
|
|
|
|
|
$vz.api.routes.registerRoute({
|
|
|
|
|
id: 'dashboard',
|
|
|
|
|
path: '',
|
|
|
|
|
render: Routes
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
vizality.api.actions.registerAction('VIZALITY_CLOSE_DASHBOARD', this._leaveDashboard.bind(this));
|
|
|
|
|
vizality.api.actions.registerAction('VIZALITY_TOGGLE_DASHBOARD', this._toggleDashboard.bind(this));
|
|
|
|
|
$vz.api.actions.registerAction('VIZALITY_CLOSE_DASHBOARD', this._leaveDashboard.bind(this));
|
|
|
|
|
$vz.api.actions.registerAction('VIZALITY_TOGGLE_DASHBOARD', this._toggleDashboard.bind(this));
|
|
|
|
|
|
|
|
|
|
vizality.api.keybinds.registerKeybind({
|
|
|
|
|
$vz.api.keybinds.registerKeybind({
|
|
|
|
|
id: 'VIZALITY_CLOSE_DASHBOARD',
|
|
|
|
|
shortcut: 'esc',
|
|
|
|
|
executor: this._leaveDashboard.bind(this)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
vizality.api.keybinds.registerKeybind({
|
|
|
|
|
$vz.api.keybinds.registerKeybind({
|
|
|
|
|
id: 'VIZALITY_TOGGLE_DASHBOARD',
|
|
|
|
|
shortcut: 'alt+v',
|
|
|
|
|
executor: this._toggleDashboard.bind(this)
|
|
|
|
@ -51,11 +51,11 @@ export default class Dashboard extends Builtin {
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
*/
|
|
|
|
|
async stop () {
|
|
|
|
|
vizality.api.routes.unregisterRoute('dashboard');
|
|
|
|
|
vizality.api.actions.unregisterAction('VIZALITY_CLOSE_DASHBOARD');
|
|
|
|
|
vizality.api.actions.unregisterAction('VIZALITY_TOGGLE_DASHBOARD');
|
|
|
|
|
vizality.api.keybinds.unregisterKeybind('VIZALITY_CLOSE_DASHBOARD');
|
|
|
|
|
vizality.api.keybinds.unregisterKeybind('VIZALITY_TOGGLE_DASHBOARD');
|
|
|
|
|
$vz.api.routes.unregisterRoute('dashboard');
|
|
|
|
|
$vz.api.actions.unregisterAction('VIZALITY_CLOSE_DASHBOARD');
|
|
|
|
|
$vz.api.actions.unregisterAction('VIZALITY_TOGGLE_DASHBOARD');
|
|
|
|
|
$vz.api.keybinds.unregisterKeybind('VIZALITY_CLOSE_DASHBOARD');
|
|
|
|
|
$vz.api.keybinds.unregisterKeybind('VIZALITY_TOGGLE_DASHBOARD');
|
|
|
|
|
unpatch('vz-dashboard-private-channels-list-item');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -65,7 +65,7 @@ export default class Dashboard extends Builtin {
|
|
|
|
|
*/
|
|
|
|
|
_leaveDashboard () {
|
|
|
|
|
try {
|
|
|
|
|
return vizality.api.routes.restorePreviousRoute();
|
|
|
|
|
return $vz.api.routes.restorePreviousRoute();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return this.error(this._labels.concat('_leaveDashboard'), err);
|
|
|
|
|
}
|
|
|
|
@ -78,11 +78,11 @@ export default class Dashboard extends Builtin {
|
|
|
|
|
*/
|
|
|
|
|
_toggleDashboard () {
|
|
|
|
|
try {
|
|
|
|
|
const currentRoute = vizality.api.routes.getLocation();
|
|
|
|
|
const currentRoute = $vz.api.routes.getLocation();
|
|
|
|
|
if (currentRoute?.pathname?.startsWith('/vizality')) {
|
|
|
|
|
return this._leaveDashboard();
|
|
|
|
|
}
|
|
|
|
|
return vizality.api.routes.navigateTo('dashboard');
|
|
|
|
|
return $vz.api.routes.navigateTo('dashboard');
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return this.error(this._labels.concat('_toggleDashboard'), err);
|
|
|
|
|
}
|
|
|
|
@ -91,7 +91,6 @@ export default class Dashboard extends Builtin {
|
|
|
|
|
/**
|
|
|
|
|
* Patches the private channels list to add a button just above the Friends button
|
|
|
|
|
* that takes you to the Vizality dashboard.
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
_injectPrivateTab () {
|
|
|
|
|
try {
|
|
|
|
@ -100,19 +99,30 @@ export default class Dashboard extends Builtin {
|
|
|
|
|
const { LinkButton } = getModule('LinkButton');
|
|
|
|
|
patch('vz-dashboard-private-channels-list-item', ConnectedPrivateChannelsList, 'default', (_, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const { children: list } = findInReactTree(res, (c) => c.channels);
|
|
|
|
|
|
|
|
|
|
if (!list) return;
|
|
|
|
|
|
|
|
|
|
list.unshift(
|
|
|
|
|
<LinkButton
|
|
|
|
|
icon={() => <Icon name='vizality' />}
|
|
|
|
|
route='/vizality'
|
|
|
|
|
text='Dashboard'
|
|
|
|
|
selected={vizality.api.routes.getLocation()?.pathname?.startsWith('/vizality')}
|
|
|
|
|
onContextMenu={evt => openContextMenu(evt, () => <SettingsContextMenu />)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
const { children: PrivateChannelsList } = findInReactTree(res, props => props.channels);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make sure the PrivateChannelsList is found.
|
|
|
|
|
*/
|
|
|
|
|
if (!PrivateChannelsList) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make sure there's a Dashboard button in the PrivateChannelsList, otherwise
|
|
|
|
|
* prepend one.
|
|
|
|
|
*/
|
|
|
|
|
if (!PrivateChannelsList.some(channel => channel.props?.text === 'Dashboard')) {
|
|
|
|
|
PrivateChannelsList.unshift(
|
|
|
|
|
<LinkButton
|
|
|
|
|
icon={() => <Icon name='vizality' />}
|
|
|
|
|
route='/vizality'
|
|
|
|
|
text='Dashboard'
|
|
|
|
|
selected={$vz.api.routes.getLocation().pathname.startsWith('/vizality')}
|
|
|
|
|
onContextMenu={evt => openContextMenu(evt, () => <SettingsContextMenu />)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return this.error(this._labels.concat('_injectPrivateTab'), err);
|
|
|
|
|
}
|
|
|
|
|