hint when promoted

This commit is contained in:
Lightczx
2024-05-21 17:05:55 +08:00
parent 1bf517f95d
commit 784c727a38
6 changed files with 51 additions and 2 deletions

View File

@@ -50,6 +50,11 @@ internal sealed class NotifyIconController : IDisposable
xamlHostWindow.Dispose();
}
public RECT GetRect()
{
return NotifyIconMethods.GetRect(id, messageWindow.HWND);
}
private void OnRecreateNotifyIconRequested(NotifyIconMessageWindow window)
{
NotifyIconMethods.Delete(id);
@@ -81,7 +86,6 @@ internal sealed class NotifyIconController : IDisposable
[SuppressMessage("", "SH002")]
private void OnContextMenuRequested(NotifyIconMessageWindow window, PointUInt16 point)
{
RECT iconRect = NotifyIconMethods.GetRect(id, window.HWND);
xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), iconRect);
xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), GetRect());
}
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.WinUI.Notifications;
using Microsoft.UI;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Content;
@@ -11,6 +12,7 @@ using Microsoft.UI.Xaml.Media;
using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Core.Windowing.Abstraction;
using Snap.Hutao.Core.Windowing.NotifyIcon;
using Snap.Hutao.Service;
using Snap.Hutao.Win32;
using Snap.Hutao.Win32.Foundation;
@@ -102,6 +104,15 @@ internal sealed class XamlWindowController
args.Handled = true;
window.Hide();
RECT iconRect = serviceProvider.GetRequiredService<NotifyIconController>().GetRect();
RECT primaryRect = StructMarshal.RECT(DisplayArea.Primary.OuterBounds);
if (!IntersectRect(out _, in primaryRect, in iconRect))
{
new ToastContentBuilder()
.AddText(SH.CoreWindowingNotifyIconPromotedHint)
.Show();
}
ICurrentXamlWindowReference currentXamlWindowReference = serviceProvider.GetRequiredService<ICurrentXamlWindowReference>();
if (currentXamlWindowReference.Window == window)
{

View File

@@ -198,6 +198,9 @@
<data name="CoreWindowingNotifyIconLaunchGameLabel" xml:space="preserve">
<value>启动游戏</value>
</data>
<data name="CoreWindowingNotifyIconPromotedHint" xml:space="preserve">
<value>胡桃已进入后台运行</value>
</data>
<data name="CoreWindowingNotifyIconViewLabel" xml:space="preserve">
<value>窗口</value>
</data>

View File

@@ -10,4 +10,12 @@ internal struct RECT
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}

View File

@@ -33,6 +33,11 @@ internal static class StructMarshal
return new(0, 0, size.X, size.Y);
}
public static RECT RECT(RectInt32 rect)
{
return new(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
}
public static RectInt32 RectInt32(RECT rect)
{
return new(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);

View File

@@ -125,6 +125,24 @@ internal static class User32
}
}
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern BOOL IntersectRect([Out] RECT* lprcDst, RECT* lprcSrc1, RECT* lprcSrc2);
public static unsafe BOOL IntersectRect(out RECT rcDst, ref readonly RECT rcSrc1, ref readonly RECT rcSrc2)
{
fixed (RECT* lprcDst = &rcDst)
{
fixed (RECT* lprcSrc1 = &rcSrc1)
{
fixed (RECT* lprcSrc2 = &rcSrc2)
{
return IntersectRect(lprcDst, lprcSrc1, lprcSrc2);
}
}
}
}
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL IsIconic(HWND hWnd);