Compare commits

...

5 Commits

Author SHA1 Message Date
Niels Laute
210b53a8dc Merge branch 'main' into copilot/add-show-hide-awake-icon 2025-10-17 03:53:10 +02:00
copilot-swe-agent[bot]
39011da721 Improve code readability by extracting tray icon text to variable
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
2025-10-16 11:27:43 +00:00
copilot-swe-agent[bot]
803ab070a6 Fix code review issues - remove unused parameter and fix timed icon update
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
2025-10-16 11:25:50 +00:00
copilot-swe-agent[bot]
281a32e21d Add ShowTrayIcon property to Awake settings model
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
2025-10-16 11:20:12 +00:00
copilot-swe-agent[bot]
a8c7d30c3c Initial plan 2025-10-16 11:10:31 +00:00
7 changed files with 69 additions and 5 deletions

View File

@@ -49,6 +49,8 @@ namespace Awake.Core
private static DateTimeOffset ExpireAt { get; set; }
private static bool ShowTrayIcon { get; set; } = true;
private static readonly CompositeFormat AwakeMinute = CompositeFormat.Parse(Resources.AWAKE_MINUTE);
private static readonly CompositeFormat AwakeMinutes = CompositeFormat.Parse(Resources.AWAKE_MINUTES);
private static readonly CompositeFormat AwakeHour = CompositeFormat.Parse(Resources.AWAKE_HOUR);
@@ -145,8 +147,42 @@ namespace Awake.Core
Logger.LogInfo("New token source and thread token instantiated.");
}
internal static void SetShowTrayIcon(bool showTrayIcon)
{
ShowTrayIcon = showTrayIcon;
SetModeShellIcon();
}
private static void UpdateTrayIconText(string iconText, Icon? icon, TrayIconAction action = TrayIconAction.Update)
{
if (!ShowTrayIcon && action != TrayIconAction.Delete)
{
return;
}
TrayHelper.SetShellIcon(TrayHelper.WindowHandle, iconText, icon, action);
}
internal static void SetModeShellIcon(bool forceAdd = false)
{
if (!ShowTrayIcon && !forceAdd)
{
// If the tray icon should be hidden and this is not a forced add (e.g., taskbar recreated),
// delete the icon if it exists
TrayHelper.SetShellIcon(
TrayHelper.WindowHandle,
string.Empty,
null,
TrayIconAction.Delete);
return;
}
if (!ShowTrayIcon && forceAdd)
{
// If the tray icon should be hidden but taskbar was recreated, still hide it
return;
}
string iconText = string.Empty;
Icon? icon = null;
@@ -344,11 +380,8 @@ namespace Awake.Core
{
TimeRemaining = (uint)remainingTimeSpan.TotalSeconds;
TrayHelper.SetShellIcon(
TrayHelper.WindowHandle,
$"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_TIMED}][{ScreenStateString}][{remainingTimeSpan.ToHumanReadableString()}]",
TrayHelper.TimedIcon,
TrayIconAction.Update);
string iconText = $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_TIMED}][{ScreenStateString}][{remainingTimeSpan.ToHumanReadableString()}]";
UpdateTrayIconText(iconText, TrayHelper.TimedIcon, TrayIconAction.Update);
},
_ => HandleTimerCompletion("timed"),
_tokenSource.Token);

View File

@@ -506,6 +506,8 @@ namespace Awake
Logger.LogInfo($"Identified custom time shortcuts for the tray: {settings.Properties.CustomTrayTimes.Count}");
Manager.SetShowTrayIcon(settings.Properties.ShowTrayIcon);
switch (settings.Properties.Mode)
{
case AwakeMode.PASSIVE:

View File

@@ -20,6 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
IntervalMinutes = 1;
ExpirationDateTime = DateTimeOffset.Now;
CustomTrayTimes = [];
ShowTrayIcon = true;
}
[JsonPropertyName("keepDisplayOn")]
@@ -40,5 +41,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("customTrayTimes")]
[CmdConfigureIgnore]
public Dictionary<string, uint> CustomTrayTimes { get; set; }
[JsonPropertyName("showTrayIcon")]
public bool ShowTrayIcon { get; set; }
}
}

View File

@@ -41,6 +41,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
// Fix old buggy default value that might be saved in Settings. Some components don't deal well with negative time zones and minimum time offsets.
ExpirationDateTime = Properties.ExpirationDateTime.Year < 2 ? DateTimeOffset.Now : Properties.ExpirationDateTime,
ShowTrayIcon = Properties.ShowTrayIcon,
},
};
}

View File

@@ -35,6 +35,13 @@
</controls:GPOInfoControl>
<controls:SettingsGroup x:Uid="Awake_BehaviorSettingsGroup" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsCard
Name="AwakeShowTrayIconSettingsCard"
x:Uid="Awake_ShowTrayIconSettingsCard"
HeaderIcon="{ui:FontIcon Glyph=&#xE7E8;}">
<ToggleSwitch IsOn="{x:Bind ViewModel.ShowTrayIcon, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard
Name="AwakeModeSettingsCard"
x:Uid="Awake_ModeSettingsCard"

View File

@@ -2356,6 +2356,9 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="Awake_BehaviorSettingsGroup.Header" xml:space="preserve">
<value>Behavior</value>
</data>
<data name="Awake_ShowTrayIconSettingsCard.Header" xml:space="preserve">
<value>Show tray icon</value>
</data>
<data name="Awake_IntervalHoursInput.Header" xml:space="preserve">
<value>Hours</value>
</data>

View File

@@ -198,6 +198,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool ShowTrayIcon
{
get => ModuleSettings.Properties.ShowTrayIcon;
set
{
if (ModuleSettings.Properties.ShowTrayIcon != value)
{
ModuleSettings.Properties.ShowTrayIcon = value;
NotifyPropertyChanged();
}
}
}
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
Logger.LogInfo($"Changed the property {propertyName}");
@@ -219,6 +232,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
OnPropertyChanged(nameof(IntervalHours));
OnPropertyChanged(nameof(IntervalMinutes));
OnPropertyChanged(nameof(ExpirationDateTime));
OnPropertyChanged(nameof(ShowTrayIcon));
}
private bool _enabledStateIsGPOConfigured;