Skip to content

Commit 0f7a505

Browse files
committed
Fixed a regression bug where running the same "monitor" causes the notification that the task "is already active" // Resolve platformio#3656
1 parent ddef207 commit 0f7a505

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 3.1.1 (2023-03-??)
4+
5+
* Fixed a regression bug where running the same "monitor" causes the notification that the task "is already active" (issue [#3656](https://github.com/platformio/platformio-vscode-ide/issues/3656))
6+
37
## 3.1.0 (2023-03-13)
48

59
* Add support for the ``${command:platformio-ide.activeEnvironment}`` variable that can be used in a custom [PlatformIO Toolbar](https://docs.platformio.org/en/latest/integration/ide/vscode.html#platformio-toolbar) and [VSCode variable substitution](https://code.visualstudio.com/docs/editor/variables-reference) (issue [#3588](https://github.com/platformio/platformio-vscode-ide/issues/3588))

src/project/tasks.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export default class ProjectTaskManager {
9090
},
9191
}),
9292

93-
vscode.tasks.onDidStartTask((event) => this.onDidStartTask(event)),
9493
vscode.tasks.onDidEndTaskProcess((event) => this.onDidEndTaskProcess(event))
9594
);
9695

@@ -149,22 +148,15 @@ export default class ProjectTaskManager {
149148
}
150149

151150
runTask(task) {
151+
this._autoCloseSerialMonitor(task);
152152
// use string-based task defination for Win 7 // issue #3481
153153
vscode.commands.executeCommand(
154154
'workbench.action.tasks.runTask',
155155
`${ProjectTaskManager.PROVIDER_TYPE}: ${task.id}`
156156
);
157157
}
158158

159-
onDidStartTask(event) {
160-
this._autoCloseSerialMonitor(event.execution.task);
161-
}
162-
163159
async _autoCloseSerialMonitor(startedTask) {
164-
if (startedTask.definition.type !== ProjectTaskManager.PROVIDER_TYPE) {
165-
return;
166-
}
167-
168160
this._startedTask = startedTask;
169161
this._tasksToRestore = [];
170162
const closeMonitorConds = [
@@ -186,18 +178,20 @@ export default class ProjectTaskManager {
186178
// }
187179

188180
vscode.tasks.taskExecutions.forEach((event) => {
189-
const isCurrentEvent = this.areTasksEqual(this._startedTask, event.task);
181+
const isCurrentTask = this.areTasksEqual(this._startedTask, event.task);
190182
const skipConds = [
191-
isCurrentEvent,
192183
// skip non-PlatformIO task
193184
event.task.definition.type !== ProjectTaskManager.PROVIDER_TYPE,
194185
!this.getTaskArgs(event.task).includes('monitor'),
195-
this.isMonitorAndUploadTask(event.task),
186+
this.isMonitorAndUploadTask(event.task) && !isCurrentTask,
196187
];
197188
if (skipConds.some((value) => value)) {
198189
return;
199190
}
200-
this._tasksToRestore.push(event.task);
191+
// do not restart the same tasks
192+
if (!isCurrentTask) {
193+
this._tasksToRestore.push(event.task);
194+
}
201195
event.terminate();
202196
});
203197
}

0 commit comments

Comments
 (0)