Skip to content

Commit

Permalink
Migrate ui/settings.js
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Jun 14, 2024
1 parent cefa452 commit ea12624
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/scripts/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ export class ComfyLogging {
$el("button", {
textContent: "View Logs",
onclick: () => {
// TODO: Remove this ts-ignore when settings dialog
// is migrated.
// @ts-ignore
this.app.ui.settings.element.close();
this.dialog.show();
},
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/ui.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { api } from "./api.js";
import { ComfyDialog as _ComfyDialog } from "./ui/dialog.js";
import { toggleSwitch } from "./ui/toggleSwitch.js";
import { ComfySettingsDialog } from "./ui/settings.js";
import { ComfySettingsDialog } from "./ui/settings";

export const ComfyDialog = _ComfyDialog;

Expand All @@ -15,8 +15,8 @@ export const ComfyDialog = _ComfyDialog;
* style?: CSSStyleDeclaration,
* for?: string
* ...any
* } | undefined } propsOrChildren
* @param { Element[] | undefined } [children]
* } | undefined } [propsOrChildren]
* @param { Element[] | Element | undefined } [children]
* @returns
*/
export function $el(tag, propsOrChildren, children) {
Expand Down
25 changes: 20 additions & 5 deletions src/scripts/ui/settings.js → src/scripts/ui/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { $el } from "../ui.js";
import { api } from "../api.js";
import { ComfyDialog } from "./dialog.js";
import type { ComfyApp } from "../app.js";

interface Setting {
id: string;
onChange?: (value: any, oldValue?: any) => void;
name: string;
render: () => HTMLElement;
}

export class ComfySettingsDialog extends ComfyDialog {
app: ComfyApp;
settingsValues: {};
settingsLookup: Record<string, Setting>;
declare element: HTMLDialogElement;

constructor(app) {
super();
this.app = app;
Expand Down Expand Up @@ -40,7 +53,7 @@ export class ComfySettingsDialog extends ComfyDialog {
}),
]),
]
);
) as HTMLDialogElement;
}

get settings() {
Expand All @@ -67,10 +80,10 @@ export class ComfySettingsDialog extends ComfyDialog {
return id;
}

getSettingValue(id, defaultValue) {
getSettingValue(id, defaultValue?) {
let value = this.settingsValues[this.getId(id)];
if(value != null) {
if(this.app.storageLocation === "browser") {
if (value != null) {
if (this.app.storageLocation === "browser") {
try {
value = JSON.parse(value);
} catch (error) {
Expand Down Expand Up @@ -288,7 +301,7 @@ export class ComfySettingsDialog extends ComfyDialog {

return element;
},
};
} as Setting;

const self = this;
return {
Expand All @@ -308,6 +321,8 @@ export class ComfySettingsDialog extends ComfyDialog {
{
style: { display: "none" },
},
// TODO remove this once ui.js is migrated.
// @ts-ignore
[$el("th"), $el("th", { style: { width: "33%" } })]
),
...this.settings.sort((a, b) => a.name.localeCompare(b.name)).map((s) => s.render())
Expand Down

0 comments on commit ea12624

Please sign in to comment.