@@ -7,19 +7,27 @@ const store = require('./main');
7
7
const bubble = new store ( ) ;
8
8
const fetchData = require ( '../core/utils/fetch' ) ;
9
9
10
- const pluginStore = document . querySelector ( '.extended-store-list .extended-info' ) ;
10
+ const pluginStore = document . querySelector (
11
+ '.extended-store-list .extended-info' ,
12
+ ) ;
11
13
12
14
class PluginList {
13
15
constructor ( ) {
14
- this . enablePluginList = JSON . parse ( localStorage . getItem ( 'enabled-plugins' ) ) || [ ] ;
16
+ this . enablePluginList
17
+ = JSON . parse ( localStorage . getItem ( 'enabled-plugins' ) ) || [ ] ;
15
18
this . pluginList = JSON . parse ( localStorage . getItem ( 'plugin-list' ) ) || [ ] ;
16
- this . loadedPlugins = JSON . parse ( localStorage . getItem ( 'loaded-plugins' ) ) || [ ] ;
19
+ this . loadedPlugins
20
+ = JSON . parse ( localStorage . getItem ( 'loaded-plugins' ) ) || [ ] ;
17
21
this . extendedInfo = document . querySelector ( '.extended-info' ) ;
18
22
this . extendedConfirmWrapper = document . querySelector ( '.confirm-wrapper' ) ;
19
- this . ConfirmSure = this . extendedConfirmWrapper . querySelector ( '.confirm-sure' ) ;
20
- this . ConfirmTitle = this . extendedConfirmWrapper . querySelector ( '.confirm-title' ) ;
23
+ this . ConfirmSure
24
+ = this . extendedConfirmWrapper . querySelector ( '.confirm-sure' ) ;
25
+ this . ConfirmTitle
26
+ = this . extendedConfirmWrapper . querySelector ( '.confirm-title' ) ;
21
27
this . extendedTopButton = document . querySelectorAll ( '.extended-list-button' ) ;
22
- this . extendedWrapper = document . querySelectorAll ( '.extended .setting-option' ) ;
28
+ this . extendedWrapper = document . querySelectorAll (
29
+ '.extended .setting-option' ,
30
+ ) ;
23
31
this . storeData = [ ] ;
24
32
this . lastState = null ;
25
33
this . lastTarget = null ;
@@ -56,7 +64,10 @@ class PluginList {
56
64
this . storeData = JSON . parse ( localStorage . getItem ( 'store-data' ) ?? '[]' ) ;
57
65
58
66
if ( Date . now ( ) - last_time > 600000 ) {
59
- const ans = await fetchData ( 'https://raw.githubusercontent.com/ExpTechTW/trem-plugins/refs/heads/main/data/repository_stats.json' , TREM . constant . HTTP_TIMEOUT . PLUGIN_INFO ) ;
67
+ const ans = await fetchData (
68
+ 'https://raw.githubusercontent.com/ExpTechTW/trem-plugins/refs/heads/main/data/repository_stats.json' ,
69
+ TREM . constant . HTTP_TIMEOUT . PLUGIN_INFO ,
70
+ ) ;
60
71
if ( ans && ans . ok ) {
61
72
const res = await ans . json ( ) ;
62
73
@@ -68,21 +79,74 @@ class PluginList {
68
79
}
69
80
70
81
this . createPluginStoreList ( ) ;
82
+ this . getPluginState ( ) ;
83
+ }
84
+
85
+ getPluginState ( ) {
86
+ let a = '' ;
87
+ const list = [
88
+ {
89
+ type : 'error' ,
90
+ plugin : 'websocket' ,
91
+ msg : '缺少 logger 依賴' ,
92
+ } ,
93
+ {
94
+ type : 'info' ,
95
+ plugin : 'config' ,
96
+ msg : '缺少 logger 依賴' ,
97
+ } ,
98
+ {
99
+ type : 'warn' ,
100
+ plugin : 'websocket' ,
101
+ msg : '缺少 logger 依賴' ,
102
+ } ,
103
+ {
104
+ type : 'debug' ,
105
+ plugin : 'websocket' ,
106
+ msg : '缺少 logger 依賴' ,
107
+ } ,
108
+ ] ;
109
+ list . forEach ( ( item ) => {
110
+ a += `<div class="wave-container wave-unloaded">
111
+ <div class="setting-option">
112
+ <div class="extended-list" style="justify-content: space-between;">
113
+ <div class="extended-list-box" style="width:95%">
114
+ <div class="extended-list-left">
115
+ <div class="extended-list-title-box">
116
+ <span class="plugin-list-title">${ item . plugin } </span>
117
+ </div>
118
+ </div>
119
+ <div class="extended-list-description-box">
120
+ <span class="extended-list-descriptions">${ item . msg } </span>
121
+ </div>
122
+ </div>
123
+ </div>
124
+ </div>
125
+ </div>` ;
126
+ } ) ;
127
+ document . querySelector ( '.extended-state-list .extended-info' ) . innerHTML = a ;
71
128
}
72
129
73
130
createPluginStoreList ( ) {
74
131
this . storeData . forEach ( ( item ) => {
75
132
if ( item . repository . releases . releases . length ) {
76
133
let button = '' ;
77
134
78
- const new_version = item . repository . releases . releases [ 0 ] . tag_name . replace ( 'v' , '' ) ;
135
+ const new_version
136
+ = item . repository . releases . releases [ 0 ] . tag_name . replace ( 'v' , '' ) ;
79
137
item . version = new_version ;
80
138
const local_item = this . pluginList . find ( ( _ ) => _ . name == item . name ) ;
81
139
82
140
if ( ! local_item ) {
83
141
button = 'download' ;
84
142
}
85
- else if ( new_version != local_item . version && PluginLoader . getInstance ( ) . compareVersions ( new_version , local_item . version ) ) {
143
+ else if (
144
+ new_version != local_item . version
145
+ && PluginLoader . getInstance ( ) . compareVersions (
146
+ new_version ,
147
+ local_item . version ,
148
+ )
149
+ ) {
86
150
button = 'update' ;
87
151
}
88
152
else {
@@ -103,7 +167,10 @@ class PluginList {
103
167
e . target . classList . add ( 'disabled' ) ;
104
168
e . target . classList . add ( 'downloading' ) ;
105
169
if ( new_item ) {
106
- await PluginLoader . getInstance ( ) . downloadPlugin ( pluginName , `https://github.com/${ new_item . repository . full_name } /releases/download/${ new_item . repository . releases . releases [ 0 ] . tag_name } /${ pluginName } .trem` ) ;
170
+ await PluginLoader . getInstance ( ) . downloadPlugin (
171
+ pluginName ,
172
+ `https://github.com/${ new_item . repository . full_name } /releases/download/${ new_item . repository . releases . releases [ 0 ] . tag_name } /${ pluginName } .trem` ,
173
+ ) ;
107
174
}
108
175
e . target . classList . add ( 'downloaded' ) ;
109
176
bubble . showBubble ( 'success-download' , 1500 ) ;
@@ -185,12 +252,17 @@ class PluginList {
185
252
renderStatusBadges ( item , isEnabled , isLoaded ) {
186
253
const badges = [ ] ;
187
254
188
- badges . push ( ! item . verified ? '<span class="unverified-badge"></span>' : '<span class="verified-badge"></span>' ) ;
255
+ badges . push (
256
+ ! item . verified
257
+ ? '<span class="unverified-badge"></span>'
258
+ : '<span class="verified-badge"></span>' ,
259
+ ) ;
189
260
190
261
if ( isEnabled ) {
191
- badges . push ( isLoaded
192
- ? '<span class="loaded-badge"></span>'
193
- : '<span class="unloaded-badge"></span>' ,
262
+ badges . push (
263
+ isLoaded
264
+ ? '<span class="loaded-badge"></span>'
265
+ : '<span class="unloaded-badge"></span>' ,
194
266
) ;
195
267
}
196
268
@@ -200,34 +272,49 @@ class PluginList {
200
272
renderPluginItem ( item , type , btn ) {
201
273
const isEnabled = ! type ? this . enablePluginList . includes ( item . name ) : '' ;
202
274
const isLoaded = ! type ? this . getPluginLoadStatus ( item . name ) : '' ;
203
- const waveClassName = ! type ? this . getWaveClassName ( item , isEnabled , isLoaded ) : '' ;
204
- const statusBadges = ! type ? this . renderStatusBadges ( item , isEnabled , isLoaded ) : '' ;
275
+ const waveClassName = ! type
276
+ ? this . getWaveClassName ( item , isEnabled , isLoaded )
277
+ : '' ;
278
+ const statusBadges = ! type
279
+ ? this . renderStatusBadges ( item , isEnabled , isLoaded )
280
+ : '' ;
205
281
206
282
const is_config_exist = fs . existsSync ( `${ item . path } /config.yml` ) ;
207
283
208
284
return `
209
- <div class="wave-container ${ waveClassName } " id="plugin-${ this . escapeHtml ( item . name ) } ">
285
+ <div class="wave-container ${ waveClassName } " id="plugin-${ this . escapeHtml (
286
+ item . name ,
287
+ ) } ">
210
288
<div class="setting-option">
211
289
<div class="extended-list">
212
290
<div class="extended-list-box">
213
291
<div class="extended-list-left">
214
292
<div class="extended-list-title-box">
215
- <span class="plugin-list-title">${ this . escapeHtml ( item . name ) } </span>
293
+ <span class="plugin-list-title">${ this . escapeHtml (
294
+ item . name ,
295
+ ) } </span>
216
296
<div class="status-box">${ statusBadges } </div>
217
297
</div>
218
298
<div class="extended-list-author-version">
219
299
<div class="author">
220
- <span class="author-name">${ this . escapeHtml ( item . author [ 0 ] ) } </span>
221
- <span class="extended-version">${ this . escapeHtml ( item . version ) } </span>
300
+ <span class="author-name">${ this . escapeHtml (
301
+ item . author [ 0 ] ,
302
+ ) } </span>
303
+ <span class="extended-version">${ this . escapeHtml (
304
+ item . version ,
305
+ ) } </span>
222
306
</div>
223
307
</div>
224
308
</div>
225
309
<div class="extended-list-description-box">
226
- <span class="extended-list-descriptions">${ this . escapeHtml ( item . description ?. zh_tw || '' ) } </span>
310
+ <span class="extended-list-descriptions">${ this . escapeHtml (
311
+ item . description ?. zh_tw || '' ,
312
+ ) } </span>
227
313
</div>
228
314
</div>
229
- ${ ! type
230
- ? `<div class="extended-list-buttons">
315
+ ${
316
+ ! type
317
+ ? `<div class="extended-list-buttons">
231
318
<label class="switch">
232
319
<input type="checkbox"
233
320
data-name="${ this . escapeHtml ( item . name ) } "
@@ -238,8 +325,16 @@ class PluginList {
238
325
${ isEnabled ? 'checked' : '' } >
239
326
<div class="slider round"></div>
240
327
</label>
241
- ${ is_config_exist ? `<div id="extended-setting-button.${ this . escapeHtml ( item . name ) } " class="extended-setting-button"></div>` : '' }
242
- <div id="extended-remove.${ this . escapeHtml ( item . name ) } " class="extended-remove">
328
+ ${
329
+ is_config_exist
330
+ ? `<div id="extended-setting-button.${ this . escapeHtml (
331
+ item . name ,
332
+ ) } " class="extended-setting-button"></div>`
333
+ : ''
334
+ }
335
+ <div id="extended-remove.${ this . escapeHtml (
336
+ item . name ,
337
+ ) } " class="extended-remove">
243
338
<svg fill="currentColor" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 27.965 27.965" xml:space="preserve" height="15px" width="15px">
244
339
<g>
245
340
<g id="c142_x">
@@ -254,9 +349,12 @@ class PluginList {
254
349
</svg>
255
350
</div>
256
351
</div>`
257
- : `<div class="extended-list-buttons">
258
- <div id="extended-download-button.${ this . escapeHtml ( item . name ) } " class="extended-${ btn } -button"></div>
259
- </div>` }
352
+ : `<div class="extended-list-buttons">
353
+ <div id="extended-download-button.${ this . escapeHtml (
354
+ item . name ,
355
+ ) } " class="extended-${ btn } -button"></div>
356
+ </div>`
357
+ }
260
358
</div>
261
359
</div>
262
360
</div>
@@ -278,11 +376,14 @@ class PluginList {
278
376
return ;
279
377
}
280
378
281
- const settingButton = document . getElementById ( `extended-setting-button.${ item . name } ` ) ;
379
+ const settingButton = document . getElementById (
380
+ `extended-setting-button.${ item . name } ` ,
381
+ ) ;
282
382
if ( settingButton ) {
283
383
settingButton . replaceWith ( settingButton . cloneNode ( true ) ) ;
284
384
285
- document . getElementById ( `extended-setting-button.${ item . name } ` )
385
+ document
386
+ . getElementById ( `extended-setting-button.${ item . name } ` )
286
387
. addEventListener ( 'click' , ( ) => {
287
388
ipcRenderer . send ( 'open-yaml-editor' , `${ item . path } /config.yml` ) ;
288
389
} ) ;
@@ -371,15 +472,20 @@ class PluginList {
371
472
372
473
if ( isEnabled ) {
373
474
manager . disable ( pluginName ) ;
374
- this . enablePluginList = this . enablePluginList . filter ( ( name ) => name !== pluginName ) ;
475
+ this . enablePluginList = this . enablePluginList . filter (
476
+ ( name ) => name !== pluginName ,
477
+ ) ;
375
478
}
376
479
else {
377
480
manager . enable ( pluginName ) ;
378
481
if ( ! this . enablePluginList . includes ( pluginName ) ) {
379
482
this . enablePluginList . push ( pluginName ) ;
380
483
}
381
484
}
382
- localStorage . setItem ( 'enabled-plugins' , JSON . stringify ( this . enablePluginList ) ) ;
485
+ localStorage . setItem (
486
+ 'enabled-plugins' ,
487
+ JSON . stringify ( this . enablePluginList ) ,
488
+ ) ;
383
489
this . hideConfirmWrapper ( ) ;
384
490
bubble . showBubble ( 'success' , 1500 ) ;
385
491
}
0 commit comments