Skip to content

Commit 8548abf

Browse files
authored
feat: 通知区域图标菜单支持定时缩放 (Blinue#1042)
1 parent 836d240 commit 8548abf

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

‎src/Magpie/HomeViewModel.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ bool HomeViewModel::IsNotRunning() const noexcept {
7676
}
7777

7878
void HomeViewModel::ToggleTimer() const noexcept {
79-
ScalingService& ScalingService = ScalingService::Get();
80-
if (ScalingService.IsTimerOn()) {
81-
ScalingService.StopTimer();
79+
ScalingService& scalingService = ScalingService::Get();
80+
if (scalingService.IsTimerOn()) {
81+
scalingService.StopTimer();
8282
} else {
83-
ScalingService.StartTimer();
83+
scalingService.StartTimer();
8484
}
8585
}
8686

‎src/Magpie/NotifyIconService.cpp‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#include "resource.h"
66
#include "App.h"
77
#include <CommCtrl.h>
8+
#include "ScalingService.h"
89

910
using namespace winrt::Magpie::implementation;
11+
using namespace winrt;
1012

1113
namespace Magpie {
1214

@@ -106,14 +108,22 @@ LRESULT NotifyIconService::_NotifyIconWndProc(HWND hWnd, UINT message, WPARAM wP
106108
}
107109
case WM_RBUTTONUP:
108110
{
109-
winrt::ResourceLoader resourceLoader =
110-
winrt::ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
111-
winrt::hstring mainWindowText = resourceLoader.GetString(L"NotifyIcon_MainWindow");
112-
winrt::hstring exitText = resourceLoader.GetString(L"NotifyIcon_Exit");
113-
114111
wil::unique_hmenu hMenu(CreatePopupMenu());
112+
113+
ResourceLoader resourceLoader =
114+
ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
115+
hstring mainWindowText = resourceLoader.GetString(L"NotifyIcon_MainWindow");
115116
AppendMenu(hMenu.get(), MF_STRING, 1, mainWindowText.c_str());
116-
AppendMenu(hMenu.get(), MF_STRING, 2, exitText.c_str());
117+
118+
hstring fmtStr = resourceLoader.GetString(L"Home_Activation_Timer_ButtonText");
119+
std::wstring timerText = fmt::format(
120+
fmt::runtime(std::wstring_view(fmtStr)),
121+
AppSettings::Get().CountdownSeconds()
122+
);
123+
AppendMenu(hMenu.get(), MF_STRING, 2, timerText.c_str());
124+
125+
hstring exitText = resourceLoader.GetString(L"NotifyIcon_Exit");
126+
AppendMenu(hMenu.get(), MF_STRING, 3, exitText.c_str());
117127

118128
// hWnd 必须为前台窗口才能正确展示弹出菜单
119129
// 即使 hWnd 是隐藏的
@@ -137,6 +147,11 @@ LRESULT NotifyIconService::_NotifyIconWndProc(HWND hWnd, UINT message, WPARAM wP
137147
break;
138148
}
139149
case 2:
150+
{
151+
ScalingService::Get().StartTimer();
152+
break;
153+
}
154+
case 3:
140155
{
141156
App::Get().Quit();
142157
break;

0 commit comments

Comments
 (0)