Skip to content

Commit

Permalink
use the downloaded sim.html instead of hitting the live sim (#185)
Browse files Browse the repository at this point in the history
* use the downloaded sim.html instead of hitting the live sim

* bump mkc
  • Loading branch information
riknoll authored Mar 4, 2025
1 parent a752d7d commit c88505d
Show file tree
Hide file tree
Showing 4 changed files with 1,392 additions and 1,239 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@
"dependencies": {
"@types/path-browserify": "^1.0.0",
"@vscode/extension-telemetry": "^0.7.5",
"makecode-browser": "^1.2.1",
"makecode-core": "^1.4.3",
"makecode-browser": "^1.3.1",
"makecode-core": "^1.7.0",
"path-browserify": "^1.0.1"
}
}
4 changes: 4 additions & 0 deletions src/web/makecodeOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export function addDependencyAsync(folder: vscode.WorkspaceFolder, repo: string,
return enqueueOperationAsync(folder, () => cmd.addCommand(repo, undefined as any /* the name is optional */, {}), cancellationToken);
}

export function getSimHtmlAsync(folder: vscode.WorkspaceFolder, cancellationToken?: vscode.CancellationToken) {
return enqueueOperationAsync(folder, () => cmd.getSimHTML({}), cancellationToken);
}

/**
* The mkc CLI uses global state, so we need to perform operations in a queue just in case the
* user is doing things in multiple workspaces at once
Expand Down
12 changes: 8 additions & 4 deletions src/web/simulator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as vscode from "vscode";

import { simloaderFiles } from "makecode-core/built/simloaderfiles";
import { existsAsync, readFileAsync } from "./host";
import { activeWorkspace, existsAsync, readFileAsync } from "./host";
import { simulateCommand } from "./extension";
import { getSimHtmlAsync } from "./makecodeOperations";

let extensionContext: vscode.ExtensionContext;

Expand Down Expand Up @@ -54,6 +55,7 @@ export class Simulator {

protected panel: vscode.WebviewPanel;
protected binaryJS: string | undefined;
protected simHtml: string | undefined;
protected disposables: vscode.Disposable[];

private constructor(panel: vscode.WebviewPanel) {
Expand All @@ -77,7 +79,8 @@ export class Simulator {
async simulateAsync(binaryJS: string) {
this.binaryJS = binaryJS;
this.panel.webview.html = "";
const simulatorHTML = await getSimHtmlAsync();
const simulatorHTML = await getSimLoaderHtmlAsync();
this.simHtml = await getSimHtmlAsync(activeWorkspace());
if (this.simState == null) {
this.simState = await extensionContext.workspaceState.get("simstate", {});
}
Expand All @@ -99,7 +102,8 @@ export class Simulator {
case "fetch-js":
this.postMessage({
...message,
text: this.binaryJS
text: this.binaryJS,
srcDoc: this.simHtml
});
break;
case "bulkserial":
Expand Down Expand Up @@ -151,7 +155,7 @@ window.addEventListener("DOMContentLoaded", () => {
`;


async function getSimHtmlAsync() {
async function getSimLoaderHtmlAsync() {
const index = simloaderFiles["index.html"];
const loaderJs = simloaderFiles["loader.js"];
let customJs = simloaderFiles["custom.js"];
Expand Down
Loading

0 comments on commit c88505d

Please sign in to comment.