Option to control how notifications are shown

This commit is contained in:
space-nuko
2023-05-29 10:27:14 -05:00
parent a2075ede60
commit 51d77ddc53
7 changed files with 77 additions and 7 deletions

View File

@@ -2,10 +2,12 @@ import { debounce } from '$lib/utils';
import { toHashMap } from '@litegraph-ts/core';
import { get, writable } from 'svelte/store';
import type { Writable } from 'svelte/store';
import { defaultConfig, type ConfigState, type ConfigDefAny, CONFIG_DEFS_BY_NAME, validateConfigOption } from './configDefs';
import { defaultConfig, type ConfigState, type ConfigDefAny, CONFIG_DEFS_BY_NAME, validateConfigOption, NotificationState } from './configDefs';
type ConfigStateOps = {
getBackendURL: () => string,
canShowNotificationText: () => boolean,
canPlayNotificationSound: () => boolean,
load: (data: any, runOnChanged?: boolean) => ConfigState
loadDefault: (runOnChanged?: boolean) => ConfigState
@@ -25,6 +27,17 @@ function getBackendURL(): string {
return `${window.location.protocol}//${state.comfyUIHostname}:${state.comfyUIPort}`
}
function canShowNotificationText(): boolean {
const state = get(store).notifications;
return state === NotificationState.MessageAndSound || state === NotificationState.MessageOnly;
}
function canPlayNotificationSound(): boolean {
const state = get(store).notifications;
return state === NotificationState.MessageAndSound || state === NotificationState.SoundOnly;
}
function setConfigOption(def: ConfigDefAny, v: any, runOnChanged: boolean): boolean {
let valid = false;
store.update(state => {
@@ -112,6 +125,9 @@ const configStateStore: WritableConfigStateStore =
{
...store,
getBackendURL,
canShowNotificationText,
canPlayNotificationSound,
validateConfigOption,
setConfigOption,
load,