Skip to content

Commit

Permalink
use the downloaded sim.html instead of hitting the live sim
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Mar 4, 2025
1 parent a752d7d commit e0ba146
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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

0 comments on commit e0ba146

Please sign in to comment.