Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awake - DAISY build fix (pre-83) #34054

Merged
merged 69 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ae527fb
Cleanup and check UI-based state
dend Apr 10, 2024
ca08069
Update Manager class to simplify settings handling
dend Apr 10, 2024
b87863c
Cleanup the code - we don't need to pass the constant to every call
dend Apr 10, 2024
f666863
Cleanup and consolidation of functionality
dend Apr 10, 2024
6044c8d
Cleanup and proper tray bootstrap with settings
dend Apr 10, 2024
f293af1
More cleanup
dend Apr 10, 2024
6cd3e28
More cleanup
dend Apr 10, 2024
fce629e
Update handling to remove redundant setting rewrites
dend Apr 10, 2024
a6f4b19
Move some strings to resources
dend Apr 10, 2024
36fce10
Cleaning up more redundancies
dend Apr 10, 2024
b5ead48
General cleanup
dend Apr 10, 2024
d8865e6
Code cleanup
dend Apr 10, 2024
6a8975c
More general cleanup
dend Apr 10, 2024
82cdca1
First stage of removing Windows Forms and natively using Win32 API
dend Apr 11, 2024
c3eef6f
Update parent window handle to HWND_MESSAGE
dend Apr 11, 2024
5360d6b
Cleanup for consistency
dend Apr 11, 2024
f0980c2
More cleanup and consolidation
dend Apr 12, 2024
b5107a5
Merge branch 'microsoft:main' into main
dend Jul 15, 2024
a52b981
Fix to the logic for native integration
dend Jul 16, 2024
19435c2
Code cleanup for unnecessary items
dend Jul 16, 2024
6bf1d56
Merge pull request #1 from microsoft/main
dend Jul 16, 2024
4cffdd4
adding in spelling adjustments
crutkas Jul 16, 2024
0fc378a
Fixing the menu and separators, along with icon tooltips
dend Jul 17, 2024
160fa46
Merge remote-tracking branch 'origin/main'
dend Jul 17, 2024
4f1f08a
Remove unused code
dend Jul 17, 2024
b2cca7d
Update Awake planning doc
dend Jul 17, 2024
ccc80c8
Update planning doc
dend Jul 17, 2024
01ff0a2
Update package releases
dend Jul 17, 2024
39f9f1e
Update Directory.Build.props
crutkas Jul 19, 2024
89d7ed8
Fixing build error in CI. I believe a ton of these aren't needed. E…
crutkas Jul 20, 2024
1e306c6
trying diff approach ... doubtful this will work but lets try as PT p…
crutkas Jul 20, 2024
02d3522
Trying with 2.0.7 as well here and reverting the changes
crutkas Jul 20, 2024
8f3ed40
Update Directory.Build.props
crutkas Jul 20, 2024
94eba7e
reverting to 2.0.4 to see if that helps
crutkas Jul 20, 2024
e2687be
fixing error, still gonna do a run agianst 2.0.7
crutkas Jul 20, 2024
0589e75
Merge branch 'main' of https://github.com/dend/PowerToys
crutkas Jul 20, 2024
ea0bd9f
lets try reverting back to 2.0.4
crutkas Jul 20, 2024
9fac940
adjusting notice
crutkas Jul 20, 2024
0adeede
Merge branch 'main' into pr32378
jaimecbernardo Jul 23, 2024
7757d1d
Fix unintended whitespace changes
jaimecbernardo Jul 23, 2024
e0d8a86
Fix more unintended whitespace changes
jaimecbernardo Jul 23, 2024
ed2aa3b
Fix remaining unintended whitespace change
jaimecbernardo Jul 23, 2024
af145f6
Add icons
dend Jul 23, 2024
d46b07a
Update doc
dend Jul 23, 2024
d425de5
Remove redundant code and fix indefinite keep-awake logic
dend Jul 23, 2024
2c1564c
Cleaning up the Awake code
dend Jul 23, 2024
3cf14c8
Remove unnecessary x:Uid definition
dend Jul 23, 2024
bb51679
Fixing the spell check issues
dend Jul 23, 2024
f0b922c
Fix typo
dend Jul 23, 2024
211dd7c
Ensure that expirable keep-awake has a default in UI view
dend Jul 25, 2024
014d4a5
Safeguards in Awake
dend Jul 25, 2024
651058e
Fix when the tray changes for passive mode
dend Jul 25, 2024
55a7e79
Save settings on expiration change
dend Jul 25, 2024
63771d2
Move icons to Awake assets folder
jaimecbernardo Jul 25, 2024
adfb399
Remove unneeded spellcheck expect entries
jaimecbernardo Jul 25, 2024
ad37725
Make sure the separator is only shown when launched from PT
dend Jul 29, 2024
7401dea
Merge remote-tracking branch 'origin/main'
dend Jul 29, 2024
8cd3538
Merge branch 'main' of https://github.com/microsoft/PowerToys into mi…
dend Jul 29, 2024
fd3d222
Merge branch 'microsoft-main'
dend Jul 29, 2024
6a56207
Fixes the issue with keeping display on resetting
dend Jul 29, 2024
4b2e866
Make sure exits are properly handled when not using PT config
dend Jul 29, 2024
3d09025
Remove unnecessary code
dend Jul 29, 2024
445d91a
Make sure that tooltips in the tray are useful
dend Jul 29, 2024
bc90ae6
Make sure that the timer stops properly
dend Jul 30, 2024
967302d
Make sure context menu is properly selected
dend Jul 30, 2024
d4ebe83
Catch unhandled exceptions in logs
dend Jul 30, 2024
e7ae812
Let's avoid memory leaks by re-using icons
dend Jul 30, 2024
87ce018
Default icon set once
dend Jul 30, 2024
0f5a715
Fixes #16123
dend Jul 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/awake/Awake/Awake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
12 changes: 12 additions & 0 deletions src/modules/awake/Awake/Core/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@ public static void AddRange<T>(this ICollection<T> target, IEnumerable<T> source
target.Add(element);
}
}

