🚀 Oh look, it works!

This commit is contained in:
Felix Rieseberg 2018-08-22 22:03:28 -07:00
parent ef02056781
commit 8a3e36a2cf
15 changed files with 436 additions and 176 deletions

7
LICENSE.md Normal file
View file

@ -0,0 +1,7 @@
Copyright 2018 Felix Rieseberg
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

12
README.md Normal file
View file

@ -0,0 +1,12 @@
# Windows95
This is Windows 95, running in an Electron app. Yes, it's the full thing. I'm sorry.
## Credits
99.999% of the work was done over at [v86](https://github.com/copy/v86/) by Copy.
## License
This project is provided for educational purposes only. It is not affiliated with and has
not been approved by Microsoft.

BIN
assets/icon.icns Normal file

Binary file not shown.

BIN
assets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

60
forge.config.js Normal file
View file

@ -0,0 +1,60 @@
const path = require('path');
const package = require('./package.json');
module.exports = {
hooks: {
generateAssets: require('./tools/generateAssets')
},
packagerConfig: {
asar: true,
icon: path.resolve(__dirname, 'assets', 'icon'),
appBundleId: 'com.felixrieseberg.windows98',
appCategoryType: 'public.app-category.developer-tools',
win32metadata: {
CompanyName: 'Felix Rieseberg',
OriginalFilename: 'windows98',
},
osxSign: {
identity: 'Developer ID Application: Felix Rieseberg (LT94ZKYDCJ)'
},
},
makers: [
{
name: '@electron-forge/maker-squirrel',
platforms: ['win32'],
config: {
name: 'windows98',
authors: 'Felix Rieseberg',
exe: 'windows98.exe',
noMsi: true,
remoteReleases: '',
setupExe: `windows98-${package.version}-setup-${process.arch}.exe`,
setupIcon: path.resolve(__dirname, 'assets', 'icon.ico'),
}
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin']
},
{
name: '@electron-forge/maker-deb',
platforms: ['linux']
},
{
name: '@electron-forge/maker-rpm',
platforms: ['linux']
}
],
publishers: [
{
name: '@electron-forge/publisher-github',
config: {
repository: {
owner: 'electron',
name: 'fiddle'
},
prerelease: true
}
}
]
};

205
package-lock.json generated
View file

@ -1,5 +1,5 @@
{
"name": "windows98",
"name": "windows95",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
@ -52,6 +52,17 @@
"requires": {
"ms": "2.0.0"
}
},
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
@ -100,6 +111,17 @@
"requires": {
"ms": "2.0.0"
}
},
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
@ -123,6 +145,19 @@
"fs-extra": "^5.0.0",
"pify": "^3.0.0",
"sudo-prompt": "^8.0.0"
},
"dependencies": {
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
"@electron-forge/installer-deb": {
@ -154,6 +189,17 @@
"requires": {
"ms": "2.0.0"
}
},
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
@ -196,6 +242,19 @@
"@electron-forge/installer-darwin": "6.0.0-beta.22",
"cross-spawn-promise": "^0.10.1",
"fs-extra": "^5.0.0"
},
"dependencies": {
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
"@electron-forge/maker-base": {
@ -206,6 +265,19 @@
"requires": {
"@electron-forge/shared-types": "6.0.0-beta.22",
"fs-extra": "^5.0.0"
},
"dependencies": {
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
"@electron-forge/maker-deb": {
@ -241,6 +313,19 @@
"@electron-forge/shared-types": "6.0.0-beta.22",
"electron-winstaller": "^2.5.0",
"fs-extra": "^5.0.0"
},
"dependencies": {
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
"@electron-forge/maker-zip": {
@ -254,6 +339,19 @@
"cross-zip": "^2.1.5",
"fs-extra": "^5.0.0",
"pify": "^3.0.0"
},
"dependencies": {
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
}
}
},
"@electron-forge/plugin-base": {
@ -886,13 +984,13 @@
}
},
"electron": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/electron/-/electron-2.0.8.tgz",
"integrity": "sha512-pbeGFbwijb5V3Xy/KMcwIp59eA9igg2br+7EHbbwQoa3HRDF5JjTrciX7OiscCA52+ze2n4q38S4lXPqRitgIA==",
"version": "3.0.0-beta.6",
"resolved": "https://registry.npmjs.org/electron/-/electron-3.0.0-beta.6.tgz",
"integrity": "sha512-yG9FsZCW6d1cLBEs7IWvqNy5czrJK2d5bP5VlBMHt79fCosV6Oj2TtLD/2joSR7VtaYeF+1049lXXTjq2uhOgw==",
"dev": true,
"requires": {
"@types/node": "^8.0.24",
"electron-download": "^3.0.1",
"electron-download": "^4.1.0",
"extract-zip": "^1.0.3"
},
"dependencies": {
@ -901,64 +999,14 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.26.tgz",
"integrity": "sha512-opk6bLLErLSwyVVJeSH5Ek7ZWOBSsN0JrvXTNVGLXLAXKB9xlTYajrplR44xVyMrmbut94H6uJ9jqzM/12jxkA==",
"dev": true
},
"electron-download": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/electron-download/-/electron-download-3.3.0.tgz",
"integrity": "sha1-LP1U1pZsAZxNSa1l++Zcyc3vaMg=",
"dev": true,
"requires": {
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"home-path": "^1.0.1",
"minimist": "^1.2.0",
"nugget": "^2.0.0",
"path-exists": "^2.1.0",
"rc": "^1.1.2",
"semver": "^5.3.0",
"sumchecker": "^1.2.0"
}
},
"fs-extra": {
"version": "0.30.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz",
"integrity": "sha1-8jP/zAjU2n1DLapEl3aYnbHfk/A=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^2.1.0",
"klaw": "^1.0.0",
"path-is-absolute": "^1.0.0",
"rimraf": "^2.2.8"
}
},
"jsonfile": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6"
}
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true
},
"sumchecker": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-1.3.1.tgz",
"integrity": "sha1-ebs7RFbdBPGOvbwNcDodHa7FEF0=",
"dev": true,
"requires": {
"debug": "^2.2.0",
"es6-promise": "^4.0.5"
}
}
}
},
"electron-default-menu": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/electron-default-menu/-/electron-default-menu-1.0.1.tgz",
"integrity": "sha1-MXPFAY61B0BP7GO987eMOO7bqAg="
},
"electron-download": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/electron-download/-/electron-download-4.1.1.tgz",
@ -1321,6 +1369,17 @@
"ms": "2.0.0"
}
},
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"yargs-parser": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz",
@ -1485,12 +1544,6 @@
"is-arrayish": "^0.2.1"
}
},
"es6-promise": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz",
"integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
@ -1657,10 +1710,9 @@
}
},
"fs-extra": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz",
"integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==",
"dev": true,
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.0.tgz",
"integrity": "sha512-EglNDLRpmaTWiD/qraZn6HREAEAHJcJOmxNEYwq6xeMKnVMAy3GUcFB+wXt2C6k4CNvB/mP1y/U3dzvKKj5OtQ==",
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
@ -1923,8 +1975,7 @@
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=",
"dev": true
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
},
"har-schema": {
"version": "2.0.0",
@ -1954,12 +2005,6 @@
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
"dev": true
},
"home-path": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/home-path/-/home-path-1.0.6.tgz",
"integrity": "sha512-wo+yjrdAtoXt43Vy92a+0IPCYViiyLAHyp0QVS4xL/tfvVz5sXIW1ubLZk3nhVkD92fQpUMKX+fzMjr5F489vw==",
"dev": true
},
"homedir-polyfill": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz",
@ -2196,7 +2241,6 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6"
}
@ -3527,8 +3571,7 @@
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
"dev": true
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
"username": {
"version": "3.0.0",

View file

@ -1,8 +1,8 @@
{
"name": "windows98",
"productName": "windows98",
"name": "windows95",
"productName": "windows95",
"version": "1.0.0",
"description": "My Electron application description",
"description": "Windows 95, in an app. I'm sorry.",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
@ -12,37 +12,15 @@
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": "felixr",
"author": "Felix Rieseberg, felix@felixrieseberg.com",
"license": "MIT",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "windows98"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
"forge": "./forge.config.js"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
"electron-default-menu": "^1.0.1",
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^7.0.0"
},
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.22",
@ -50,6 +28,6 @@
"@electron-forge/maker-rpm": "^6.0.0-beta.22",
"@electron-forge/maker-squirrel": "^6.0.0-beta.22",
"@electron-forge/maker-zip": "^6.0.0-beta.22",
"electron": "2.0.8"
"electron": "3.0.0-beta.6"
}
}

