From bfb8b337447f982c0ffac133dd9261be9fb730ba Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Fri, 29 Dec 2023 10:23:52 +0300 Subject: [PATCH] Add option to lock backend --- src/components/dos-option-select.tsx | 2 ++ src/load.ts | 12 ++++++++++-- src/main.tsx | 9 +++++++++ src/public/types.ts | 4 +++- src/store/dos.ts | 5 +++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/components/dos-option-select.tsx b/src/components/dos-option-select.tsx index 1ac1c426..cf9ffa12 100644 --- a/src/components/dos-option-select.tsx +++ b/src/components/dos-option-select.tsx @@ -10,9 +10,11 @@ import { import { ThemeValues, Theme, uiSlice } from "../store/ui"; export function BackendSelect() { + const locked = useSelector((state: State) => state.dos.backendLocked); return state.dos.backend} dispatch={(newValue: Backend) => dosSlice.actions.dosBackend(newValue)} />; diff --git a/src/load.ts b/src/load.ts index 914ff252..d7ad2f11 100644 --- a/src/load.ts +++ b/src/load.ts @@ -40,7 +40,7 @@ export async function loadBundleFromConfg(config: DosConfig, dispatch: Dispatch) nonSerializableStore.loadedBundle = null; dispatch(editorSlice.actions.init(config)); - dispatch(dosSlice.actions.mouseCapture(config.dosboxConf.indexOf("autolock=true") > 0)); + syncWithConfig(config, dispatch); nonSerializableStore.loadedBundle = { bundleUrl: null, @@ -80,7 +80,7 @@ async function doLoadBundle(bundleName: string, if (config === null) { dispatch(uiSlice.actions.frameConf()); } else { - dispatch(dosSlice.actions.mouseCapture(config.dosboxConf.indexOf("autolock=true") > 0)); + syncWithConfig(config, dispatch); } nonSerializableStore.loadedBundle = { @@ -129,3 +129,11 @@ export async function updateBundleConf() { nonSerializableStore.loadedBundle!.bundle = await emulators.bundleUpdateConfig(bundle, config); } + +function syncWithConfig(config: DosConfig, dispatch: Dispatch) { + if (config.dosboxConf.indexOf("sockdrive") >= 0) { + dispatch(dosSlice.actions.dosBackendLocked(true)); + dispatch(dosSlice.actions.dosBackend("dosboxX")); + } + dispatch(dosSlice.actions.mouseCapture(config.dosboxConf.indexOf("autolock=true") >= 0)); +} diff --git a/src/main.tsx b/src/main.tsx index b0ca156a..2361d39f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -80,6 +80,10 @@ export const Dos: DosFn = (element: HTMLDivElement, store.dispatch(dosSlice.actions.dosBackend(backend)); } + function setBackendLocked(locked: boolean) { + store.dispatch(dosSlice.actions.dosBackendLocked(locked)); + } + function setWorkerThread(workerThread: DosOptions["workerThread"]) { store.dispatch(dosSlice.actions.dosWorker(workerThread)); } @@ -120,6 +124,10 @@ export const Dos: DosFn = (element: HTMLDivElement, setBackend(options.backend); } + if (options.backendLoked) { + setBackendLocked(options.backendLoked); + } + if (options.workerThread !== undefined) { setWorkerThread(options.workerThread); } @@ -155,6 +163,7 @@ export const Dos: DosFn = (element: HTMLDivElement, setTheme, setLang, setBackend, + setBackendLocked, setWorkerThread, setMouseCapture, setServer, diff --git a/src/public/types.ts b/src/public/types.ts index 949c4b80..c54f5564 100644 --- a/src/public/types.ts +++ b/src/public/types.ts @@ -10,6 +10,7 @@ export interface DosOptions { "night" | "coffee" | "winter", lang: "ru" | "en", backend: "dosbox" | "dosboxX", + backendLoked: boolean, workerThread: boolean, mouseCapture: boolean, onEvent: (event: "emu-ready" | "ci-ready" | "bnd-play", ci?: any) => void, @@ -21,7 +22,8 @@ export interface DosOptions { export interface DosProps { setTheme(theme: DosOptions["theme"]): void; setLang(lang: DosOptions["lang"]): void; - setBackend(lang: DosOptions["backend"]): void; + setBackend(backend: DosOptions["backend"]): void; + setBackendLocked(locked: boolean): void; setWorkerThread(capture: DosOptions["workerThread"]): void; setMouseCapture(capture: DosOptions["mouseCapture"]): void; setServer(server: DosOptions["server"]): void; diff --git a/src/store/dos.ts b/src/store/dos.ts index fe7e7ea0..ffa553a3 100644 --- a/src/store/dos.ts +++ b/src/store/dos.ts @@ -53,6 +53,7 @@ const initialState: { emuVersion: string, worker: boolean, backend: Backend, + backendLocked: boolean, renderBackend: RenderBackend, renderAspect: RenderAspect, volume: number, @@ -78,6 +79,7 @@ const initialState: { config: {}, worker: lStorage.getItem("worker") !== "false", backend: (lStorage.getItem("backend") ?? "dosboxX") as Backend, + backendLocked: false, renderBackend: (lStorage.getItem("renderBackend") ?? "webgl") as RenderBackend, renderAspect: (lStorage.getItem("renderAspect") ?? "AsIs") as RenderAspect, volume: (Number.parseFloat(lStorage.getItem("volume") ?? "1.0")), @@ -168,6 +170,9 @@ export const dosSlice = createSlice({ s.backend = a.payload as Backend; lStorage.setItem("backend", s.backend); }, + dosBackendLocked: (s, a: { payload: boolean }) => { + s.backendLocked = a.payload; + }, renderBackend: (s, a: { payload: RenderBackend }) => { s.renderBackend = a.payload; lStorage.setItem("renderBackend", s.renderBackend);