Skip to content

Commit

Permalink
support dosboxConf
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Nov 8, 2023
1 parent 2f509c4 commit 803b58c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/frame/editor/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
export const dosboxconf = [{
name: "DOS",
backend: "dosbox",
Expand Down Expand Up @@ -207,7 +208,7 @@ echo on
# █ ███ █ ▀█▀▀▄▀▀▄████▀▀█▄█
# █ ▀▀▀ █ ▄▀▀█▀█▀▄ ▀▀▄▄█▄█
# ▀▀▀▀▀▀▀ ▀ ▀▀ ▀ ▀ ▀▀▀
`.replace(/\n/g, "\r\n")
`.replace(/\n/g, "\r\n"),
}, {
name: "X - DOS 7.1",
backend: "dosboxX",
Expand Down Expand Up @@ -339,5 +340,5 @@ echo on
# ▀▀▀▀▀▀▀ ▀ ▀▀ ▀ ▀ ▀▀▀
#
`.replace(/\n/g, "\r\n"),
}
},
];
1 change: 0 additions & 1 deletion src/frame/editor/editor-conf-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { State } from "../../store";
import { editorSlice } from "../../store/editor";
import { dosboxconf } from "./defaults";
import { dosSlice } from "../../store/dos";
import { uiSlice } from "../../store/ui";

export function EditorConf() {
const t = useT();
Expand Down
20 changes: 17 additions & 3 deletions src/load.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, Unsubscribe } from "@reduxjs/toolkit";
import { Emulators } from "emulators";
import { DosConfig, Emulators } from "emulators";
import { dosSlice } from "./store/dos";
import { nonSerializableStore } from "./non-serializable-store";
import { bundleFromChanges, bundleFromFile, bundleFromUrl } from "./host/bundle-storage";
Expand Down Expand Up @@ -36,6 +36,20 @@ export function loadBundleFromFile(file: File, dispatch: Dispatch) {
null, null, dispatch);
}

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));

nonSerializableStore.loadedBundle = {
bundleUrl: null,
bundleChangesUrl: null,
bundle: config,
bundleChanges: null,
};
dispatch(dosSlice.actions.bndReady({}));
}

export async function loadBundleFromUrl(url: string, dispatch: Dispatch) {
const owner = store.getState().auth.account?.email ?? "guest";
Expand Down Expand Up @@ -108,10 +122,10 @@ async function changesProducer(bundleUrl: string): Promise<{
export async function updateBundleConf() {
const config = store.getState().editor.bundleConfig;
const bundle = nonSerializableStore.loadedBundle?.bundle;
if (bundle === null || config === null) {
if (bundle === null || config === null || !ArrayBuffer.isView(bundle)) {
throw new Error("Unexpected behaviour (internal state is broken), bundle is null");
}

nonSerializableStore.loadedBundle!.bundle =
await emulators.bundleUpdateConfig(bundle!, config);
await emulators.bundleUpdateConfig(bundle, config);
}
18 changes: 14 additions & 4 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { uiSlice } from "./store/ui";
import { i18nSlice } from "./i18n";
import { nonSerializableStore, postJsDosEvent } from "./non-serializable-store";
import { getCache } from "./host/lcache";
import { loadBundleFromUrl } from "./load";
import { loadBundleFromConfg, loadBundleFromUrl } from "./load";

import { DosOptions, DosProps, DosFn } from "./public/types";
import { browserSetFullScreen } from "./host/fullscreen";
Expand All @@ -33,8 +33,18 @@ async function pollEvents() {
nonSerializableStore.cache = await getCache(cachedEmail ?? "guest");

if (nonSerializableStore.options.url) {
loadBundleFromUrl(nonSerializableStore.options.url, store.dispatch)
.catch((e) => store.dispatch(dosSlice.actions.bndError(e.message)));
try {
await loadBundleFromUrl(nonSerializableStore.options.url, store.dispatch);
} catch (e: any) {
store.dispatch(dosSlice.actions.bndError(e.message));
}
} else if (nonSerializableStore.options.dosboxConf) {
loadBundleFromConfg({
dosboxConf: nonSerializableStore.options.dosboxConf,
jsdosConf: {
version: "8",
},
}, store.dispatch);
} else {
store.dispatch(uiSlice.actions.windowSelect());
}
Expand All @@ -49,7 +59,7 @@ store.subscribe(pollEvents);

let skipEmulatorsInit = false;
export const Dos: DosFn = (element: HTMLDivElement,
options: Partial<DosOptions> = {}): DosProps =>{
options: Partial<DosOptions> = {}): DosProps => {
nonSerializableStore.options = options;
setupRootElement(element);

Expand Down
4 changes: 2 additions & 2 deletions src/non-serializable-store.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CommandInterface } from "emulators";
import { CommandInterface, InitFs } from "emulators";
import { Cache, CacheNoop } from "./host/lcache";
import { Dispatch } from "@reduxjs/toolkit";
import { DosOptions } from "./public/types";

export interface LoadedBundle {
bundleUrl: string | null,
bundleChangesUrl: string | null,
bundle: Uint8Array | null,
bundle: InitFs | null,
bundleChanges: Uint8Array | null,
}

Expand Down
5 changes: 3 additions & 2 deletions src/public/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface DosOptions {
url: string | null,
background: string | null,
url: string,
dosboxConf: string,
background: string,
pathPrefix: string,
theme: "light" | "dark" | "cupcake" | "bumblebee" | "emerald" | "corporate" |
"synthwave" | "retro" | "cyberpunk" | "valentine" | "halloween" | "garden" |
Expand Down

0 comments on commit 803b58c

Please sign in to comment.