1
- import { html , nothing , render , svg } from 'lit-html' ;
1
+ import { html , nothing , render , svg , SVGTemplateResult , TemplateResult } from 'lit-html' ;
2
2
import { browser } from 'webextension-polyfill-ts' ;
3
3
4
4
import { background } from '../background' ;
@@ -30,9 +30,11 @@ interface PopupState {
30
30
31
31
class Popup {
32
32
constructor ( ) {
33
- window . addEventListener ( 'click' , ( ev ) => this . openLink ( ev ) ) ;
33
+ window . addEventListener ( 'click' , ( ev ) => {
34
+ this . openLink ( ev ) . catch ( logger . error ) ;
35
+ } ) ;
34
36
this . _update ( ) ;
35
- this . getVersion ( ) . catch ( logger . error ) ;
37
+ this . getVersion ( ) ;
36
38
this . checkVersion ( ) . catch ( logger . error ) ;
37
39
this . loadConfig ( ) . catch ( logger . error ) ;
38
40
browser . management
@@ -41,8 +43,10 @@ class Popup {
41
43
this . state . extensionVersion = `${ data . version } ` ;
42
44
} )
43
45
. catch ( logger . error ) ;
44
- const downloadStatusSub = background . updater . downloadStatus . subscribe ( ( data ) => this . downloadStatus ( data ) ) ;
45
- window . addEventListener ( 'unload' , ( _ ) => {
46
+ const downloadStatusSub = background . updater . downloadStatus . subscribe ( ( data ) => {
47
+ this . downloadStatus ( data ) . catch ( logger . error ) ;
48
+ } ) ;
49
+ window . addEventListener ( 'unload' , ( ) => {
46
50
downloadStatusSub . unsubscribe ( ) ;
47
51
} ) ;
48
52
}
@@ -86,12 +90,12 @@ class Popup {
86
90
[ 0 , 0 ] ,
87
91
] ;
88
92
89
- async loadConfig ( ) {
93
+ async loadConfig ( ) : Promise < void > {
90
94
this . configOriginal = await config . get ( ) ;
91
95
this . state . configValue = { ...this . configOriginal } ;
92
96
}
93
97
94
- testAnimation ( ) {
98
+ testAnimation ( ) : void {
95
99
const a = this . testAnimationList [ this . testAnimationIndex ] ;
96
100
this . testAnimationIndex ++ ;
97
101
if ( ! this . testAnimationList [ this . testAnimationIndex ] ) {
@@ -101,7 +105,7 @@ class Popup {
101
105
this . state . progress = a [ 1 ] ;
102
106
}
103
107
104
- async getVersion ( ) {
108
+ getVersion ( ) : void {
105
109
const sha = background . tagDatabase . sha . value ;
106
110
const releaseLink = background . tagDatabase . releaseLink . value ;
107
111
const updateTime = background . tagDatabase . updateTime . value ;
@@ -111,7 +115,7 @@ class Popup {
111
115
this . state . updateTimeFull = updateTime ?. toLocaleString ( ) ?? 'N/A' ;
112
116
}
113
117
114
- async checkVersion ( ) {
118
+ async checkVersion ( ) : Promise < void > {
115
119
this . state . versionInfo = '检查中...' ;
116
120
const data = await background . updater . checkVersion ( ) ;
117
121
logger . log ( 'Release Data' , data ) ;
@@ -150,7 +154,7 @@ class Popup {
150
154
this . state . progress = 100 ;
151
155
this . state . animationState = 2 ;
152
156
this . state . updateButtonDisabled = false ;
153
- await this . getVersion ( ) ;
157
+ this . getVersion ( ) ;
154
158
await this . checkVersion ( ) ;
155
159
156
160
await sleep ( 500 ) ;
@@ -161,12 +165,12 @@ class Popup {
161
165
}
162
166
}
163
167
164
- private updateButtonClick = async ( ) = > {
168
+ private async updateButtonClick ( ) : Promise < void > {
165
169
this . state . updateButtonDisabled = true ;
166
170
await background . updater . update ( ) ;
167
- } ;
171
+ }
168
172
169
- _logoTemplate ( progress = 0 ) {
173
+ _logoTemplate ( progress = 0 ) : SVGTemplateResult {
170
174
const PushRodStyle = `transform: translate(${ ( progress / 400 ) * 70 } px, 0)` ;
171
175
const EnemaStyle = `transform: scaleX(${ progress / 100 } )` ;
172
176
@@ -233,7 +237,7 @@ class Popup {
233
237
</ svg > ` ;
234
238
}
235
239
236
- changeConfigValue ( key : string , value : any ) {
240
+ changeConfigValue ( key : string , value : any ) : void {
237
241
if ( key === 'introduceImageLevel' ) {
238
242
this . state . configValue = {
239
243
...this . state . configValue ,
@@ -251,20 +255,20 @@ class Popup {
251
255
return ! keys . every ( ( key ) => ( this . configOriginal as any ) [ key ] === ( this . state . configValue as any ) [ key ] ) ;
252
256
}
253
257
254
- async saveConfig ( ) {
258
+ async saveConfig ( ) : Promise < void > {
255
259
await config . set ( this . state . configValue ) ;
256
260
await this . loadConfig ( ) ;
257
261
await sleep ( 200 ) ;
262
+ window . close ( ) ;
258
263
const tabs = await browser . tabs . query ( { active : true } ) ;
259
264
if ( tabs ?. length ) {
260
265
const ehtabs = tabs . filter ( ( v ) => v . url && / ( \/ \/ | \. ) ( e - | e x ) h e n t a i \. o r g / i. test ( v . url ) ) ;
261
266
logger . log ( 'Reload tabs' , ehtabs ) ;
262
- ehtabs . forEach ( ( v ) => browser . tabs . reload ( v . id ) . catch ( logger . error ) ) ;
267
+ await Promise . all ( ehtabs . map ( ( v ) => browser . tabs . reload ( v . id ) ) ) ;
263
268
}
264
- window . close ( ) ;
265
269
}
266
270
267
- _settingPanelTemplate ( ) {
271
+ _settingPanelTemplate ( ) : TemplateResult {
268
272
const state = this . state ;
269
273
270
274
const checkboxList : Array < { key : string ; name : string } > = [
@@ -355,7 +359,7 @@ class Popup {
355
359
` ;
356
360
}
357
361
358
- _template ( ) {
362
+ _template ( ) : TemplateResult {
359
363
const state = this . state ;
360
364
return html ` < div class ="popup-root ${ state . showSettingPanel ? 'hide' : '' } ">
361
365
< div class ="head-buttons ">
@@ -428,7 +432,7 @@ class Popup {
428
432
${ state . configValue ? this . _settingPanelTemplate ( ) : nothing } ` ;
429
433
}
430
434
431
- _update ( ) {
435
+ _update ( ) : void {
432
436
render ( this . _template ( ) , document . body ) ;
433
437
}
434
438
}
0 commit comments