Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Dev14/ExtensionUtils/StatusbarControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -9,12 +10,15 @@ namespace WakaTime.ExtensionUtils
internal class StatusbarControl : TextBlock
{
private const string Icon = "🕑";
private const string DefaultDashboardUrl = "https://wakatime.com/";

private readonly Brush _normalBackground = new SolidColorBrush(Colors.Transparent);
private readonly Brush _hoverBackground = new SolidColorBrush(Colors.White) { Opacity = 0.2 };
private readonly string _dashboardUrl;

public StatusbarControl()
public StatusbarControl(string apiUrl)
{
_dashboardUrl = GetDashboardUrl(apiUrl);
Text = Icon;
Foreground = new SolidColorBrush(Colors.White);
Background = _normalBackground;
Expand All @@ -38,10 +42,30 @@ public StatusbarControl()
MouseLeftButtonUp += (s, e) =>
{
// Open WakaTime in browser
System.Diagnostics.Process.Start("https://wakatime.com/");
System.Diagnostics.Process.Start(_dashboardUrl);
};
}

private static string GetDashboardUrl(string apiUrl)
{
if (string.IsNullOrWhiteSpace(apiUrl))
return DefaultDashboardUrl;

if (!Uri.TryCreate(apiUrl, UriKind.Absolute, out var apiUri))
return DefaultDashboardUrl;

var host = apiUri.Host.StartsWith("api.", StringComparison.OrdinalIgnoreCase)
? apiUri.Host.Substring(4)
: apiUri.Host;

var dashboardUriBuilder = new UriBuilder(apiUri.Scheme, host, apiUri.IsDefaultPort ? -1 : apiUri.Port)
{
Path = "/"
};

return dashboardUriBuilder.Uri.AbsoluteUri;
}

public void SetText(string text)
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand Down
2 changes: 1 addition & 1 deletion Dev14/WakaTimePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private async Task InitializeAsync(CancellationToken cancellationToken)
if (_wakatime.Config.GetSettingAsBoolean("status_bar_enabled", true))
{
// Inject control to status bar
_statusbarControl = new StatusbarControl();
_statusbarControl = new StatusbarControl(_wakatime.Config.GetSetting("api_url"));
_statusbarControl.SetText("Initializing...");
_statusbarControl.SetToolTip("WakaTime: Initializing...");
await StatusbarInjector.InjectControlAsync(_statusbarControl);
Expand Down
28 changes: 26 additions & 2 deletions Dev16/ExtensionUtils/StatusbarControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -9,12 +10,15 @@ namespace WakaTime.ExtensionUtils
internal class StatusbarControl : TextBlock
{
private const string Icon = "🕑";
private const string DefaultDashboardUrl = "https://wakatime.com/";

private readonly Brush _normalBackground = new SolidColorBrush(Colors.Transparent);
private readonly Brush _hoverBackground = new SolidColorBrush(Colors.White) { Opacity = 0.2 };
private readonly string _dashboardUrl;

public StatusbarControl()
public StatusbarControl(string apiUrl)
{
_dashboardUrl = GetDashboardUrl(apiUrl);
Text = Icon;
Foreground = new SolidColorBrush(Colors.White);
Background = _normalBackground;
Expand All @@ -38,10 +42,30 @@ public StatusbarControl()
MouseLeftButtonUp += (s, e) =>
{
// Open WakaTime in browser
System.Diagnostics.Process.Start("https://wakatime.com/");
System.Diagnostics.Process.Start(_dashboardUrl);
};
}

private static string GetDashboardUrl(string apiUrl)
{
if (string.IsNullOrWhiteSpace(apiUrl))
return DefaultDashboardUrl;

if (!Uri.TryCreate(apiUrl, UriKind.Absolute, out var apiUri))
return DefaultDashboardUrl;

var host = apiUri.Host.StartsWith("api.", StringComparison.OrdinalIgnoreCase)
? apiUri.Host.Substring(4)
: apiUri.Host;

var dashboardUriBuilder = new UriBuilder(apiUri.Scheme, host, apiUri.IsDefaultPort ? -1 : apiUri.Port)
{
Path = "/"
};

return dashboardUriBuilder.Uri.AbsoluteUri;
}

public void SetText(string text)
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand Down
2 changes: 1 addition & 1 deletion Dev16/WakaTimePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private async Task InitializeAsync(CancellationToken cancellationToken)
if (_wakatime.Config.GetSettingAsBoolean("status_bar_enabled", true))
{
// Inject control to status bar
_statusbarControl = new StatusbarControl();
_statusbarControl = new StatusbarControl(_wakatime.Config.GetSetting("api_url"));
_statusbarControl.SetText("Initializing...");
_statusbarControl.SetToolTip("WakaTime: Initializing...");
await StatusbarInjector.InjectControlAsync(_statusbarControl);
Expand Down
28 changes: 26 additions & 2 deletions Dev17/ExtensionUtils/StatusbarControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -9,12 +10,15 @@ namespace WakaTime.ExtensionUtils
internal class StatusbarControl : TextBlock
{
private const string Icon = "🕑";
private const string DefaultDashboardUrl = "https://wakatime.com/";

private readonly Brush _normalBackground = new SolidColorBrush(Colors.Transparent);
private readonly Brush _hoverBackground = new SolidColorBrush(Colors.White) { Opacity = 0.2 };
private readonly string _dashboardUrl;

public StatusbarControl()
public StatusbarControl(string apiUrl)
{
_dashboardUrl = GetDashboardUrl(apiUrl);
Text = Icon;
Foreground = new SolidColorBrush(Colors.White);
Background = _normalBackground;
Expand All @@ -38,10 +42,30 @@ public StatusbarControl()
MouseLeftButtonUp += (s, e) =>
{
// Open WakaTime in browser
System.Diagnostics.Process.Start("https://wakatime.com/");
System.Diagnostics.Process.Start(_dashboardUrl);
};
}

private static string GetDashboardUrl(string apiUrl)
{
if (string.IsNullOrWhiteSpace(apiUrl))
return DefaultDashboardUrl;

if (!Uri.TryCreate(apiUrl, UriKind.Absolute, out var apiUri))
return DefaultDashboardUrl;

var host = apiUri.Host.StartsWith("api.", StringComparison.OrdinalIgnoreCase)
? apiUri.Host.Substring(4)
: apiUri.Host;

var dashboardUriBuilder = new UriBuilder(apiUri.Scheme, host, apiUri.IsDefaultPort ? -1 : apiUri.Port)
{
Path = "/"
};

return dashboardUriBuilder.Uri.AbsoluteUri;
}

public void SetText(string text)
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand Down
2 changes: 1 addition & 1 deletion Dev17/WakaTimePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private async Task InitializeAsync(CancellationToken cancellationToken)
if (_wakatime.Config.GetSettingAsBoolean("status_bar_enabled", true))
{
// Inject control to status bar
_statusbarControl = new StatusbarControl();
_statusbarControl = new StatusbarControl(_wakatime.Config.GetSetting("api_url"));
_statusbarControl.SetText("Initializing...");
_statusbarControl.SetToolTip("WakaTime: Initializing...");
await StatusbarInjector.InjectControlAsync(_statusbarControl);
Expand Down
Loading