@@ -18,8 +18,31 @@ type MessageApi = ReturnType<typeof useMessage>;
18
18
const renderButton = ( label : string , props : ButtonProps ) => ( ) => h ( NButton , { tertiary : true , type : 'info' , ...props } , { default : ( ) => label } ) ;
19
19
20
20
export class NotificationService {
21
- static notification : NotificationApi ;
22
- static message : MessageApi ;
21
+ static _notification ?: NotificationApi ;
22
+ static _message ?: MessageApi ;
23
+
24
+ static get notification ( ) : NotificationApi {
25
+ if ( ! this . _notification ) throw new Error ( 'NotificationService not initialized' ) ;
26
+ return this . _notification ;
27
+ }
28
+
29
+ static set notification ( value : NotificationApi ) {
30
+ this . _notification = value ;
31
+ }
32
+
33
+ static get message ( ) : MessageApi {
34
+ if ( ! this . _message ) throw new Error ( 'NotificationService not initialized' ) ;
35
+ return this . _message ;
36
+ }
37
+
38
+ static set message ( value : MessageApi ) {
39
+ this . _message = value ;
40
+ }
41
+
42
+ static destroy ( ) {
43
+ this . _notification = undefined ;
44
+ this . _message = undefined ;
45
+ }
23
46
24
47
static error ( title : string , error : Error | Response | unknown , duration = 5000 ) {
25
48
const option : Mutable < NotificationOptions > = {
@@ -40,7 +63,7 @@ export class NotificationService {
40
63
41
64
static release ( payload : MessagePayload < typeof MessageType . VersionUpdate > ) {
42
65
const i18n = useI18n ( 'notification' ) ;
43
- const notification = NotificationService . notification . info ( {
66
+ const notification = this . notification . info ( {
44
67
title : i18n ( 'release_title' ) ,
45
68
description : `From ${ payload . previousVersion } to ${ payload . nextVersion } ` ,
46
69
content : i18n ( 'release_content' ) ,
@@ -58,7 +81,7 @@ export class NotificationService {
58
81
59
82
static userMismatch ( { user, session } : { user : string ; session : string } ) {
60
83
const i18n = useI18n ( 'notification' ) ;
61
- const notification = NotificationService . notification . warning ( {
84
+ const notification = this . notification . warning ( {
62
85
title : 'Warning: user mismatch' ,
63
86
description : `Displaying ${ session } instead of ${ user } ` ,
64
87
content : 'Current user does not match the session. \nPlease log out and log in from trakt.tv.' ,
0 commit comments