Skip to content

Commit

Permalink
Fix efficiency mode being always enabled, fix icon tray not showing w…
Browse files Browse the repository at this point in the history
…hen launched as daemon
  • Loading branch information
marticliment committed Feb 8, 2025
1 parent a56af41 commit 18188e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
18 changes: 3 additions & 15 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.RegularExpressions;
using Windows.ApplicationModel.Activation;
using CommunityToolkit.WinUI.Helpers;
using H.NotifyIcon;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -349,14 +350,9 @@ private async Task CheckForMissingDependencies()
await MainWindow.HandleMissingDependencies(missing_deps);
}

protected override async void OnLaunched(LaunchActivatedEventArgs args)
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
if (!CoreData.IsDaemon)
{
await ShowMainWindowFromLaunchAsync();
}

CoreData.IsDaemon = false;
MainWindow?.Activate();
}

public async Task ShowMainWindowFromRedirectAsync(AppActivationArguments rawArgs)
Expand Down Expand Up @@ -390,14 +386,6 @@ public async Task ShowMainWindowFromRedirectAsync(AppActivationArguments rawArgs
MainWindow.DispatcherQueue.TryEnqueue(MainWindow.Activate);
}

public async Task ShowMainWindowFromLaunchAsync()
{
while (MainWindow is null)
await Task.Delay(100);

MainWindow.DispatcherQueue.TryEnqueue(MainWindow.Activate);
}

public async void DisposeAndQuit(int outputCode = 0)

Check warning on line 389 in src/UniGetUI/App.xaml.cs

View workflow job for this annotation

GitHub Actions / test-codebase

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Logger.Warn("Quitting UniGetUI");
Expand Down
48 changes: 39 additions & 9 deletions src/UniGetUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using UniGetUI.PackageEngine.Classes.Manager.Classes;
using UniGetUI.PackageEngine.Interfaces;
using Windows.ApplicationModel.DataTransfer;
using H.NotifyIcon.EfficiencyMode;
using Microsoft.Windows.AppNotifications;
using UniGetUI.Core.Classes;
using UniGetUI.Interface.Enums;
Expand Down Expand Up @@ -125,6 +126,27 @@ public MainWindow()
DWMThreadHelper.ChangeState_XAML(false);
}
};

if (CoreData.IsDaemon)
{
try
{
TrayIcon?.ForceCreate(true);
}
catch (Exception ex)
{
TrayIcon?.ForceCreate(false);
Logger.Error("Could not create taskbar tray with efficiency mode enabled");
Logger.Error(ex);
}
DWMThreadHelper.ChangeState_DWM(true);
DWMThreadHelper.ChangeState_XAML(true);
CoreData.IsDaemon = false;
}
else
{
Activate();
}
}

private static void TransferOldSettingsFormats()
Expand Down Expand Up @@ -206,21 +228,19 @@ public async void HandleClosingEvent(AppWindow sender, AppWindowClosingEventArgs
args.Cancel = true;
DWMThreadHelper.ChangeState_DWM(true);
DWMThreadHelper.ChangeState_XAML(true);

try
{
// this.Hide(enableEfficiencyMode: true);
AppWindow.Hide();
MainContentFrame.Content = null;
EfficiencyModeUtilities.SetEfficiencyMode(true);
}
catch (Exception ex)
{
// Somewhere, Sometimes, MS Window Efficiency mode just crashes
Logger.Debug("Windows efficiency mode API crashed, but this was [kinda] expected");
Logger.Debug(ex);
// this.Hide(enableEfficiencyMode: false);
AppWindow.Hide();
MainContentFrame.Content = null;
Logger.Error("Could not disable efficiency mode");
Logger.Error(ex);
}

MainContentFrame.Content = null;
AppWindow.Hide();
}
else
{
Expand Down Expand Up @@ -369,6 +389,16 @@ public void ProcessCommandLineParameters()

public new void Activate()
{
try
{
EfficiencyModeUtilities.SetEfficiencyMode(false);
}
catch (Exception ex)
{
Logger.Error("Could not disable efficiency mode");
Logger.Error(ex);
}

DWMThreadHelper.ChangeState_DWM(false);
DWMThreadHelper.ChangeState_XAML(false);

Expand Down

0 comments on commit 18188e7

Please sign in to comment.