1
- import { store } from "../extensionPreferences"
1
+ import { store } from "../extensionPreferences" ;
2
2
export class OLFeature {
3
3
moduleName = "unset" ;
4
4
moduleId = "unset" ;
@@ -33,28 +33,39 @@ export class SettingButton extends SettingOption {
33
33
export class SettingToggle extends SettingOption {
34
34
settingId : string ;
35
35
callback : ( newState : boolean ) => void ;
36
- constructor ( title : string , description : string , settingId : string , callback : ( newState : boolean ) => void ) {
36
+ constructor (
37
+ title : string ,
38
+ description : string ,
39
+ settingId : string ,
40
+ callback : ( newState : boolean ) => void
41
+ ) {
37
42
super ( title , description ) ;
38
43
this . settingId = settingId ;
39
44
this . callback = callback ;
40
45
this . element . classList . add ( "ol-setting-toggle" ) ;
41
46
this . element . innerHTML = `<span class="ol-set-inner"><p class="ol-set-title">${ title } </p><p class="ol-set-desc">${ description } </p></span><input type="checkbox" id="${ settingId } " class="ol-setting-toggle-checkbox">` ;
42
- this . element . addEventListener ( "click" , async ( ) => await this . toggleSetting ( ) ) ;
43
- this . loadPD ( )
47
+ this . element . addEventListener (
48
+ "click" ,
49
+ async ( ) => await this . toggleSetting ( )
50
+ ) ;
51
+ this . loadPD ( ) ;
52
+ }
53
+ async getValue ( ) : Promise < boolean > {
54
+ const prefData = await store . get ( this . settingId ) ;
55
+ return ! ! prefData ;
44
56
}
45
57
async loadPD ( ) {
46
- const prefData = await store . get ( this . settingId )
47
- const value = ! ! prefData
58
+ const value = await this . getValue ( ) ;
48
59
this . element . querySelector ( "input" ) ! . checked = value ;
49
60
this . callback ( value ) ;
50
61
}
51
62
async toggleSetting ( ) {
52
- const prefData = await store . get ( this . settingId )
53
- const old_value = prefData
54
- const new_value = ! old_value
63
+ const prefData = await store . get ( this . settingId ) ;
64
+ const old_value = prefData ;
65
+ const new_value = ! old_value ;
55
66
await store . set ( this . settingId , new_value ) ;
56
67
console . log ( "updating" , this . settingId , old_value , new_value ) ;
57
68
this . element . querySelector ( "input" ) ! . checked = ! old_value ;
58
- this . callback ( new_value )
69
+ this . callback ( new_value ) ;
59
70
}
60
- }
71
+ }
0 commit comments