2023-04-04 10:38:30 +03:00
|
|
|
import { useState } from "react"
|
|
|
|
import { ClientType } from "@dannadori/voice-changer-client-js"
|
|
|
|
|
|
|
|
export type AppGuiSetting = AppGuiDemoSetting
|
|
|
|
|
|
|
|
export type AppGuiDemoSetting = {
|
|
|
|
type: "demo",
|
|
|
|
id: ClientType,
|
|
|
|
front: {
|
2023-04-07 08:07:03 +03:00
|
|
|
"title": GuiComponentSetting[],
|
|
|
|
"serverControl": GuiComponentSetting[],
|
|
|
|
"modelSetting": GuiComponentSetting[],
|
|
|
|
"deviceSetting": GuiComponentSetting[],
|
|
|
|
"qualityControl": GuiComponentSetting[],
|
|
|
|
"speakerSetting": GuiComponentSetting[],
|
|
|
|
"converterSetting": GuiComponentSetting[],
|
|
|
|
"advancedSetting": GuiComponentSetting[],
|
2023-04-30 10:53:15 +03:00
|
|
|
"lab": GuiComponentSetting[],
|
2023-04-04 10:38:30 +03:00
|
|
|
},
|
|
|
|
dialogs: {
|
|
|
|
"license": { title: string, auther: string, contact: string, url: string, license: string }[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 08:07:03 +03:00
|
|
|
export type GuiComponentSetting = {
|
|
|
|
"name": string,
|
|
|
|
"options": any
|
|
|
|
}
|
2023-04-04 10:38:30 +03:00
|
|
|
|
|
|
|
const InitialAppGuiDemoSetting: AppGuiDemoSetting = {
|
|
|
|
type: "demo",
|
|
|
|
id: ClientType.MMVCv13,
|
|
|
|
front: {
|
2023-04-07 08:07:03 +03:00
|
|
|
"title": [],
|
|
|
|
"serverControl": [],
|
|
|
|
"modelSetting": [],
|
|
|
|
"deviceSetting": [],
|
|
|
|
"qualityControl": [],
|
|
|
|
"speakerSetting": [],
|
|
|
|
"converterSetting": [],
|
2023-04-30 10:53:15 +03:00
|
|
|
"advancedSetting": [],
|
|
|
|
"lab": []
|
2023-04-04 10:38:30 +03:00
|
|
|
},
|
|
|
|
dialogs: {
|
|
|
|
"license": [{ title: "", auther: "", contact: "", url: "", license: "MIT" }]
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type AppGuiSettingState = {
|
|
|
|
appGuiSetting: AppGuiSetting
|
2023-04-04 21:35:16 +03:00
|
|
|
guiSettingLoaded: boolean
|
2023-04-04 10:38:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export type AppGuiSettingStateAndMethod = AppGuiSettingState & {
|
2023-04-10 18:21:17 +03:00
|
|
|
getAppGuiSetting: (url: string) => Promise<void>
|
|
|
|
clearAppGuiSetting: () => void
|
2023-04-04 10:38:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export const userAppGuiSetting = (): AppGuiSettingStateAndMethod => {
|
2023-04-04 21:35:16 +03:00
|
|
|
const [guiSettingLoaded, setGuiSettingLoaded] = useState<boolean>(false)
|
2023-04-04 10:38:30 +03:00
|
|
|
const [appGuiSetting, setAppGuiSetting] = useState<AppGuiSetting>(InitialAppGuiDemoSetting)
|
2023-04-10 18:21:17 +03:00
|
|
|
const getAppGuiSetting = async (url: string) => {
|
2023-04-04 10:38:30 +03:00
|
|
|
const res = await fetch(`${url}`, {
|
|
|
|
method: "GET",
|
|
|
|
})
|
|
|
|
const appSetting = await res.json() as AppGuiSetting
|
|
|
|
setAppGuiSetting(appSetting)
|
2023-04-04 21:35:16 +03:00
|
|
|
setGuiSettingLoaded(true)
|
2023-04-04 10:38:30 +03:00
|
|
|
}
|
2023-04-10 18:21:17 +03:00
|
|
|
const clearAppGuiSetting = () => {
|
|
|
|
setAppGuiSetting(InitialAppGuiDemoSetting)
|
|
|
|
setGuiSettingLoaded(false)
|
|
|
|
}
|
2023-04-04 10:38:30 +03:00
|
|
|
return {
|
|
|
|
appGuiSetting,
|
2023-04-04 21:35:16 +03:00
|
|
|
guiSettingLoaded,
|
2023-04-10 18:21:17 +03:00
|
|
|
getAppGuiSetting,
|
|
|
|
clearAppGuiSetting,
|
|
|
|
|
2023-04-04 10:38:30 +03:00
|
|
|
}
|
|
|
|
}
|