Skip to content

Commit

Permalink
visual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
crystian committed Sep 24, 2024
1 parent 3f71a4c commit 348c05d
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 114 deletions.
8 changes: 4 additions & 4 deletions web/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ class CrystoolsMonitor {
configurable: true,
writable: true,
value: (monitorSettings) => {
const value = app.ui.settings.getSettingValue(monitorSettings.id, monitorSettings.defaultValue);
if (monitorSettings.htmlMonitorRef) {
monitorSettings.htmlMonitorRef.style.display = value ? 'flex' : 'none';
if (this.monitorUI) {
const value = app.ui.settings.getSettingValue(monitorSettings.id, monitorSettings.defaultValue);
this.monitorUI.showMonitor(monitorSettings, value);
}
}
});
Expand Down Expand Up @@ -637,7 +637,7 @@ class CrystoolsMonitor {
this.createSettings();
const currentRate = parseFloat(app.ui.settings.getSettingValue(this.settingsRate.id, this.settingsRate.defaultValue));
this.newMenu = app.ui.settings.getSettingValue('Comfy.UseNewMenu', 'Disabled');
this.monitorUI = new MonitorUI(this.monitorCPUElement, this.monitorRAMElement, this.monitorHDDElement, this.monitorGPUSettings, this.monitorVRAMSettings, this.monitorTemperatureSettings, currentRate, (this.newMenu === NewMenuOptions.Disabled));
this.monitorUI = new MonitorUI(this.monitorCPUElement, this.monitorRAMElement, this.monitorHDDElement, this.monitorGPUSettings, this.monitorVRAMSettings, this.monitorTemperatureSettings, currentRate);
this.updateDisplay();
this.registerListeners();
}
Expand Down
26 changes: 4 additions & 22 deletions web/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,12 @@ class CrystoolsMonitor {
});
};

