@@ -121,12 +121,10 @@ public async Task<TimeEntryDtoImpl> GetRunningTimerAsync()
121
121
{
122
122
return null ;
123
123
}
124
-
125
- if ( string . IsNullOrEmpty ( _projectName ) )
124
+
125
+ if ( string . IsNullOrEmpty ( _projectName ) && string . IsNullOrEmpty ( _timerName ) )
126
126
{
127
- return string . IsNullOrEmpty ( _timerName )
128
- ? timeEntries . Data . FirstOrDefault ( )
129
- : timeEntries . Data . FirstOrDefault ( t => t . Description == _timerName ) ;
127
+ return timeEntries . Data . FirstOrDefault ( t => string . IsNullOrEmpty ( _timerName ) || t . Description == _timerName ) ;
130
128
}
131
129
132
130
var project = await FindMatchingProjectAsync ( workspace . Id ) ;
@@ -135,10 +133,12 @@ public async Task<TimeEntryDtoImpl> GetRunningTimerAsync()
135
133
{
136
134
return null ;
137
135
}
136
+
137
+ var task = await FindMatchingTaskAsync ( workspace . Id , project . Id , _taskName ) ;
138
138
139
- return string . IsNullOrEmpty ( _timerName )
140
- ? timeEntries . Data . FirstOrDefault ( t => t . ProjectId == project . Id )
141
- : timeEntries . Data . FirstOrDefault ( t => t . ProjectId == project . Id && t . Description == _timerName ) ;
139
+ return timeEntries . Data . FirstOrDefault ( t => t . ProjectId == project . Id
140
+ && ( string . IsNullOrEmpty ( _timerName ) || t . Description == _timerName )
141
+ && ( string . IsNullOrEmpty ( _taskName ) || string . IsNullOrEmpty ( task ) || t . TaskId == task ) ) ;
142
142
}
143
143
144
144
public async Task UpdateSettings ( PluginSettings settings )
@@ -258,18 +258,25 @@ private async Task<ProjectDtoImpl> FindMatchingProjectAsync(string workspaceId)
258
258
return project . Single ( ) ;
259
259
}
260
260
261
- private async Task < string > FindOrCreateTaskAsync ( string workspaceId , string projectId , string taskName )
261
+ private async Task < string > FindMatchingTaskAsync ( string workspaceId , string projectId , string taskName )
262
262
{
263
263
var taskResponse = await _clockifyClient . FindAllTasksAsync ( workspaceId , projectId , name : taskName , pageSize : 5000 ) ;
264
264
265
- if ( ! taskResponse . IsSuccessful || taskResponse . Data == null )
265
+ if ( ! taskResponse . IsSuccessful || taskResponse . Data == null || ! taskResponse . Data . Any ( ) )
266
266
{
267
267
return null ;
268
268
}
269
269
270
- if ( taskResponse . Data . Any ( ) )
270
+ return taskResponse . Data . First ( ) . Id ;
271
+ }
272
+
273
+ private async Task < string > FindOrCreateTaskAsync ( string workspaceId , string projectId , string taskName )
274
+ {
275
+ var task = await FindMatchingTaskAsync ( workspaceId , projectId , taskName ) ;
276
+
277
+ if ( ! string . IsNullOrEmpty ( task ) )
271
278
{
272
- return taskResponse . Data . First ( ) . Id ;
279
+ return task ;
273
280
}
274
281
275
282
var taskRequest = new TaskRequest
0 commit comments