@@ -19,8 +19,18 @@ class CEActiveTask: ObservableObject, Identifiable, Hashable {
1919 /// The name of the associated task.
2020 @ObservedObject var task : CETask
2121
22+ /// Prevents tasks overwriting each other.
23+ /// Say a user cancels one task, then runs it immediately, the cancel message should show and then the
24+ /// starting message should show. If we don't add this modifier the starting message will be deleted.
25+ var activeTaskID : String = UUID ( ) . uuidString
26+
27+ var taskId : String {
28+ task. id. uuidString + " - " + activeTaskID
29+ }
30+
2231 var process : Process ?
2332 var outputPipe : Pipe ?
33+ var workspaceURL : URL ?
2434
2535 private var cancellables = Set < AnyCancellable > ( )
2636
@@ -35,6 +45,8 @@ class CEActiveTask: ObservableObject, Identifiable, Hashable {
3545 }
3646
3747 func run( workspaceURL: URL ? = nil ) {
48+ self . workspaceURL = workspaceURL
49+ self . activeTaskID = UUID ( ) . uuidString // generate a new ID for this run
3850 Task {
3951 // Reconstruct the full command to ensure it executes in the correct directory.
4052 // Because: CETask only contains information about the relative path.
@@ -146,30 +158,33 @@ class CEActiveTask: ObservableObject, Identifiable, Hashable {
146158
147159 private func createStatusTaskNotification( ) {
148160 let userInfo : [ String : Any ] = [
149- " id " : self . task . id . uuidString ,
161+ " id " : taskId ,
150162 " action " : " createWithPriority " ,
151163 " title " : " Running \( self . task. name) " ,
152164 " message " : " Running your task: \( self . task. name) . " ,
153- " isLoading " : true
165+ " isLoading " : true ,
166+ " workspace " : workspaceURL as Any
154167 ]
155168
156169 NotificationCenter . default. post ( name: . taskNotification, object: nil , userInfo: userInfo)
157170 }
158171
159172 private func deleteStatusTaskNotification( ) {
160173 let deleteInfo : [ String : Any ] = [
161- " id " : " \( task . id . uuidString ) " ,
174+ " id " : taskId ,
162175 " action " : " deleteWithDelay " ,
163- " delay " : 3.0
176+ " delay " : 3.0 ,
177+ " workspace " : workspaceURL as Any
164178 ]
165179
166180 NotificationCenter . default. post ( name: . taskNotification, object: nil , userInfo: deleteInfo)
167181 }
168182
169183 private func updateTaskNotification( title: String ? = nil , message: String ? = nil , isLoading: Bool ? = nil ) {
170184 var userInfo : [ String : Any ] = [
171- " id " : task. id. uuidString,
172- " action " : " update "
185+ " id " : taskId,
186+ " action " : " update " ,
187+ " workspace " : workspaceURL as Any
173188 ]
174189 if let title {
175190 userInfo [ " title " ] = title
0 commit comments