Skip to content

Commit

Permalink
feat: 通知区域图标菜单支持定时缩放 (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue authored Dec 28, 2024
1 parent 836d240 commit 8548abf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Magpie/HomeViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ bool HomeViewModel::IsNotRunning() const noexcept {
}

void HomeViewModel::ToggleTimer() const noexcept {
ScalingService& ScalingService = ScalingService::Get();
if (ScalingService.IsTimerOn()) {
ScalingService.StopTimer();
ScalingService& scalingService = ScalingService::Get();
if (scalingService.IsTimerOn()) {
scalingService.StopTimer();
} else {
ScalingService.StartTimer();
scalingService.StartTimer();
}
}

Expand Down
27 changes: 21 additions & 6 deletions src/Magpie/NotifyIconService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include "resource.h"
#include "App.h"
#include <CommCtrl.h>
#include "ScalingService.h"

using namespace winrt::Magpie::implementation;
using namespace winrt;

namespace Magpie {

Expand Down Expand Up @@ -106,14 +108,22 @@ LRESULT NotifyIconService::_NotifyIconWndProc(HWND hWnd, UINT message, WPARAM wP
}
case WM_RBUTTONUP:
{
winrt::ResourceLoader resourceLoader =
winrt::ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
winrt::hstring mainWindowText = resourceLoader.GetString(L"NotifyIcon_MainWindow");
winrt::hstring exitText = resourceLoader.GetString(L"NotifyIcon_Exit");

wil::unique_hmenu hMenu(CreatePopupMenu());

ResourceLoader resourceLoader =
ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
hstring mainWindowText = resourceLoader.GetString(L"NotifyIcon_MainWindow");
AppendMenu(hMenu.get(), MF_STRING, 1, mainWindowText.c_str());
AppendMenu(hMenu.get(), MF_STRING, 2, exitText.c_str());

hstring fmtStr = resourceLoader.GetString(L"Home_Activation_Timer_ButtonText");
std::wstring timerText = fmt::format(
fmt::runtime(std::wstring_view(fmtStr)),
AppSettings::Get().CountdownSeconds()
);
AppendMenu(hMenu.get(), MF_STRING, 2, timerText.c_str());

hstring exitText = resourceLoader.GetString(L"NotifyIcon_Exit");
AppendMenu(hMenu.get(), MF_STRING, 3, exitText.c_str());

// hWnd 必须为前台窗口才能正确展示弹出菜单
// 即使 hWnd 是隐藏的
Expand All @@ -137,6 +147,11 @@ LRESULT NotifyIconService::_NotifyIconWndProc(HWND hWnd, UINT message, WPARAM wP
break;
}
case 2:
{
ScalingService::Get().StartTimer();
break;
}
case 3:
{
App::Get().Quit();
break;
Expand Down

0 comments on commit 8548abf

Please sign in to comment.