25
src/cache.js Normal file
View file

@ -0,0 +1,25 @@
const { session } = require('electron')
const clearCaches = async () => {
await clearCache()
await clearStorageData()
}
const clearCache = () => {
return new Promise((resolve) => {
session.defaultSession.clearCache(resolve)
})
}
const clearStorageData = () => {
return new Promise((resolve) => {
session.defaultSession.clearStorageData({
storages: 'appcache, cookies, filesystem, indexdb, localstorage, shadercache, websql, serviceworkers',
quotas: 'temporary, persistent, syncable'
}, resolve)
})
}
module.exports = {
clearCaches
}

View file

@ -1,56 +1,47 @@
const { app, BrowserWindow } = require('electron');
const { app, BrowserWindow, session } = require('electron')
const path = require('path')
const { clearCaches } = require('./cache')
const { createMenu } = require('./menu')
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
app.quit()
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1024,
height: 768,
width: 1280,
height: 800,
useContentSize: true,
nodeIntegration: false
nodeIntegration: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/renderer/index.html?system=win98`);
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
};
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
app.on('ready', async () => {
await createMenu()
await clearCaches()
createWindow()
})
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.quit()
})
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
createWindow()
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
})

12
src/menu.js Normal file
View file

@ -0,0 +1,12 @@
const { app, shell, Menu } = require('electron')
const defaultMenu = require('electron-default-menu')
async function createMenu() {
const menu = defaultMenu(app, shell);
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
}
module.exports = {
createMenu
}

42
src/preload.js Normal file
View file

@ -0,0 +1,42 @@
const { remote } = require('electron')
const fs = require('fs-extra')
const path = require('path')
const { STATE_PATH, getState } = require('./state')
window.windows95 = {
STATE_PATH,
async saveState(state) {
return new Promise((resolve) => {
if (!window.emulator || !window.emulator.save_state) {
return resolve()
}
window.emulator.save_state(async (error, new_state) => {
if (error) {
console.log(error)
return
}
await fs.outputFile(STATE_PATH, Buffer.from(new_state))
console.log(`Saved state to ${STATE_PATH}`)
resolve()
});
})
},
async restoreState() {
try {
window.emulator.restore_state(getState())
} catch (error) {
console.log(`Could not read state file. Maybe none exists?`, error)
}
},
quit() {
remote.app.quit()
}
}

View file

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -8,16 +9,30 @@
<script src="./lib/libv86.js"></script>
<link rel="stylesheet" href="style/style.css">
</head>
<body class="paused">
<div id="start-buttons">
<div class="btn" id="win98">Windows 98</div>
<div class="btn" id="win95">Windows 95</div>
<div class="btn" id="win1">Windows 1</div>
<div id="buttons">
<div id="start-buttons">
<!-- <div class="btn" id="win98">Windows 98</div> -->
<div class="btn" id="win95">
Start Windows 95
<br />
<small>Hit ESC to lock or unlock your mouse</small>
</div>
<!-- <div class="btn" id="win1">Windows 1</div> -->
</div>
<div id="other-buttons">
<div class="btn" id="reset">Reset Machine & Delete State</div>
</div>
</div>
<div id="emulator" style="height: 100vh; width: 100vw">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas style="display: none"></canvas>
</div>
<script>require('./renderer.js')</script>
<script>
require('./renderer.js')
</script>
</body>
</html>
</html>

View file

@ -1,19 +1,8 @@
const START_BUTTONS = document.querySelector('#start-buttons')
const BUTTONS = document.querySelector('#buttons')
let cursorCaptured = false;
const OPTIONS = {
win1: {
fda: {
url: './images/windows101.img',
size: 1474560,
}
},
win98: {
hda: {
url: './images/windows98.img',
async: true,
size: 300 * 1024 * 1024,
}
},
win95: {
hda: {
url: './images/windows95.img',
@ -23,7 +12,7 @@ const OPTIONS = {
}
}
function main(id) {
async function main(id) {
const opts = Object.assign({
memory_size: 64 * 1024 * 1024,
screen_container: document.getElementById('emulator'),
@ -32,24 +21,76 @@ function main(id) {
},
vga_bios: {
url: './bios/vgabios.bin',
},
autostart: true
}
}, OPTIONS[id])
console.log(opts, OPTIONS[id])
// New v86 instance
window.emulator = new V86Starter(opts)
window.emulator.lock_mouse()
// Restore state. We can't do this right away.
setTimeout(async () => {
await windows95.restoreState()
cursorCaptured = true
window.emulator.lock_mouse()
window.emulator.run()
}, 500)
}
function setupButtons() {
document.querySelectorAll('.btn').forEach((btn) => {
btn.addEventListener('click', () => {
START_BUTTONS.remove()
BUTTONS.remove()
document.body.className = '';
main(btn.id)
})
})
document.querySelector('#reset').addEventListener('click', () => {
if (window.emulator) {
window.emulator.stop()
}
windows95.resetState()
if (window.emulator) {
window.emulator.run()
}
})
}
function setupEscListener() {
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
if (cursorCaptured) {
cursorCaptured = false
document.exitPointerLock()
} else {
cursorCaptured = true
window.emulator.lock_mouse()
}
}
}
}
function setupCloseListener() {
let isQuitting = false
const handleClose = async () => {
await windows95.saveState()
isQuitting = true
windows95.quit()
}
window.onbeforeunload = (event) => {
if (isQuitting) return
handleClose()
event.preventDefault()
event.returnValue = false
}
}
setupEscListener()
setupCloseListener()
setupButtons()

View file

@ -17,27 +17,37 @@ body.paused > #emulator {
display: none;
}
#other-buttons {
position: absolute;
width: 100vw;
height: 100px;
display: flex;
align-items: flex-end;
bottom: 0;
justify-content: center;
}
#start-buttons {
position: absolute;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
/* flex-direction: column; */
justify-content: center;
font-family: Courier;
}
#start-buttons > .btn {
.btn {
font-family: Courier;
cursor: pointer;
background: #ffd2fd;
margin: 10px;
padding: 5px;
text-align: center;
}
#start-buttons > .btn:hover {
.btn:hover {
cursor: pointer;
background: #ff95fa;
margin: 10px;
padding: 5px;
}
}

24
src/state.js Normal file
View file

@ -0,0 +1,24 @@
const fs = require('fs-extra')
const path = require('path')
const { remote } = require('electron')
const DEFAULT_PATH = path.join(__dirname, 'renderer/images/default-state.bin')
const STATE_PATH = path.join(remote.app.getPath('userData'), 'state.bin')
function getState() {
const statePath = fs.existsSync(STATE_PATH)
? STATE_PATH
: DEFAULT_PATH
return fs.readFileSync(statePath).buffer
}
function resetState() {
fs.removeSync(STATE_PATH)
}
module.exports = {
STATE_PATH,
resetState,
getState
}