Fix theme toggle (#200)
* Use builtin event on color change * Fix theme toggle * Update test expectations [skip ci] --------- Co-authored-by: github-actions <github-actions@github.com>
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
26
src/App.vue
@@ -22,17 +22,15 @@ import {
|
|||||||
NodeSearchService,
|
NodeSearchService,
|
||||||
SYSTEM_NODE_DEFS,
|
SYSTEM_NODE_DEFS,
|
||||||
} from "./services/nodeSearchService";
|
} from "./services/nodeSearchService";
|
||||||
import { ColorPaletteLoadedEvent } from "./types/colorPalette";
|
|
||||||
import { LiteGraphNodeSearchSettingEvent } from "./scripts/ui";
|
|
||||||
import { app } from "./scripts/app";
|
import { app } from "./scripts/app";
|
||||||
|
|
||||||
const isLoading = ref(true);
|
const isLoading = ref(true);
|
||||||
const nodeSearchEnabled = ref(false);
|
const nodeSearchEnabled = ref(false);
|
||||||
const nodeSearchService = ref<NodeSearchService>();
|
const nodeSearchService = ref<NodeSearchService>();
|
||||||
|
|
||||||
const updateTheme = (e: ColorPaletteLoadedEvent) => {
|
const updateTheme = (e) => {
|
||||||
const DARK_THEME_CLASS = "dark-theme";
|
const DARK_THEME_CLASS = "dark-theme";
|
||||||
const isDarkTheme = e.detail.id !== "light";
|
const isDarkTheme = e.detail.value !== "light";
|
||||||
|
|
||||||
if (isDarkTheme) {
|
if (isDarkTheme) {
|
||||||
document.body.classList.add(DARK_THEME_CLASS);
|
document.body.classList.add(DARK_THEME_CLASS);
|
||||||
@@ -41,8 +39,8 @@ const updateTheme = (e: ColorPaletteLoadedEvent) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateNodeSearchSetting = (e: LiteGraphNodeSearchSettingEvent) => {
|
const updateNodeSearchSetting = (e) => {
|
||||||
nodeSearchEnabled.value = !e.detail;
|
nodeSearchEnabled.value = e.detail.value === "default";
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
@@ -52,12 +50,11 @@ const init = async () => {
|
|||||||
...SYSTEM_NODE_DEFS,
|
...SYSTEM_NODE_DEFS,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
document.addEventListener("comfy:setting:color-palette-loaded", updateTheme);
|
app.ui.settings.addEventListener("Comfy.ColorPalette.change", updateTheme);
|
||||||
document.addEventListener(
|
app.ui.settings.addEventListener(
|
||||||
"comfy:setting:litegraph-node-search",
|
"Comfy.NodeSearchBoxImpl.change",
|
||||||
updateNodeSearchSetting
|
updateNodeSearchSetting
|
||||||
);
|
);
|
||||||
|
|
||||||
app.ui.settings.refreshSetting("Comfy.NodeSearchBoxImpl");
|
app.ui.settings.refreshSetting("Comfy.NodeSearchBoxImpl");
|
||||||
app.ui.settings.refreshSetting("Comfy.ColorPalette");
|
app.ui.settings.refreshSetting("Comfy.ColorPalette");
|
||||||
};
|
};
|
||||||
@@ -73,12 +70,9 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
document.removeEventListener(
|
app.ui.settings.removeEventListener("Comfy.ColorPalette.change", updateTheme);
|
||||||
"comfy:setting:color-palette-loaded",
|
app.ui.settings.removeEventListener(
|
||||||
updateTheme
|
"Comfy.NodeSearchBoxImpl.change",
|
||||||
);
|
|
||||||
document.removeEventListener(
|
|
||||||
"comfy:setting:litegraph-node-search",
|
|
||||||
updateNodeSearchSetting
|
updateNodeSearchSetting
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||||
import SideBarIcon from "./SideBarIcon.vue";
|
import SideBarIcon from "./SideBarIcon.vue";
|
||||||
import { app } from "@/scripts/app";
|
import { app } from "@/scripts/app";
|
||||||
|
|
||||||
const isDarkMode = ref(false);
|
const isDarkMode = ref(false);
|
||||||
const icon = computed(() => (isDarkMode.value ? "pi pi-sun" : "pi pi-moon"));
|
const icon = computed(() => (isDarkMode.value ? "pi pi-moon" : "pi pi-sun"));
|
||||||
const themeId = computed(() => (isDarkMode.value ? "dark" : "light"));
|
const themeId = computed(() => (isDarkMode.value ? "dark" : "light"));
|
||||||
const toggleTheme = () => {
|
const toggleTheme = () => {
|
||||||
isDarkMode.value = !isDarkMode.value;
|
isDarkMode.value = !isDarkMode.value;
|
||||||
@@ -17,4 +17,17 @@ const toggleTheme = () => {
|
|||||||
watch(themeId, (newThemeId) => {
|
watch(themeId, (newThemeId) => {
|
||||||
app.ui.settings.setSettingValue("Comfy.ColorPalette", newThemeId);
|
app.ui.settings.setSettingValue("Comfy.ColorPalette", newThemeId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateTheme = (e) => {
|
||||||
|
isDarkMode.value = e.detail.value !== "light";
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
app.ui.settings.addEventListener("Comfy.ColorPalette.change", updateTheme);
|
||||||
|
app.ui.settings.refreshSetting("Comfy.ColorPalette");
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
app.ui.settings.removeEventListener("Comfy.ColorPalette.change", updateTheme);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -672,12 +672,6 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
app.canvas.draw(true, true);
|
app.canvas.draw(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.dispatchEvent(
|
|
||||||
new CustomEvent("comfy:setting:color-palette-loaded", {
|
|
||||||
detail: colorPalette,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getColorPalette = (colorPaletteId?) => {
|
const getColorPalette = (colorPaletteId?) => {
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import { TaskItem } from "@/types/apiTypes";
|
|||||||
|
|
||||||
export const ComfyDialog = _ComfyDialog;
|
export const ComfyDialog = _ComfyDialog;
|
||||||
|
|
||||||
export type LiteGraphNodeSearchSettingEvent = CustomEvent<boolean>;
|
|
||||||
|
|
||||||
type Position2D = {
|
type Position2D = {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -434,11 +432,6 @@ export class ComfyUI {
|
|||||||
value = value || "default";
|
value = value || "default";
|
||||||
const useLitegraphSearch = value === "litegraph (legacy)";
|
const useLitegraphSearch = value === "litegraph (legacy)";
|
||||||
app.canvas.allow_searchbox = useLitegraphSearch;
|
app.canvas.allow_searchbox = useLitegraphSearch;
|
||||||
document.dispatchEvent(
|
|
||||||
new CustomEvent("comfy:setting:litegraph-node-search", {
|
|
||||||
detail: useLitegraphSearch,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -93,4 +93,3 @@ const colorPalettesSchema = z.record(paletteSchema);
|
|||||||
export type Colors = z.infer<typeof colorsSchema>;
|
export type Colors = z.infer<typeof colorsSchema>;
|
||||||
export type Palette = z.infer<typeof paletteSchema>;
|
export type Palette = z.infer<typeof paletteSchema>;
|
||||||
export type ColorPalettes = z.infer<typeof colorPalettesSchema>;
|
export type ColorPalettes = z.infer<typeof colorPalettesSchema>;
|
||||||
export type ColorPaletteLoadedEvent = CustomEvent<Palette>;
|
|
||||||
|
|||||||