-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathPluginBootstrap.ts
More file actions
117 lines (106 loc) · 4.22 KB
/
PluginBootstrap.ts
File metadata and controls
117 lines (106 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { AppScreenService, SkipNavService } from '@cloudbeaver/core-app';
import { ActionSnackbar, importLazyComponent } from '@cloudbeaver/core-blocks';
import { LocalStorageSaveService } from '@cloudbeaver/core-browser';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { CommonDialogService } from '@cloudbeaver/core-dialogs';
import { ENotificationType, type INotification, NotificationService } from '@cloudbeaver/core-events';
import { ScreenService } from '@cloudbeaver/core-routing';
import { ActionService, menuExtractItems, MenuService } from '@cloudbeaver/core-view';
import { MENU_APP_STATE } from '@cloudbeaver/plugin-top-app-bar';
import { NavigationTabsService } from '@cloudbeaver/plugin-navigation-tabs';
import { ACTION_APP_HELP } from './actions/ACTION_APP_HELP.js';
const SkipNavShortcutsLink = importLazyComponent(() => import('./SkipNavShortcutsLink.js').then(m => m.SkipNavShortcutsLink));
const ShortcutsDialog = importLazyComponent(() => import('./Shortcuts/ShortcutsDialog.js').then(m => m.ShortcutsDialog));
const WelcomeDocs = importLazyComponent(() => import('./WelcomeDocs.js').then(m => m.WelcomeDocs));
@injectable(() => [
MenuService,
ScreenService,
ActionService,
CommonDialogService,
NotificationService,
LocalStorageSaveService,
NavigationTabsService,
SkipNavService,
])
export class PluginBootstrap extends Bootstrap {
private errorNotification: INotification<any> | null;
constructor(
private readonly menuService: MenuService,
private readonly screenService: ScreenService,
private readonly actionService: ActionService,
private readonly commonDialogService: CommonDialogService,
private readonly notificationService: NotificationService,
private readonly localStorageSaveService: LocalStorageSaveService,
private readonly navigationTabsService: NavigationTabsService,
private readonly skipNavService: SkipNavService,
) {
super();
this.errorNotification = null;
}
override async load(): Promise<void> {}
override register(): void {
this.navigationTabsService.welcomeContainer.add(WelcomeDocs, undefined);
this.addTopAppMenuItems();
this.addMultiTabSupportNotification();
this.skipNavService.extraLinks.add(SkipNavShortcutsLink);
}
private addMultiTabSupportNotification() {
const displayErrorMessage = () => {
if (this.errorNotification) {
return;
}
if (this.screenService.isActive(AppScreenService.screenName) && this.localStorageSaveService.storage === 'session') {
this.errorNotification = this.notificationService.customNotification(
() => ActionSnackbar,
{
actionText: 'plugin_help_multi_tab_support_load_settings',
onAction: () => {
this.localStorageSaveService.updateStorage('local');
this.errorNotification?.close(false);
},
},
{
type: ENotificationType.Error,
title: 'plugin_help_multi_tab_support_title',
message: 'plugin_help_multi_tab_support_description',
onClose: () => {
this.errorNotification = null;
},
},
);
}
};
this.localStorageSaveService.onStorageChange.addHandler(displayErrorMessage);
this.screenService.routeChange.addPostHandler(displayErrorMessage);
}
private addTopAppMenuItems() {
this.menuService.addCreator({
menus: [MENU_APP_STATE],
getItems: (context, items) => [...items, ACTION_APP_HELP],
orderItems: (context, items) => {
const extracted = menuExtractItems(items, [ACTION_APP_HELP]);
items.splice(items.length - 1, 0, ...extracted);
return items;
},
});
this.actionService.addHandler({
id: 'app-help',
actions: [ACTION_APP_HELP],
handler: async (context, action) => {
switch (action) {
case ACTION_APP_HELP: {
await this.commonDialogService.open(ShortcutsDialog, undefined);
break;
}
}
},
});
}
}