// eslint-disable-next-line complexity
moveMonitor = (position: NewMenuOptions): void => {
let parentElement: Element | null | undefined;

switch (position) {
case NewMenuOptions.Disabled:
parentElement = document.getElementById('queue-button');
// TODO remove this
if (document.getElementById('ProgressBarUI')) {
// @ts-ignore
document.getElementById('ProgressBarUI').style.display = 'flex';

}
if (parentElement && this.monitorUI.htmlRoot) {
parentElement.insertAdjacentElement('afterend', this.monitorUI.htmlRoot);
} else {
Expand All @@ -426,26 +419,16 @@ class CrystoolsMonitor {

case NewMenuOptions.Top:
case NewMenuOptions.Bottom:
// TODO remove this
if (document.getElementById('ProgressBarUI')) {
// @ts-ignore
document.getElementById('ProgressBarUI').style.display = 'none';
}
//comfyui-button-group
this.monitorUI.htmlRoot.classList.add('comfyui-button-group');
// this.monitorUI.htmlRoot.classList.add('comfyui-menu-mobile-collapse');
this.monitorUI.htmlRoot?.classList.add('comfyui-button-group');
parentElement = document.getElementsByClassName('comfyui-menu-push')[0];

if (parentElement && this.monitorUI.htmlRoot) {
parentElement.insertAdjacentElement('afterend', this.monitorUI.htmlRoot);
// parentElement.appendChild(this.monitorUI.htmlRoot);
} else {
console.error('Crystools: parentElement to move monitors not found!', parentElement);
}
break;
}


};

updateAllWidget = (): void => {
Expand All @@ -469,9 +452,9 @@ class CrystoolsMonitor {
* @param monitorSettings
*/
updateWidget = (monitorSettings: TMonitorSettings): void => {
const value = app.ui.settings.getSettingValue(monitorSettings.id, monitorSettings.defaultValue);
if (monitorSettings.htmlMonitorRef) {
monitorSettings.htmlMonitorRef.style.display = value ? 'flex' : 'none';
if (this.monitorUI) {
const value = app.ui.settings.getSettingValue(monitorSettings.id, monitorSettings.defaultValue);
this.monitorUI.showMonitor(monitorSettings, value);
}
};

Expand Down Expand Up @@ -544,7 +527,6 @@ class CrystoolsMonitor {
this.monitorVRAMSettings,
this.monitorTemperatureSettings,
currentRate,
(this.newMenu === NewMenuOptions.Disabled),
);

this.updateDisplay();
Expand Down
3 changes: 2 additions & 1 deletion web/monitorUI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export declare class MonitorUI extends ProgressBarUIBase {
private currentRate;
lastMonitor: number;
styleSheet: HTMLStyleElement;
constructor(monitorCPUElement: TMonitorSettings, monitorRAMElement: TMonitorSettings, monitorHDDElement: TMonitorSettings, monitorGPUSettings: TMonitorSettings[], monitorVRAMSettings: TMonitorSettings[], monitorTemperatureSettings: TMonitorSettings[], currentRate: number, showSection: boolean);
constructor(monitorCPUElement: TMonitorSettings, monitorRAMElement: TMonitorSettings, monitorHDDElement: TMonitorSettings, monitorGPUSettings: TMonitorSettings[], monitorVRAMSettings: TMonitorSettings[], monitorTemperatureSettings: TMonitorSettings[], currentRate: number);
createDOM: () => void;
createDOMGPUMonitor: (monitorSettings?: TMonitorSettings) => void;
orderMonitors: () => void;
Expand All @@ -19,4 +19,5 @@ export declare class MonitorUI extends ProgressBarUIBase {
updatedAnimationDuration: (monitorSettings: TMonitorSettings, value: number) => void;
createMonitor: (monitorSettings?: TMonitorSettings) => HTMLDivElement;
updateMonitorSize: (width: number, height: number) => void;
showMonitor: (monitorSettings: TMonitorSettings, value: boolean) => void;
}
23 changes: 12 additions & 11 deletions web/monitorUI.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ProgressBarUIBase } from './progressBarUIBase.js';
import { createStyleSheet, formatBytes } from './utils.js';
export class MonitorUI extends ProgressBarUIBase {
constructor(monitorCPUElement, monitorRAMElement, monitorHDDElement, monitorGPUSettings, monitorVRAMSettings, monitorTemperatureSettings, currentRate, showSection) {
super('queue-button', 'crystools-root', showSection);
constructor(monitorCPUElement, monitorRAMElement, monitorHDDElement, monitorGPUSettings, monitorVRAMSettings, monitorTemperatureSettings, currentRate) {
super('queue-button', 'crystools-root');
Object.defineProperty(this, "monitorCPUElement", {
enumerable: true,
configurable: true,
Expand Down Expand Up @@ -45,12 +45,6 @@ export class MonitorUI extends ProgressBarUIBase {
writable: true,
value: currentRate
});
Object.defineProperty(this, "showSection", {
enumerable: true,
configurable: true,
writable: true,
value: showSection
});
Object.defineProperty(this, "lastMonitor", {
enumerable: true,
configurable: true,
Expand Down Expand Up @@ -163,9 +157,6 @@ export class MonitorUI extends ProgressBarUIBase {
configurable: true,
writable: true,
value: (monitorSettings, percent, used, total) => {
if (!this.showSection) {
return;
}
if (!(monitorSettings.htmlMonitorSliderRef && monitorSettings.htmlMonitorLabelRef)) {
return;
}
Expand Down Expand Up @@ -269,6 +260,16 @@ export class MonitorUI extends ProgressBarUIBase {
}`;
}
});
Object.defineProperty(this, "showMonitor", {
enumerable: true,
configurable: true,
writable: true,
value: (monitorSettings, value) => {
if (monitorSettings.htmlMonitorRef) {
monitorSettings.htmlMonitorRef.style.display = value ? 'flex' : 'none';
}
}
});
this.createDOM();
this.styleSheet = createStyleSheet('crystools-monitors-size');
}
Expand Down
15 changes: 8 additions & 7 deletions web/monitorUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export class MonitorUI extends ProgressBarUIBase {
private monitorVRAMSettings: TMonitorSettings[],
private monitorTemperatureSettings: TMonitorSettings[],
private currentRate: number,
showSection: boolean,
) {
super('queue-button', 'crystools-root', showSection);
super('queue-button', 'crystools-root');
this.createDOM();

this.styleSheet = createStyleSheet('crystools-monitors-size');
Expand Down Expand Up @@ -117,12 +116,7 @@ export class MonitorUI extends ProgressBarUIBase {
});
};

// eslint-disable-next-line complexity
updateMonitor = (monitorSettings: TMonitorSettings, percent: number, used?: number, total?: number): void => {
if (!this.showSection) {
return;
}

if (!(monitorSettings.htmlMonitorSliderRef && monitorSettings.htmlMonitorLabelRef)) {
return;
}
Expand All @@ -132,6 +126,7 @@ export class MonitorUI extends ProgressBarUIBase {
}

// console.log('updateMonitor', monitorSettings.id, percent);

const prefix = monitorSettings.monitorTitle ? monitorSettings.monitorTitle + ' - ' : '';
let title = `${Math.floor(percent)}${monitorSettings.symbol}`;
let postfix = '';
Expand Down Expand Up @@ -222,4 +217,10 @@ export class MonitorUI extends ProgressBarUIBase {
height: ${height}px; width: ${width}px;
}`;
};

showMonitor = (monitorSettings: TMonitorSettings, value: boolean): void => {
if (monitorSettings.htmlMonitorRef) {
monitorSettings.htmlMonitorRef.style.display = value ? 'flex' : 'none';
}
};
}
2 changes: 1 addition & 1 deletion web/progressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CrystoolsProgressBar {
const newMenu = app.ui.settings.getSettingValue('Comfy.UseNewMenu', 'Disabled');
if (newMenu !== this.newMenu) {
this.newMenu = newMenu;
this.progressBarUI.showFullSection(this.newMenu === NewMenuOptions.Disabled);
this.progressBarUI.showSection(this.newMenu === NewMenuOptions.Disabled);
}
this.progressBarUI.updateDisplay(this.currentStatus, this.timeStart, this.currentProgress);
});
Expand Down
19 changes: 7 additions & 12 deletions web/progressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ class CrystoolsProgressBar {
};

updateDisplay = (): void => {
const newMenu = app.ui.settings.getSettingValue('Comfy.UseNewMenu', 'Disabled');
setTimeout(() => {
const newMenu = app.ui.settings.getSettingValue('Comfy.UseNewMenu', 'Disabled');
if (newMenu !== this.newMenu) {
this.newMenu = newMenu;

if (newMenu !== this.newMenu) {
this.newMenu = newMenu;

this.progressBarUI.showSection = (this.newMenu === NewMenuOptions.Disabled);
if (this.progressBarUI.showSection) {
this.setup();
this.progressBarUI.showSection(this.newMenu === NewMenuOptions.Disabled);
}
}
// this.progressBarUI.showSection = (this.newMenu !== NewMenuOptions.Disabled);
// this.progressBarUI.htmlContainer.style.display = 'none';
this.progressBarUI.updateDisplay(this.currentStatus, this.timeStart, this.currentProgress);
this.progressBarUI.updateDisplay(this.currentStatus, this.timeStart, this.currentProgress);
});
};

// automatically called by ComfyUI
Expand All @@ -58,7 +54,6 @@ class CrystoolsProgressBar {
return;
}


this.newMenu = app.ui.settings.getSettingValue('Comfy.UseNewMenu', 'Disabled');
this.progressBarUI = new ProgressBarUI((this.newMenu === NewMenuOptions.Disabled), this.centerNode);

Expand Down
7 changes: 5 additions & 2 deletions web/progressBarUI.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { EStatus, ProgressBarUIBase } from './progressBarUIBase.js';
export declare class ProgressBarUI extends ProgressBarUIBase {
showSectionFlag: boolean;
private centerNode;
htmlProgressSliderRef: HTMLDivElement;
htmlProgressLabelRef: HTMLDivElement;
currentStatus: EStatus;
timeStart: number;
currentProgress: number;
progressBar: boolean;
constructor(showSection: boolean, centerNode: () => void);
showProgressBarFlag: boolean;
constructor(showSectionFlag: boolean, centerNode: () => void);
createDOM: () => void;
updateDisplay: (currentStatus: EStatus, timeStart: number, currentProgress: number) => void;
showSection: (value: boolean) => void;
showProgressBar: (value: boolean) => void;
private displaySection;
}
33 changes: 25 additions & 8 deletions web/progressBarUI.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EStatus, ProgressBarUIBase } from './progressBarUIBase.js';
export class ProgressBarUI extends ProgressBarUIBase {
constructor(showSection, centerNode) {
super('queue-button', 'crystools-root', showSection);
Object.defineProperty(this, "showSection", {
constructor(showSectionFlag, centerNode) {
super('queue-button', 'crystools-root');
Object.defineProperty(this, "showSectionFlag", {
enumerable: true,
configurable: true,
writable: true,
value: showSection
value: showSectionFlag
});
Object.defineProperty(this, "centerNode", {
enumerable: true,
Expand Down Expand Up @@ -44,7 +44,7 @@ export class ProgressBarUI extends ProgressBarUIBase {
writable: true,
value: void 0
});
Object.defineProperty(this, "progressBar", {
Object.defineProperty(this, "showProgressBarFlag", {
enumerable: true,
configurable: true,
writable: true,
Expand Down Expand Up @@ -79,7 +79,7 @@ export class ProgressBarUI extends ProgressBarUIBase {
configurable: true,
writable: true,
value: (currentStatus, timeStart, currentProgress) => {
if (!(this.showSection && this.progressBar)) {
if (!(this.showSectionFlag && this.showProgressBarFlag)) {
return;
}
if (!(this.htmlProgressLabelRef && this.htmlProgressSliderRef)) {
Expand Down Expand Up @@ -108,13 +108,30 @@ export class ProgressBarUI extends ProgressBarUIBase {
}
}
});
Object.defineProperty(this, "showSection", {
enumerable: true,
configurable: true,
writable: true,
value: (value) => {
this.showSectionFlag = value;
this.displaySection();
}
});
Object.defineProperty(this, "showProgressBar", {
enumerable: true,
configurable: true,
writable: true,
value: (value) => {
this.progressBar = value;
this.showFullSectionOnDemand(this.progressBar && this.showSection);
this.showProgressBarFlag = value;
this.displaySection();
}
});
Object.defineProperty(this, "displaySection", {
enumerable: true,
configurable: true,
writable: true,
value: () => {
this.htmlContainer.style.display = (this.showSectionFlag && this.showProgressBarFlag) ? 'block' : 'none';
}
});
this.createDOM();
Expand Down
25 changes: 15 additions & 10 deletions web/progressBarUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export class ProgressBarUI extends ProgressBarUIBase {
currentStatus: EStatus;
timeStart: number;
currentProgress: number;
progressBar: boolean;
showProgressBarFlag: boolean;

constructor(
showSection: boolean,
public showSectionFlag: boolean,
private centerNode: () => void,
) {
super('queue-button', 'crystools-root', showSection);
super('queue-button', 'crystools-root');
this.createDOM();
}

Expand Down Expand Up @@ -41,11 +41,7 @@ export class ProgressBarUI extends ProgressBarUIBase {

// eslint-disable-next-line complexity
updateDisplay = (currentStatus: EStatus, timeStart: number, currentProgress: number): void => {
if (!this.showSection) {
return;
}

if (!this.progressBar) {
if (!(this.showSectionFlag && this.showProgressBarFlag)) {
return;
}

Expand Down Expand Up @@ -84,9 +80,18 @@ export class ProgressBarUI extends ProgressBarUIBase {

};

public showSection = (value: boolean): void => {
this.showSectionFlag = value;
this.displaySection();
};

// remember it can't have more parameters because it is used on settings automatically
public showProgressBar = (value: boolean): void => {
this.progressBar = value;
this.htmlContainer.style.display = this.progressBar ? 'block' : 'none';
this.showProgressBarFlag = value;
this.displaySection();
};

private displaySection = (): void => {
this.htmlContainer.style.display = (this.showSectionFlag && this.showProgressBarFlag) ? 'block' : 'none';
};
}
3 changes: 1 addition & 2 deletions web/progressBarUIBase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export declare enum NewMenuOptions {
export declare abstract class ProgressBarUIBase {
parentId: string;
rootId: string;
showSection: boolean;
htmlRoot: HTMLElement | null;
htmlContainer: HTMLDivElement;
protected htmlClassMonitor: string;
protected constructor(parentId: string, rootId: string, showSection: boolean);
protected constructor(parentId: string, rootId: string);
private createRoot;
abstract createDOM(): void;
}
Loading

0 comments on commit 348c05d

Please sign in to comment.