Skip to content

Commit

Permalink
feat(ux): 🚸 display currently running timer at top level (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jul 4, 2023
1 parent 92d2cea commit aacbd2f
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,14 @@ internal async ValueTask<List<Result>> _GetCommands(CancellationToken token, Que
},
};

if (await this._GetRunningTimeEntry(token) is null)
var me = (await this._GetMe(token))?.ToMe();
if (me is null)
{
return this.NotifyUnknownError();
}

var runningTimeEntry = (await this._GetRunningTimeEntry(token))?.ToTimeEntry(me);
if (runningTimeEntry is null)
{
return (string.IsNullOrEmpty(query.FirstSearch))
? results
Expand All @@ -722,15 +729,49 @@ internal async ValueTask<List<Result>> _GetCommands(CancellationToken token, Que

results.Add(new Result
{
Title = Settings.StopCommand,
SubTitle = "Stop the current time entry",
IcoPath = "stop.png",
Title = $"Stop {runningTimeEntry.GetDescription()}",
SubTitle = $"{runningTimeEntry.Project?.WithClientName ?? Settings.NoProjectName} | {runningTimeEntry.HumanisedElapsed} ({runningTimeEntry.DetailedElapsed})",
IcoPath = this._colourIconProvider.GetColourIcon(runningTimeEntry.Project?.Colour, "stop.png"),
AutoCompleteText = $"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.StopCommand} ",
Score = 15050,
Action = _ =>
Action = context =>
{
this._context.API.ChangeQuery($"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.StopCommand} ");
return false;
if (!context.SpecialKeyState.AltPressed)
{
this._context.API.ChangeQuery($"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.StopCommand} ");
return false;
}
// Alt key modifier will stop the time entry now
Task.Run(async delegate
{
try
{
this._context.API.LogInfo("TogglTrack", $"{this._state.SelectedIds.Project}, {runningTimeEntry.Id}, {runningTimeEntry.WorkspaceId}, {runningTimeEntry.StartDate}, {runningTimeEntry.DetailedElapsed}, from commands");
var stoppedTimeEntry = (await this._client.StopTimeEntry(
workspaceId: runningTimeEntry.WorkspaceId,
id: runningTimeEntry.Id
))?.ToTimeEntry(me);
if (stoppedTimeEntry?.Id is null)
{
throw new Exception("An API error was encountered.");
}
this.ShowSuccessMessage($"Stopped {stoppedTimeEntry.GetRawDescription()}", $"{runningTimeEntry.DetailedElapsed} elapsed", "stop.png");
// Update cached running time entry state
this.RefreshCache();
}
catch (Exception exception)
{
this._context.API.LogException("TogglTrack", "Failed to stop time entry", exception);
this.ShowErrorMessage("Failed to stop time entry.", exception.Message);
}
});
return true;
}
});

Expand Down Expand Up @@ -782,7 +823,7 @@ private async ValueTask<List<Result>> _GetStartResults(CancellationToken token,
return false;
}
// Alt key modifier will continue the time entry now
// Alt key modifier will start the time entry now
Task.Run(async delegate
{
long? projectId = null;
Expand Down Expand Up @@ -907,7 +948,7 @@ private async ValueTask<List<Result>> _GetStartResults(CancellationToken token,
return false;
}
// Alt key modifier will continue the time entry now
// Alt key modifier will start the time entry now
Task.Run(async delegate
{
long projectId = project.Id;
Expand Down

0 comments on commit aacbd2f

Please sign in to comment.