Skip to content

Commit

Permalink
Fetches iso from github on prod builds
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkar598 committed Jun 21, 2024
1 parent 4d194e9 commit e165709
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
- name: Install NPM Dependencies
run: npm ci

- name: Download ISO
run: wget https://spacestation13.github.io/dm-playground-linux/rootfs.iso9660 -O public/lib/rootfs.iso

- name: Build project
run: npx ng build --base-href /dm-playground/

Expand Down
8 changes: 7 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
"sourceMap": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand Down
3 changes: 3 additions & 0 deletions src/environments/environment.development.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
isoUrl: './lib/rootfs.iso',
};
3 changes: 3 additions & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
isoUrl: 'https://spacestation13.github.io/dm-playground-linux/rootfs.iso9660',
};
1 change: 1 addition & 0 deletions src/utils/literalConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isoUrlSearchParameter = 'isoUrl';
13 changes: 12 additions & 1 deletion src/vm/emulator.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { EventEmitter, Injectable, Output } from '@angular/core';
import type { WorkerMsgWithoutCID, WorkerResponseMsg } from './emulator.worker';
import { environment } from '../environments/environment';
import { isoUrlSearchParameter } from '../utils/literalConstants';

const encoder = new TextEncoder();

Expand All @@ -16,11 +18,20 @@ export class EmulatorService {
@Output()
public receivedOutputController = new EventEmitter<string>();

private worker = new Worker(new URL('./emulator.worker', import.meta.url));
private worker;

private asyncCallbacks = new Map<number, Function>();

constructor() {
interface FakeWorker {
new (url: URL): Worker;
}
const Worker = function (url: URL) {
url.searchParams.set(isoUrlSearchParameter, environment.isoUrl);
return new window.Worker(url);
} as unknown as FakeWorker;
this.worker = new Worker(new URL('./emulator.worker', import.meta.url));

this.worker.onmessage = (event: MessageEvent<WorkerResponseMsg>) => {
let e = event.data;
if ('event' in e) {
Expand Down
8 changes: 4 additions & 4 deletions src/vm/emulator.worker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// <reference lib="webworker" />

// @ts-ignore
import { dynamic_import } from '../utils/misc';
import { isoUrlSearchParameter } from '../utils/literalConstants';

await dynamic_import('./lib/libv86.js');
importScripts('./lib/libv86.js');

interface MsgSendTerminal {
command: 'sendTerminal';
Expand Down Expand Up @@ -73,6 +72,7 @@ export type WorkerEventResponseMsg =
data: void;
};

const parameters = new URLSearchParams(location.search);
const emulator = new V86({
//Emulator binaries
wasm_path: 'lib/v86.wasm',
Expand Down Expand Up @@ -131,7 +131,7 @@ const emulator = new V86({
url: 'https://raw.githubusercontent.com/copy/v86/master/bios/vgabios.bin',
},
cdrom: {
url: './lib/rootfs.iso', //TODO: Use github url
url: parameters.get(isoUrlSearchParameter),
},
hda: null,
hdb: null,
Expand Down

0 comments on commit e165709

Please sign in to comment.