Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dend committed Nov 27, 2024
1 parent d1d8a94 commit cc21240
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Threading;
using ManagedCommon;

using ManagedCommon;

namespace Awake.Core.Threading
{
internal sealed class SingleThreadSynchronizationContext : SynchronizationContext
Expand Down
16 changes: 7 additions & 9 deletions src/modules/awake/Awake/Core/TrayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ namespace Awake.Core
internal static class TrayHelper
{
private static NotifyIconData _notifyIconData;
private static IntPtr _trayMenu;
private static IntPtr _hiddenWindowHandle;
private static SingleThreadSynchronizationContext? _syncContext;
private static Thread? _mainThread;

private static IntPtr TrayMenu { get => _trayMenu; set => _trayMenu = value; }
private static IntPtr TrayMenu { get; set; }

internal static IntPtr HiddenWindowHandle { get => _hiddenWindowHandle; private set => _hiddenWindowHandle = value; }
internal static IntPtr HiddenWindowHandle { get; private set; }

static TrayHelper()
{
Expand All @@ -59,7 +57,7 @@ private static void ShowContextMenu(IntPtr hWnd)
Bridge.ScreenToClient(hWnd, ref cursorPos);

// Set menu information
var menuInfo = new MenuInfo
MenuInfo menuInfo = new()
{
CbSize = (uint)Marshal.SizeOf<MenuInfo>(),
FMask = Native.Constants.MIM_STYLE,
Expand Down Expand Up @@ -169,7 +167,7 @@ internal static void SetShellIcon(IntPtr hWnd, string text, Icon? icon, TrayIcon
break;
}

if (action == TrayIconAction.Add || action == TrayIconAction.Update)
if (action is TrayIconAction.Add or TrayIconAction.Update)
{
_notifyIconData = new NotifyIconData
{
Expand Down Expand Up @@ -240,7 +238,7 @@ private static int WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lPar
switch (message)
{
case Native.Constants.WM_USER:
if (lParam == (IntPtr)Native.Constants.WM_LBUTTONDOWN || lParam == (IntPtr)Native.Constants.WM_RBUTTONDOWN)
if (lParam is Native.Constants.WM_LBUTTONDOWN or Native.Constants.WM_RBUTTONDOWN)
{
// Show the context menu associated with the tray icon
ShowContextMenu(hWnd);
Expand Down Expand Up @@ -404,13 +402,13 @@ private static void EnsureDefaultTrayTimeShortcuts(Dictionary<string, int> trayT

private static void CreateAwakeTimeSubMenu(Dictionary<string, int> trayTimeShortcuts, bool isChecked = false)
{
var awakeTimeMenu = Bridge.CreatePopupMenu();
nint awakeTimeMenu = Bridge.CreatePopupMenu();
for (int i = 0; i < trayTimeShortcuts.Count; i++)
{
Bridge.InsertMenu(awakeTimeMenu, (uint)i, Native.Constants.MF_BYPOSITION | Native.Constants.MF_STRING, (uint)TrayCommands.TC_TIME + (uint)i, trayTimeShortcuts.ElementAt(i).Key);
}

Bridge.InsertMenu(TrayMenu, 0, Native.Constants.MF_BYPOSITION | Native.Constants.MF_POPUP | (isChecked == true ? Native.Constants.MF_CHECKED : Native.Constants.MF_UNCHECKED), (uint)awakeTimeMenu, Resources.AWAKE_KEEP_ON_INTERVAL);
Bridge.InsertMenu(TrayMenu, 0, Native.Constants.MF_BYPOSITION | Native.Constants.MF_POPUP | (isChecked ? Native.Constants.MF_CHECKED : Native.Constants.MF_UNCHECKED), (uint)awakeTimeMenu, Resources.AWAKE_KEEP_ON_INTERVAL);
}

private static void InsertAwakeModeMenuItems(AwakeMode mode)
Expand Down

0 comments on commit cc21240

Please sign in to comment.