public static string ToHumanReadableString(this TimeSpan timeSpan)
{
// Get days, hours, minutes, and seconds from the TimeSpan
int days = timeSpan.Days;
int hours = timeSpan.Hours;
int minutes = timeSpan.Minutes;
int seconds = timeSpan.Seconds;

// Format the string based on the presence of days, hours, minutes, and seconds
return $"{days:D2}{Properties.Resources.AWAKE_LABEL_DAYS} {hours:D2}{Properties.Resources.AWAKE_LABEL_HOURS} {minutes:D2}{Properties.Resources.AWAKE_LABEL_MINUTES} {seconds:D2}{Properties.Resources.AWAKE_LABEL_SECONDS}";
}
}
}
85 changes: 56 additions & 29 deletions src/modules/awake/Awake/Core/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class Manager

private static readonly BlockingCollection<ExecutionState> _stateQueue;

// Core icons used for the tray
private static readonly Icon _timedIcon = new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/timed.ico"));
private static readonly Icon _expirableIcon = new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/expirable.ico"));
private static readonly Icon _indefiniteIcon = new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/indefinite.ico"));
private static readonly Icon _disabledIcon = new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/disabled.ico"));

private static CancellationTokenSource _tokenSource;

private static SettingsUtils? _moduleSettings;
Expand Down Expand Up @@ -135,7 +141,7 @@ internal static void SetIndefiniteKeepAwake(bool keepDisplayOn = false)

_stateQueue.Add(ComputeAwakeState(keepDisplayOn));

TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_INDEFINITE}]", new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/indefinite.ico")), TrayIconAction.Update);
TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_INDEFINITE}]", _indefiniteIcon, TrayIconAction.Update);

if (IsUsingPowerToysConfig)
{
Expand Down Expand Up @@ -172,14 +178,23 @@ internal static void SetExpirableKeepAwake(DateTimeOffset expireAt, bool keepDis
Logger.LogInfo($"Starting expirable log for {expireAt}");
_stateQueue.Add(ComputeAwakeState(keepDisplayOn));

TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_EXPIRATION}]", new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/expirable.ico")), TrayIconAction.Update);
TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_EXPIRATION} - {expireAt}]", _expirableIcon, TrayIconAction.Update);

