Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions localtypings/pxteditor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ declare namespace pxt.editor {
feedback?: FeedbackState;
themePickerOpen?: boolean;
errorListNote?: string;
timeMachine?: boolean;
}

export interface EditorState {
Expand Down
24 changes: 23 additions & 1 deletion webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,17 @@ export class ProjectView
restartSimulator: () => this.restartSimulator(),
singleSimulator: () => this.singleSimulator(),
onStateChanged: (state) => {
const simStateChanged = () => this.allEditors.forEach((editor) => editor.simStateChanged());
const simStateChanged = () => {
// If the simulator was pending a run when the user switched to
// a different view, stop the simulator to avoid running in the background
if (
state === pxsim.SimulatorState.Running &&
this.isSimulatorInaccessible()
) {
this.stopSimulator();
}
this.allEditors.forEach((editor) => editor.simStateChanged())
};
switch (state) {
case pxsim.SimulatorState.Paused:
case pxsim.SimulatorState.Unloaded:
Expand Down Expand Up @@ -4174,6 +4184,14 @@ export class ProjectView
})();
}

protected isSimulatorInaccessible() {
return this.state.home ||
this.state.extensionsVisible ||
this.profileDialog?.state?.visible ||
this.scriptSearch?.state.visible ||
this.state.timeMachine
}

openNewTab(hd: pxt.workspace.Header, dependent: boolean) {
if (!hd
|| pxt.BrowserUtils.isElectron()
Expand Down Expand Up @@ -4710,11 +4728,15 @@ export class ProjectView
this.stopSimulator();
}

this.setState({ timeMachine: true });

await dialogs.showTurnBackTimeDialogAsync(this.state.header, () => {
this.reloadHeaderAsync();
simWasRunning = false;
});

this.setState({ timeMachine: false });

if (simWasRunning) {
this.startSimulator();
}
Expand Down
Loading