Skip to content

Commit 6f2025f

Browse files
Improve reset
1 parent 3a7b37f commit 6f2025f

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ out
33
.DS_Store
44

55
/images*/
6+
/helper-images/
67

78
dist
89
!.github/images

docs/qemu.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Installation
2020
qemu-system-i386 \
2121
-cdrom Win95_OSR25.iso \
2222
-m 128 \
23-
-hda images/windows95_v4.raw \
23+
-hda windows95.img \
2424
-device sb16 \
2525
-nic user,model=ne2k_pci \
2626
-fda Win95_boot.img \
@@ -39,10 +39,10 @@ qemu-system-i386 \
3939
```sh
4040
qemu-system-i386 \
4141
-m 128 \
42-
-hda images/windows95_v4.raw \
42+
-hda images/windows95.img \
4343
-device sb16 \
4444
-M pc,acpi=off \
4545
-cpu pentium \
46-
-netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
46+
-netdev user,id=mynet0 \
4747
-device ne2k_isa,netdev=mynet0,irq=10
4848
```

src/main/menu.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, shell, Menu, BrowserWindow, ipcMain } from "electron";
1+
import { app, shell, Menu, BrowserWindow, ipcMain, dialog } from "electron";
22

33
import { clearCaches } from "../cache";
44
import { IPC_COMMANDS } from "../constants";
@@ -164,7 +164,20 @@ async function createMenu({ isRunning } = { isRunning: false }) {
164164
},
165165
{
166166
label: "Reset",
167-
click: () => send(IPC_COMMANDS.MACHINE_RESET),
167+
click: async () => {
168+
const result = await dialog.showMessageBox({
169+
type: 'warning',
170+
buttons: ['Reset', 'Cancel'],
171+
defaultId: 1,
172+
title: 'Reset Machine',
173+
message: 'Are you sure you want to reset the machine?',
174+
detail: 'This will delete the machine state, including all changes you have made.',
175+
});
176+
177+
if (result.response === 0) {
178+
send(IPC_COMMANDS.MACHINE_RESET);
179+
}
180+
},
168181
enabled: isRunning,
169182
},
170183
{

src/renderer/card-settings.tsx

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from "react";
2-
import * as fs from "fs";
32

4-
import { getStatePath } from "./utils/get-state-path";
3+
import { resetState } from "./utils/reset-state";
54

65
interface CardSettingsProps {
76
bootFromScratch: () => void;
@@ -213,16 +212,7 @@ export class CardSettings extends React.Component<
213212
* Handle the state reset
214213
*/
215214
private async onResetState() {
216-
const statePath = await getStatePath();
217-
218-
if (fs.existsSync(statePath)) {
219-
try {
220-
await fs.promises.unlink(statePath);
221-
} catch (error) {
222-
console.error(`Failed to delete state file: ${error}`);
223-
}
224-
}
225-
215+
await resetState();
226216
this.setState({ isStateReset: true });
227217
}
228218
}

src/renderer/emulator.tsx

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import * as fs from "fs";
33
import * as path from "path";
4-
import { ipcRenderer, shell } from "electron";
4+
import { ipcRenderer, shell, webUtils } from "electron";
55

66
import { CONSTANTS, IPC_COMMANDS } from "../constants";
77
import { getDiskImageSize } from "../utils/disk-image-size";
@@ -11,6 +11,7 @@ import { CardSettings } from "./card-settings";
1111
import { EmulatorInfo } from "./emulator-info";
1212
import { getStatePath } from "./utils/get-state-path";
1313
import { Win95Window } from "./app";
14+
import { resetState } from "./utils/reset-state";
1415

1516
declare let window: Win95Window;
1617

@@ -53,10 +54,6 @@ export class Emulator extends React.Component<{}, EmulatorState> {
5354
this.setupInputListeners();
5455
this.setupIpcListeners();
5556
this.setupUnloadListeners();
56-
57-
if (document.location.hash.includes("AUTO_START")) {
58-
this.startEmulator();
59-
}
6057
}
6158

6259
/**
@@ -274,6 +271,10 @@ export class Emulator extends React.Component<{}, EmulatorState> {
274271
private async startEmulator() {
275272
document.body.classList.remove("paused");
276273

274+
const cdromPath = this.state.cdromFile
275+
? webUtils.getPathForFile(this.state.cdromFile)
276+
: null;
277+
277278
const options = {
278279
wasm_path: path.join(__dirname, "build/v86.wasm"),
279280
memory_size: 128 * 1024 * 1024,
@@ -303,11 +304,11 @@ export class Emulator extends React.Component<{}, EmulatorState> {
303304
buffer: this.state.floppyFile,
304305
}
305306
: undefined,
306-
cdrom: this.state.cdromFile?.path
307+
cdrom: cdromPath
307308
? {
308-
url: this.state.cdromFile.path,
309+
url: cdromPath,
309310
async: true,
310-
size: await getDiskImageSize(this.state.cdromFile.path),
311+
size: await getDiskImageSize(cdromPath),
311312
}
312313
: undefined,
313314
boot_order: 0x132,
@@ -378,7 +379,10 @@ export class Emulator extends React.Component<{}, EmulatorState> {
378379
*/
379380
private async resetEmulator() {
380381
this.isResetting = true;
381-
document.location.hash = `#AUTO_START`;
382+
383+
await this.stopEmulator();
384+
await resetState();
385+
382386
document.location.reload();
383387
}
384388

@@ -518,7 +522,7 @@ export class Emulator extends React.Component<{}, EmulatorState> {
518522
*/
519523
private resetCanvas() {
520524
const canvas = document.getElementById("emulator-canvas");
521-
525+
522526
if (canvas instanceof HTMLCanvasElement) {
523527
const ctx = canvas.getContext('2d');
524528
ctx?.clearRect(0, 0, canvas.width, canvas.height);

src/renderer/utils/reset-state.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import fs from "fs";
2+
import { getStatePath } from "./get-state-path";
3+
4+
export async function resetState() {
5+
const statePath = await getStatePath();
6+
7+
if (fs.existsSync(statePath)) {
8+
try {
9+
await fs.promises.unlink(statePath);
10+
} catch (error) {
11+
console.error(`Failed to delete state file: ${error}`);
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)