diff --git a/Clockify.csproj b/Clockify.csproj index c492c1e..eee9871 100644 --- a/Clockify.csproj +++ b/Clockify.csproj @@ -10,8 +10,8 @@ StyleCop.ruleset false AllEnabledByDefault - 1.4 - 1.4 + 1.5 + 1.5 Clockify Lukas Dürrenberger This plugin allows you to track, start and stop Clockify timers on your Elgato Stream Deck diff --git a/Clockify/ClockifyContext.cs b/Clockify/ClockifyContext.cs index 15f1680..42eae7d 100644 --- a/Clockify/ClockifyContext.cs +++ b/Clockify/ClockifyContext.cs @@ -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> _projects = new (); @@ -127,18 +128,25 @@ public async Task 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 SetApiKeyAsync(string apiKey) + public async Task 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()) diff --git a/Clockify/PluginSettings.cs b/Clockify/PluginSettings.cs index d27d765..93fc038 100644 --- a/Clockify/PluginSettings.cs +++ b/Clockify/PluginSettings.cs @@ -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"; } } \ No newline at end of file diff --git a/Clockify/ToggleAction.cs b/Clockify/ToggleAction.cs index 4361755..46c53dd 100644 --- a/Clockify/ToggleAction.cs +++ b/Clockify/ToggleAction.cs @@ -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); } } @@ -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) diff --git a/PropertyInspector/PluginActionPI.html b/PropertyInspector/PluginActionPI.html index 03d9f29..14dac19 100644 --- a/PropertyInspector/PluginActionPI.html +++ b/PropertyInspector/PluginActionPI.html @@ -32,6 +32,10 @@
Timer Name
+
+
Server Url
+ +
diff --git a/README.md b/README.md index 7d78fd9..5795449 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/manifest.json b/manifest.json index be4e8db..2d25563 100644 --- a/manifest.json +++ b/manifest.json @@ -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",