Skip to content

Commit

Permalink
Add support for custom server URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
eXpl0it3r committed Dec 31, 2022
1 parent 8030561 commit 7f6b77c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Clockify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<CodeAnalysisRuleSet>StyleCop.ruleset</CodeAnalysisRuleSet>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AssemblyVersion>1.4</AssemblyVersion>
<PackageVersion>1.4</PackageVersion>
<AssemblyVersion>1.5</AssemblyVersion>
<PackageVersion>1.5</PackageVersion>
<Title>Clockify</Title>
<Authors>Lukas Dürrenberger</Authors>
<Description>This plugin allows you to track, start and stop Clockify timers on your Elgato Stream Deck</Description>
Expand Down
14 changes: 11 additions & 3 deletions Clockify/ClockifyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Clockify
public class ClockifyContext
{
private string _apiKey = string.Empty;
private string _serverUrl = string.Empty;
private ClockifyClient _clockifyClient;
private CurrentUserDto _currentUser = new ();
private Dictionary<string, List<ProjectDtoImpl>> _projects = new ();
Expand Down Expand Up @@ -127,18 +128,25 @@ public async Task<TimeEntryDtoImpl> GetRunningTimerAsync(string workspaceName, s
return string.IsNullOrEmpty(timeName) ? timeEntries.Data.FirstOrDefault(t => t.ProjectId == project.Id) : timeEntries.Data.FirstOrDefault(t => t.ProjectId == project.Id && t.Description == timeName);
}

public async Task<bool> SetApiKeyAsync(string apiKey)
public async Task<bool> SetApiKeyAsync(string serverUrl, string apiKey)
{
if (_clockifyClient == null || apiKey != _apiKey)
if (_clockifyClient == null || apiKey != _apiKey || serverUrl != _serverUrl)
{
if (!Uri.IsWellFormedUriString(serverUrl, UriKind.Absolute))
{
Logger.Instance.LogMessage(TracingLevel.WARN, "Server URL is invalid");
return false;
}

if (apiKey.Length != 48)
{
Logger.Instance.LogMessage(TracingLevel.WARN, "Invalid API key format");
return false;
}

_serverUrl = serverUrl;
_apiKey = apiKey;
_clockifyClient = new ClockifyClient(_apiKey);
_clockifyClient = new ClockifyClient(_apiKey, serverUrl);
}

if (await TestConnectionAsync())
Expand Down
3 changes: 3 additions & 0 deletions Clockify/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ public class PluginSettings

[JsonProperty(PropertyName = "timerName")]
public string TimeName { get; set; } = string.Empty;

[JsonProperty(PropertyName = "serverUrl")]
public string ServerUrl { get; set; } = "https://api.clockify.me/api/v1";
}
}
4 changes: 2 additions & 2 deletions Clockify/ToggleAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override async void OnTick()
}
else if (_settings.ApiKey.Length == 48)
{
await _clockifyContext.SetApiKeyAsync(_settings.ApiKey);
await _clockifyContext.SetApiKeyAsync(_settings.ServerUrl, _settings.ApiKey);
}
}

Expand All @@ -86,7 +86,7 @@ public override async void ReceivedSettings(ReceivedSettingsPayload payload)
Tools.AutoPopulateSettings(_settings, payload.Settings);
Logger.Instance.LogMessage(TracingLevel.INFO, $"Settings Received: {_settings}");
await SaveSettings();
await _clockifyContext.SetApiKeyAsync(_settings.ApiKey);
await _clockifyContext.SetApiKeyAsync(_settings.ServerUrl, _settings.ApiKey);
}

public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
Expand Down
4 changes: 4 additions & 0 deletions PropertyInspector/PluginActionPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<div class="sdpi-item-label">Timer Name</div>
<input class="sdpi-item-value sdProperty" id="timerName" value="" placeholder="Enter the name of the Timer" oninput="setSettings()">
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Server Url</div>
<input class="sdpi-item-value sdProperty" id="serverUrl" value="https://api.clockify.me/api/v1" placeholder="Enter the ULR of the Server" oninput="setSettings()" required>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Until the plugin is available in the [Stream Deck Store](https://apps.elgato.com
- **Project Name:** *(optional)* Provide the name of an existing project to run/track a timer for
- **Task Name:** *(optional)* Set the name of the project specific task
- **Timer Name:** *(optional)* Specify a name for the timer you want to run/track
- **Server Url:** *(required)* Change from the *default* URL to the API URL of your own/company instance

https://user-images.githubusercontent.com/920861/132741561-6f9f3ff0-a920-408d-8279-579840ce0a6b.mp4

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"Description": "Stream Deck integration for Clockify, the most popular free time tracker available for an unlimited numbers of users for free.",
"Icon": "Images/clockifyIcon",
"URL": "https://duerrenberger.dev",
"Version": "1.4",
"Version": "1.5",
"CodePathWin": "Windows/dev.duerrenberger.clockify.exe",
"CodePathMac": "macOS/dev.duerrenberger.clockify",
"Category": "Time Tracking",
Expand Down

0 comments on commit 7f6b77c

Please sign in to comment.