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
8 changes: 4 additions & 4 deletions wpf/QuotaFloat.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<AssemblyName>QuotaFloat.Wpf</AssemblyName>
<RootNamespace>QuotaFloat.Wpf</RootNamespace>
<ApplicationIcon>Assets\QuoteFloat.ico</ApplicationIcon>
<Version>1.1.1</Version>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<FileVersion>1.1.1.0</FileVersion>
<InformationalVersion>1.1.1</InformationalVersion>
<Version>1.1.2</Version>
<AssemblyVersion>1.1.2.0</AssemblyVersion>
<FileVersion>1.1.2.0</FileVersion>
<InformationalVersion>1.1.2</InformationalVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
<DebugType>embedded</DebugType>
<Deterministic>true</Deterministic>
Expand Down
6 changes: 6 additions & 0 deletions wpf/Resources/UiText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public sealed record WidgetText(
string Synced,
string Refresh,
string Settings,
string TrayOpenSettings,
string TrayExit,
string SyncAutomationName,
string RefreshAutomationName,
string SettingsAutomationName,
Expand Down Expand Up @@ -47,6 +49,8 @@ public static WidgetText For(string language) => string.Equals(language, "en-US"
Synced: "已同步",
Refresh: "刷新",
Settings: "设置",
TrayOpenSettings: "打开设置",
TrayExit: "退出 Quote Float",
SyncAutomationName: "已同步",
RefreshAutomationName: "刷新",
SettingsAutomationName: "设置",
Expand Down Expand Up @@ -75,6 +79,8 @@ public static WidgetText For(string language) => string.Equals(language, "en-US"
Synced: "Synced",
Refresh: "Refresh",
Settings: "Settings",
TrayOpenSettings: "Open Settings",
TrayExit: "Exit Quote Float",
SyncAutomationName: "Synced",
RefreshAutomationName: "Refresh",
SettingsAutomationName: "Settings",
Expand Down
10 changes: 7 additions & 3 deletions wpf/Services/TrayIconService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using QuotaFloat.Wpf.Resources;

namespace QuotaFloat.Wpf.Services;

Expand All @@ -28,16 +29,18 @@ public sealed class TrayIconService : IDisposable

private readonly Action openSettings;
private readonly Action exitApplication;
private readonly Func<WidgetText> textProvider;
private readonly HwndSource hwndSource;
private readonly uint iconId = 0x5146;
private IntPtr productIcon;
private bool disposed;
private bool iconAdded;

public TrayIconService(Window owner, Action openSettings, Action exitApplication)
public TrayIconService(Window owner, Action openSettings, Action exitApplication, Func<WidgetText> textProvider)
{
this.openSettings = openSettings;
this.exitApplication = exitApplication;
this.textProvider = textProvider;

var hwnd = new WindowInteropHelper(owner).Handle;
hwndSource = HwndSource.FromHwnd(hwnd)
Expand Down Expand Up @@ -153,8 +156,9 @@ private void ShowContextMenu(IntPtr hwnd)

try
{
AppendMenu(menu, MfString | MfEnabled, OpenSettingsCommandId, "打开设置");
AppendMenu(menu, MfString | MfEnabled, ExitCommandId, "退出 Quote Float");
var text = textProvider();
AppendMenu(menu, MfString | MfEnabled, OpenSettingsCommandId, text.TrayOpenSettings);
AppendMenu(menu, MfString | MfEnabled, ExitCommandId, text.TrayExit);
SetForegroundWindow(hwnd);
if (!GetCursorPos(out var point))
{
Expand Down
3 changes: 2 additions & 1 deletion wpf/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ private void MainWindow_OnSourceInitialized(object? sender, EventArgs e)
var hwnd = new WindowInteropHelper(this).Handle;
hwndSource = HwndSource.FromHwnd(hwnd);
hwndSource?.AddHook(MainWindowWndProc);
trayIconService = new TrayIconService(this, ShowSettings, ExitApplication);
trayIconService = new TrayIconService(this, ShowSettings, ExitApplication,
() => WidgetText.For(preferenceStore.Current.Language));
widgetController.ApplyState(widgetController.State);
}

Expand Down
2 changes: 1 addition & 1 deletion wpf/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.1.1.0" name="QuotaFloat.Wpf.app" />
<assemblyIdentity version="1.1.2.0" name="QuotaFloat.Wpf.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
Expand Down
12 changes: 11 additions & 1 deletion wpf/tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ void Check(bool condition, string label)

Check(QuotaDisplayState.LoadingState.Status == QuotaUiStatus.Loading && QuotaDisplayState.LoadingState.ActiveRequests == 1, "loading state is explicit");
Check(WidgetText.For("en-US").Status(QuotaUiStatus.Stale, true) == "Refreshing" && WidgetText.For("zh-Hans").Status(QuotaUiStatus.Stale, true) == "刷新中", "refreshing copy is localized");
var trayLanguage = "zh-Hans";
Func<WidgetText> trayText = () => WidgetText.For(trayLanguage);
Check(trayText().TrayOpenSettings == "打开设置" && trayText().TrayExit == "退出 Quote Float",
"Chinese tray labels are exact");
trayLanguage = "en-US";
Check(trayText().TrayOpenSettings == "Open Settings" && trayText().TrayExit == "Exit Quote Float",
"English tray labels are exact");
trayLanguage = "zh-Hans";
Check(trayText().TrayOpenSettings == "打开设置" && trayText().TrayExit == "退出 Quote Float",
"tray labels refresh dynamically from current language");

var refreshingSnapshot = new QuotaSnapshot("Plus", new QuotaWindow(72, DateTimeOffset.UtcNow.AddHours(1), 18000, "5h"), new QuotaWindow(38, DateTimeOffset.UtcNow.AddDays(2), 604800, "Weekly"), 2, Array.Empty<DateTimeOffset>(), DateTimeOffset.UtcNow);
using var refreshingSource = new GateAfterFirstSource(refreshingSnapshot);
Expand Down Expand Up @@ -292,7 +302,7 @@ void Check(bool condition, string label)
}

Console.WriteLine("PASS: QF-WPF-009 focused fixtures and orchestration checks");
Console.WriteLine($"RESULTS: fixtures=35; checks={checkCount}; activeRequests={source.MaxActive}; refreshCalls={source.CallCount}; backoffCalls={backoffSource.CallCount}; privacy=normalized-values-only");
Console.WriteLine($"RESULTS: fixtures=36; checks={checkCount}; activeRequests={source.MaxActive}; refreshCalls={source.CallCount}; backoffCalls={backoffSource.CallCount}; privacy=normalized-values-only");
return 0;

sealed class ManualTimeProvider : TimeProvider
Expand Down