1- import { store } from "../extensionPreferences"
1+ import { store } from "../extensionPreferences" ;
22export class OLFeature {
33 moduleName = "unset" ;
44 moduleId = "unset" ;
@@ -33,28 +33,39 @@ export class SettingButton extends SettingOption {
3333export class SettingToggle extends SettingOption {
3434 settingId : string ;
3535 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+ ) {
3742 super ( title , description ) ;
3843 this . settingId = settingId ;
3944 this . callback = callback ;
4045 this . element . classList . add ( "ol-setting-toggle" ) ;
4146 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 ;
4456 }
4557 async loadPD ( ) {
46- const prefData = await store . get ( this . settingId )
47- const value = ! ! prefData
58+ const value = await this . getValue ( ) ;
4859 this . element . querySelector ( "input" ) ! . checked = value ;
4960 this . callback ( value ) ;
5061 }
5162 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 ;
5566 await store . set ( this . settingId , new_value ) ;
5667 console . log ( "updating" , this . settingId , old_value , new_value ) ;
5768 this . element . querySelector ( "input" ) ! . checked = ! old_value ;
58- this . callback ( new_value )
69+ this . callback ( new_value ) ;
5970 }
60- }
71+ }
0 commit comments