Skip to content

Commit d44343c

Browse files
committed
Fix #288, Ext freeze after run command multi trigger
Signed-off-by: paulober <[email protected]>
1 parent e6a7dd5 commit d44343c

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

src/activator.mts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default class Activator {
6565
private commandExecuting = false;
6666

6767
private disableExtWarning = false;
68+
private statusbarMsgDisposable?: vscode.Disposable;
6869

6970
constructor() {
7071
this.logger = new Logger("Activator");
@@ -542,13 +543,16 @@ export default class Activator {
542543
}
543544
}
544545

546+
if (await this.checkForRunningOperation()) {
547+
return;
548+
}
549+
545550
const forceDisableSoftReset =
546551
this.settings?.getBoolean(SettingsKey.noSoftResetOnRun) ?? false;
547552

548553
if (!noSoftReset && !forceDisableSoftReset) {
549554
await PicoMpyCom.getInstance().softReset();
550555
}
551-
await focusTerminal(this.terminalOptions);
552556
// TODO: maybe freeze terminal until this operation runs to prevent user input
553557
const data = await PicoMpyCom.getInstance().runFile(
554558
file,
@@ -557,6 +561,7 @@ export default class Activator {
557561
return;
558562
}
559563

564+
void focusTerminal(this.terminalOptions);
560565
this.commandExecuting = true;
561566
this.terminal?.cleanAndStore();
562567
this.ui?.userOperationStarted();
@@ -610,6 +615,11 @@ export default class Activator {
610615

611616
return;
612617
}
618+
619+
if (await this.checkForRunningOperation()) {
620+
return;
621+
}
622+
613623
const forceDisableSoftReset =
614624
this.settings?.getBoolean(SettingsKey.noSoftResetOnRun) ?? false;
615625

@@ -2172,4 +2182,47 @@ export default class Activator {
21722182
);
21732183
}
21742184
}
2185+
2186+
/**
2187+
* Checks if there is a running operation and asks the user if it should be canceled.
2188+
*
2189+
* @returns `true` if the user does not want to cancel the already running
2190+
* operation, `false` otherwise.
2191+
*/
2192+
private async checkForRunningOperation(): Promise<boolean> {
2193+
if (this.commandExecuting) {
2194+
// ask user if it want to cancel running operation or cancel the new one
2195+
const choice = await vscode.window.showWarningMessage(
2196+
"An operation is already running. Do you want to cancel it?",
2197+
{
2198+
modal: true,
2199+
},
2200+
"Yes",
2201+
"No"
2202+
);
2203+
2204+
if (choice === "Yes") {
2205+
if (this.commandExecuting) {
2206+
PicoMpyCom.getInstance().interruptExecution();
2207+
2208+
// wait for 500ms for operation to stop and clean up local state
2209+
await new Promise(resolve => setTimeout(resolve, 500));
2210+
}
2211+
} else {
2212+
if (this.statusbarMsgDisposable) {
2213+
this.statusbarMsgDisposable.dispose();
2214+
}
2215+
2216+
// void vscode.window.showWarningMessage("Operation canceled.");
2217+
this.statusbarMsgDisposable = vscode.window.setStatusBarMessage(
2218+
"Operation canceled.",
2219+
5000
2220+
);
2221+
2222+
return true;
2223+
}
2224+
}
2225+
2226+
return false;
2227+
}
21752228
}

src/logger.mts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { window } from "vscode";
2-
import type { LogOutputChannel } from "vscode";
1+
import { env, window } from "vscode";
2+
import { type LogOutputChannel, LogLevel as VSCodeLogLevel } from "vscode";
33

44
type LogLevel = "info" | "warn" | "error" | "debug";
55

@@ -21,6 +21,19 @@ interface Stringable {
2121
toString(): string;
2222
}
2323

24+
function customLogLevelToVscode(logLevel: LogLevel): VSCodeLogLevel {
25+
switch (logLevel) {
26+
case "info":
27+
return VSCodeLogLevel.Info;
28+
case "warn":
29+
return VSCodeLogLevel.Warning;
30+
case "error":
31+
return VSCodeLogLevel.Error;
32+
case "debug":
33+
return VSCodeLogLevel.Debug;
34+
}
35+
}
36+
2437
export default class Logger {
2538
private className: string;
2639
private static outputChannel?: LogOutputChannel;
@@ -33,6 +46,7 @@ export default class Logger {
3346
/*Logger.outputChannel = window.createOutputChannel("Pico-W-Go", {
3447
log: true,
3548
});*/
49+
//env.logLevel = customLogLevelToVscode(logLevel);
3650
Logger.outputChannel = window.createOutputChannel("MicroPico", {
3751
log: true,
3852
});

src/ui.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default class UI {
5050
item.tooltip
5151
);
5252
}
53+
this.statusbarItemPriority = Object.keys(this.items).length;
5354

5455
this.setState(false);
5556

@@ -128,7 +129,7 @@ export default class UI {
128129
return;
129130
}
130131

131-
private statusbarItemPriority = 11;
132+
private statusbarItemPriority = 14;
132133

133134
private createStatusBarItem(
134135
key: string,

0 commit comments

Comments
 (0)