Skip to content

Commit

Permalink
💾 Feat(MainWindow): More info in tray icon tip text.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynesshely committed Jun 14, 2023
1 parent e7fd002 commit 26bd227
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
51 changes: 49 additions & 2 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using Avalonia.Controls;
using Avalonia;
using Avalonia.Controls;
using KitX_Dashboard.Data;
using KitX_Dashboard.Managers;
using KitX_Dashboard.Services;
using KitX_Dashboard.Views;
using ReactiveUI;
using System.ComponentModel;
using System.Reactive;
using System.Reflection;
using System.Text;

namespace KitX_Dashboard.ViewModels;

internal class MainWindowViewModel : ViewModelBase
internal class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged
{
public new event PropertyChangedEventHandler? PropertyChanged;

public MainWindowViewModel()
{
InitCommands();

InitEvents();
}

internal void InitCommands()
Expand Down Expand Up @@ -53,6 +60,46 @@ internal void InitCommands()
});
}

private void InitEvents()
{
Program.DeviceCards.CollectionChanged += (_, _) =>
{
PropertyChanged?.Invoke(this, new(nameof(TrayIconText)));
};
}

internal static string TrayIconText
{
get
{
var sb = new StringBuilder();

sb.AppendLine(
FetchStringFromResource(Application.Current, "Text_MainWindow_Title") ?? "KitX"
);

sb.AppendLine($"v{Assembly.GetEntryAssembly()?.GetName().Version}");

sb.AppendLine();

sb.AppendLine(
$"{Program.DeviceCards.Count} " +
$"{FetchStringFromResource(Application.Current, "Text_Device_Tip_Detected")}"
);

sb.AppendLine(
$"{Program.PluginCards.Count} " +
$"{FetchStringFromResource(Application.Current, "Text_Lib_Tip_Connected")}"
);

sb.AppendLine();

sb.Append("Hello, World!");

return sb.ToString();
}
}

internal ReactiveCommand<object?, Unit>? TrayIconClickedCommand { get; set; }

internal ReactiveCommand<object?, Unit>? ExitCommand { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
CommandParameter="{DynamicResource MainWindow}"
Icon="resm:KitX_Dashboard.Assets.KitX-Icon-256x256.ico"
IsVisible="True"
ToolTipText="{DynamicResource Text_MainWindow_Title}">
ToolTipText="{Binding TrayIconText}">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Command="{Binding TrayIconClickedCommand}"
Expand Down

0 comments on commit 26bd227

Please sign in to comment.