1
1
import { ChangeDetectorRef , Component } from '@angular/core' ;
2
2
import { Event , NavigationStart , Router } from '@angular/router' ;
3
+ import { NgbModal , NgbModalRef } from '@ng-bootstrap/ng-bootstrap' ;
3
4
import { I18n } from '@ngx-translate/i18n-polyfill' ;
4
5
import { Messages } from './messages/messages' ;
5
6
import { SettingsService } from '../services/settings/settings-service' ;
@@ -10,6 +11,9 @@ import { UtilTranslations } from '../util/util-translations';
10
11
import { AppController } from '../services/app-controller' ;
11
12
import { ImageUrlMaker } from '../services/imagestore/image-url-maker' ;
12
13
import { ConfigurationChangeNotifications } from './configuration/notifications/configuration-change-notifications' ;
14
+ import { UpdateUsernameModalComponent } from './settings/update-username-modal.component' ;
15
+ import { MenuContext } from '../services/menu-context' ;
16
+ import { Menus } from '../services/menus' ;
13
17
14
18
const remote = typeof window !== 'undefined' ? window . require ( '@electron/remote' ) : undefined ;
15
19
const ipcRenderer = typeof window !== 'undefined' ? window . require ( 'electron' ) . ipcRenderer : undefined ;
@@ -34,6 +38,8 @@ export class AppComponent {
34
38
configurationChangeNotifications : ConfigurationChangeNotifications ,
35
39
imageUrlMaker : ImageUrlMaker ,
36
40
settingsService : SettingsService ,
41
+ private menus : Menus ,
42
+ private modalService : NgbModal ,
37
43
private messages : Messages ,
38
44
private i18n : I18n ,
39
45
private utilTranslations : UtilTranslations ,
@@ -61,6 +67,10 @@ export class AppComponent {
61
67
AppComponent . preventDefaultDragAndDropBehavior ( ) ;
62
68
this . initializeUtilTranslations ( ) ;
63
69
this . listenToSettingsChangesFromMenu ( ) ;
70
+
71
+ if ( ! Settings . hasUsername ( settingsProvider . getSettings ( ) ) ) {
72
+ this . openUpdateUsernameModal ( true ) ;
73
+ }
64
74
}
65
75
66
76
@@ -131,4 +141,27 @@ export class AppComponent {
131
141
document . addEventListener ( 'dragover' , event => event . preventDefault ( ) ) ;
132
142
document . addEventListener ( 'drop' , event => event . preventDefault ( ) ) ;
133
143
}
144
+
145
+
146
+ public async openUpdateUsernameModal ( welcomeMode : boolean = false ) {
147
+
148
+ const menuContext : MenuContext = this . menus . getContext ( ) ;
149
+ this . menus . setContext (
150
+ menuContext === MenuContext . CONFIGURATION
151
+ ? MenuContext . CONFIGURATION_MODAL
152
+ : MenuContext . MODAL
153
+ ) ;
154
+
155
+ try {
156
+ const modalRef : NgbModalRef = this . modalService . open (
157
+ UpdateUsernameModalComponent , { animation : false , backdrop : 'static' , keyboard : false }
158
+ ) ;
159
+ modalRef . componentInstance . welcomeMode = welcomeMode ;
160
+ await modalRef . result ;
161
+ } catch ( _ ) {
162
+ // Modal has been canceled
163
+ } finally {
164
+ this . menus . setContext ( menuContext ) ;
165
+ }
166
+ }
134
167
}
0 commit comments