@@ -2,44 +2,14 @@ import { $el } from "../ui";
22import { api } from "../api" ;
33import { ComfyDialog } from "./dialog" ;
44import type { ComfyApp } from "../app" ;
5-
6- /* The Setting entry stored in `ComfySettingsDialog` */
7- interface Setting {
8- id : string ;
9- onChange ?: ( value : any , oldValue ?: any ) => void ;
10- name : string ;
11- render : ( ) => HTMLElement ;
12- }
13-
14- interface SettingOption {
15- text : string ;
16- value ?: string ;
17- }
18-
19- interface SettingParams {
20- id : string ;
21- name : string ;
22- type :
23- | string
24- | ( (
25- name : string ,
26- setter : ( v : any ) => void ,
27- value : any ,
28- attrs : any
29- ) => HTMLElement ) ;
30- defaultValue : any ;
31- onChange ?: ( newValue : any , oldValue ?: any ) => void ;
32- attrs ?: any ;
33- tooltip ?: string ;
34- options ?: Array < string | SettingOption > | ( ( value : any ) => SettingOption [ ] ) ;
35- }
5+ import type { Setting , SettingParams } from "@/types/settingTypes" ;
366
377export class ComfySettingsDialog extends ComfyDialog < HTMLDialogElement > {
388 app : ComfyApp ;
399 settingsValues : any ;
4010 settingsLookup : Record < string , Setting > ;
4111
42- constructor ( app ) {
12+ constructor ( app : ComfyApp ) {
4313 super ( ) ;
4414 this . app = app ;
4515 this . settingsValues = { } ;
@@ -83,7 +53,7 @@ export class ComfySettingsDialog extends ComfyDialog<HTMLDialogElement> {
8353 return Object . values ( this . settingsLookup ) ;
8454 }
8555
86- #dispatchChange( id , value , oldValue ?) {
56+ #dispatchChange< T > ( id : string , value : T , oldValue ?: T ) {
8757 this . dispatchEvent (
8858 new CustomEvent ( id + ".change" , {
8959 detail : {
@@ -109,26 +79,26 @@ export class ComfySettingsDialog extends ComfyDialog<HTMLDialogElement> {
10979 }
11080 }
11181
112- getId ( id ) {
82+ getId ( id : string ) {
11383 if ( this . app . storageLocation === "browser" ) {
11484 id = "Comfy.Settings." + id ;
11585 }
11686 return id ;
11787 }
11888
119- getSettingValue ( id , defaultValue ?) {
89+ getSettingValue < T > ( id : string , defaultValue ?: T ) : T {
12090 let value = this . settingsValues [ this . getId ( id ) ] ;
12191 if ( value != null ) {
12292 if ( this . app . storageLocation === "browser" ) {
12393 try {
124- value = JSON . parse ( value ) ;
94+ value = JSON . parse ( value ) as T ;
12595 } catch ( error ) { }
12696 }
12797 }
12898 return value ?? defaultValue ;
12999 }
130100
131- async setSettingValueAsync ( id , value ) {
101+ async setSettingValueAsync ( id : string , value : any ) {
132102 const json = JSON . stringify ( value ) ;
133103 localStorage [ "Comfy.Settings." + id ] = json ; // backwards compatibility for extensions keep setting in storage
134104
@@ -143,7 +113,7 @@ export class ComfySettingsDialog extends ComfyDialog<HTMLDialogElement> {
143113 await api . storeSetting ( id , value ) ;
144114 }
145115
146- setSettingValue ( id , value ) {
116+ setSettingValue ( id : string , value : any ) {
147117 this . setSettingValueAsync ( id , value ) . catch ( ( err ) => {
148118 alert ( `Error saving setting '${ id } '` ) ;
149119 console . error ( err ) ;
0 commit comments