diff --git a/src/Files.App/ServicesImplementation/SideloadUpdateService.cs b/src/Files.App/ServicesImplementation/SideloadUpdateService.cs index 1aafe1f91ba4..a5388b5eee91 100644 --- a/src/Files.App/ServicesImplementation/SideloadUpdateService.cs +++ b/src/Files.App/ServicesImplementation/SideloadUpdateService.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using System.IO; using System.Net.Http; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Xml.Serialization; @@ -19,6 +20,9 @@ namespace Files.App.ServicesImplementation { public sealed class SideloadUpdateService : ObservableObject, IUpdateService, IDisposable { + [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] + private static extern uint RegisterApplicationRestart(string pwzCommandLine, int dwFlags); + private const string SIDELOAD_STABLE = "https://cdn.files.community/files/stable/Files.Package.appinstaller"; private const string SIDELOAD_PREVIEW = "https://cdn.files.community/files/preview/Files.Package.appinstaller"; @@ -185,6 +189,10 @@ private async Task ApplyPackageUpdate() try { + var restartStatus = RegisterApplicationRestart(null, 0); + + Logger?.Info($"Register for restart: {restartStatus}"); + await Task.Run(async () => { var bundlePath = new Uri(ApplicationData.Current.LocalFolder.Path + "\\" + TEMPORARY_UPDATE_PACKAGE_NAME); @@ -192,7 +200,7 @@ await Task.Run(async () => var deployment = pm.RequestAddPackageAsync( bundlePath, null, - DeploymentOptions.ForceTargetApplicationShutdown, + DeploymentOptions.ForceApplicationShutdown, pm.GetDefaultPackageVolume(), null, null);