Observable.Timer(expireAt - DateTimeOffset.Now).Subscribe(
_ =>
{
Logger.LogInfo($"Completed expirable keep-awake.");
CancelExistingThread();
SetPassiveKeepAwake();

if (IsUsingPowerToysConfig)
{
SetPassiveKeepAwake();
}
else
{
Logger.LogInfo("Exiting after expirable keep awake.");
CompleteExit(Environment.ExitCode);
}
},
_tokenSource.Token);
}
Expand Down Expand Up @@ -224,16 +239,40 @@ internal static void SetTimedKeepAwake(uint seconds, bool keepDisplayOn = true)
Logger.LogInfo($"Timed keep awake started for {seconds} seconds.");
_stateQueue.Add(ComputeAwakeState(keepDisplayOn));

TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_TIMED}]", new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/timed.ico")), TrayIconAction.Update);
TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_TIMED}]", _timedIcon, TrayIconAction.Update);

Observable.Timer(TimeSpan.FromSeconds(seconds)).Subscribe(
_ =>
{
Logger.LogInfo($"Completed timed thread.");
CancelExistingThread();
SetPassiveKeepAwake();
},
_tokenSource.Token);
var timerObservable = Observable.Timer(TimeSpan.FromSeconds(seconds));
var intervalObservable = Observable.Interval(TimeSpan.FromSeconds(1)).TakeUntil(timerObservable);

var combinedObservable = Observable.CombineLatest(intervalObservable, timerObservable.StartWith(0), (elapsedSeconds, _) => elapsedSeconds + 1);

combinedObservable.Subscribe(
elapsedSeconds =>
{
var timeRemaining = seconds - (uint)elapsedSeconds;
if (timeRemaining >= 0)
{
TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_TIMED}]\n{TimeSpan.FromSeconds(timeRemaining).ToHumanReadableString()}", _timedIcon, TrayIconAction.Update);
}
},
() =>
{
Console.WriteLine("Completed timed thread.");
CancelExistingThread();

if (IsUsingPowerToysConfig)
{
// If we're using PowerToys settings, we need to make sure that
// we just switch over the Passive Keep-Awake.
SetPassiveKeepAwake();
}
else
{
Logger.LogInfo("Exiting after timed keep-awake.");
CompleteExit(Environment.ExitCode);
}
},
_tokenSource.Token);

if (IsUsingPowerToysConfig)
{
Expand Down Expand Up @@ -264,9 +303,7 @@ internal static void SetTimedKeepAwake(uint seconds, bool keepDisplayOn = true)
/// Performs a clean exit from Awake.
/// </summary>
/// <param name="exitCode">Exit code to exit with.</param>
/// <param name="exitSignal">Exit signal tracking the state.</param>
/// <param name="force">Determines whether to force exit and post a quitting message.</param>
internal static void CompleteExit(int exitCode, ManualResetEvent? exitSignal, bool force = false)
internal static void CompleteExit(int exitCode)
{
SetPassiveKeepAwake(updateSettings: false);

Expand All @@ -277,22 +314,12 @@ internal static void CompleteExit(int exitCode, ManualResetEvent? exitSignal, bo

// Close the message window that we used for the tray.
Bridge.SendMessage(TrayHelper.HiddenWindowHandle, Native.Constants.WM_CLOSE, 0, 0);
}

if (force)
{
Bridge.PostQuitMessage(exitCode);
}

try
{
exitSignal?.Set();
Bridge.DestroyWindow(TrayHelper.HiddenWindowHandle);
}
catch (Exception ex)
{
Logger.LogError($"Exit signal error ${ex}");
}

Bridge.PostQuitMessage(exitCode);
Environment.Exit(exitCode);
}

/// <summary>
Expand Down Expand Up @@ -350,7 +377,7 @@ internal static void SetPassiveKeepAwake(bool updateSettings = true)

CancelExistingThread();

TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_OFF}]", new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets/Awake/disabled.ico")), TrayIconAction.Update);
TrayHelper.SetShellIcon(TrayHelper.HiddenWindowHandle, $"{Constants.FullAppName} [{Resources.AWAKE_TRAY_TEXT_OFF}]", _disabledIcon, TrayIconAction.Update);

if (IsUsingPowerToysConfig && updateSettings)
{
Expand Down
Loading
Loading