-
Notifications
You must be signed in to change notification settings - Fork 940
Track packages that cannot finish until the machine reboots #5464
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
Merged
Gabriel Dufresne (GabrielDuf)
merged 3 commits into
main
from
feat/pending-machine-restart
Oct 1, 2026
+1,016
−52
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/UniGetUI.Avalonia/Infrastructure/OperationNotificationText.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using UniGetUI.Core.Tools; | ||
| using UniGetUI.PackageOperations; | ||
|
|
||
| namespace UniGetUI.Avalonia.Infrastructure; | ||
|
|
||
| internal static class OperationNotificationText | ||
| { | ||
| public static string SuccessTitle(AbstractOperation operation) | ||
| => operation.Metadata.SuccessTitle.Length > 0 | ||
| ? operation.Metadata.SuccessTitle | ||
| : CoreTools.Translate("Success!"); | ||
|
|
||
| public static string SuccessMessage(AbstractOperation operation) | ||
| { | ||
| string message = operation.Metadata.SuccessMessage.Length > 0 | ||
| ? operation.Metadata.SuccessMessage | ||
| : CoreTools.Translate("Success!"); | ||
|
|
||
| if (!operation.SystemRestartRequired) return message; | ||
|
|
||
| message = message.TrimEnd(); | ||
| if (message.Length > 0 && !".!?:;。!?".Contains(message[^1])) | ||
| message += "."; | ||
|
|
||
| return message | ||
| + " " | ||
| + CoreTools.Translate( | ||
| "This operation finished, but the computer must be restarted before the changes take effect"); | ||
| } | ||
| } |
146 changes: 146 additions & 0 deletions
146
src/UniGetUI.Avalonia/Infrastructure/SystemRestartService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| using System.Diagnostics; | ||
| using Avalonia.Controls; | ||
| using Avalonia.Media; | ||
| using Avalonia.Threading; | ||
| using UniGetUI.Avalonia.Views.DialogPages; | ||
| using UniGetUI.Core.Logging; | ||
| using UniGetUI.Core.Tools; | ||
| using UniGetUI.PackageEngine.Operations.Reboot; | ||
|
|
||
| namespace UniGetUI.Avalonia.Infrastructure; | ||
|
|
||
| internal static class SystemRestartService | ||
| { | ||
| private const int ShutdownRequestTimeoutMs = 10000; | ||
|
|
||
| public static async Task ConfirmAndRestartAsync(Window owner) | ||
| { | ||
| try | ||
| { | ||
| if (!await ConfirmAsync(owner)) return; | ||
|
|
||
| if (!await RestartAsync()) ReportRestartFailure(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Logger.Error("Failed to prompt for a system restart:"); | ||
| Logger.Error(ex); | ||
| } | ||
| } | ||
|
|
||
| private static async Task<bool> ConfirmAsync(Window owner) | ||
| { | ||
| var pending = PendingRebootStore.GetPending(); | ||
| if (pending.Count == 0) return false; | ||
|
|
||
| var body = new StackPanel { Spacing = 12 }; | ||
| body.Children.Add(new TextBlock | ||
| { | ||
| Text = pending.Count == 1 | ||
| ? CoreTools.Translate("1 package cannot finish until your computer restarts.") | ||
| : CoreTools.Translate( | ||
| "{0} packages cannot finish until your computer restarts.", | ||
| pending.Count), | ||
| Opacity = 0.82, | ||
| TextWrapping = TextWrapping.Wrap, | ||
| }); | ||
|
|
||
| body.Children.Add(new ScrollViewer | ||
| { | ||
| MaxHeight = 180, | ||
| Content = new TextBlock | ||
| { | ||
| Text = string.Join( | ||
| Environment.NewLine, | ||
| pending | ||
| .Select(entry => entry.PackageName.Length > 0 ? entry.PackageName : entry.PackageId) | ||
| .OrderBy(name => name, StringComparer.OrdinalIgnoreCase) | ||
| .Select(name => "* " + name)), | ||
| FontFamily = new FontFamily("Consolas"), | ||
| TextWrapping = TextWrapping.Wrap, | ||
| }, | ||
| }); | ||
|
|
||
| body.Children.Add(new TextBlock | ||
| { | ||
| Text = CoreTools.Translate( | ||
| "Your computer will restart now. Save your work and close any open applications first."), | ||
| TextWrapping = TextWrapping.Wrap, | ||
| }); | ||
|
|
||
| var dialog = new ImmersiveConfirmationDialog( | ||
| CoreTools.Translate("Restart your computer?"), | ||
| body, | ||
| CoreTools.Translate("Restart now"), | ||
| CoreTools.Translate("Not now")) | ||
| { | ||
| MaxWidth = 560, | ||
| MaxHeight = 420, | ||
| FocusPrimaryButton = false, | ||
| }; | ||
|
|
||
| await dialog.ShowDialog(owner); | ||
| return dialog.Result is true; | ||
| } | ||
|
|
||
| private static async Task<bool> RestartAsync() | ||
| { | ||
| if (!OperatingSystem.IsWindows()) | ||
| { | ||
| Logger.Warn("A system restart was requested on a platform where UniGetUI cannot trigger one"); | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| using var process = Process.Start(new ProcessStartInfo | ||
| { | ||
| FileName = Path.Combine(Environment.SystemDirectory, "shutdown.exe"), | ||
| Arguments = "/r /t 0", | ||
| UseShellExecute = false, | ||
| CreateNoWindow = true, | ||
| }); | ||
|
|
||
| if (process is null) | ||
| { | ||
| Logger.Error("Could not start shutdown.exe to request a system restart"); | ||
| return false; | ||
| } | ||
|
|
||
| using var timeout = new CancellationTokenSource(ShutdownRequestTimeoutMs); | ||
| try | ||
| { | ||
| await process.WaitForExitAsync(timeout.Token); | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| Logger.Warn("shutdown.exe did not return in time; assuming the restart was requested"); | ||
| return true; | ||
| } | ||
|
|
||
| if (process.ExitCode != 0) | ||
| { | ||
| Logger.Error($"shutdown.exe refused the restart request with exit code {process.ExitCode}"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Logger.Error("Failed to request a system restart:"); | ||
| Logger.Error(ex); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private static void ReportRestartFailure() | ||
| { | ||
| Dispatcher.UIThread.Post(() => | ||
| Views.MainWindow.Instance?.ShowRuntimeNotification( | ||
| CoreTools.Translate("The computer could not be restarted"), | ||
| CoreTools.Translate( | ||
| "UniGetUI could not start the restart. Please restart your computer manually."), | ||
| Views.MainWindow.RuntimeNotificationLevel.Error)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.