Browse Source

Set executable permissions for linux updater

pull/55/head
Ionite 1 year ago
parent
commit
12ce5fda0f
No known key found for this signature in database
  1. 7
      StabilityMatrix.Avalonia/Program.cs
  2. 7
      StabilityMatrix.Avalonia/ViewModels/Dialogs/UpdateViewModel.cs
  3. 13
      StabilityMatrix.Core/Updater/UpdateHelper.cs

7
StabilityMatrix.Avalonia/Program.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -89,6 +90,12 @@ public class Program
{ {
currentExe.CopyTo(targetExe, true); currentExe.CopyTo(targetExe, true);
// Ensure permissions are set for unix
if (Compat.IsUnix)
{
File.SetUnixFileMode(targetExe, (UnixFileMode) 0x755);
}
// Start the new app // Start the new app
Process.Start(targetExe); Process.Start(targetExe);

7
StabilityMatrix.Avalonia/ViewModels/Dialogs/UpdateViewModel.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsyncAwaitBestPractices; using AsyncAwaitBestPractices;
@ -78,6 +79,12 @@ public partial class UpdateViewModel : ContentDialogViewModelBase
ProgressValue = Convert.ToInt32(report.Percentage); ProgressValue = Convert.ToInt32(report.Percentage);
})); }));
// On unix, we need to set the executable bit
if (Compat.IsUnix)
{
File.SetUnixFileMode(UpdateHelper.ExecutablePath, (UnixFileMode) 0x755);
}
UpdateText = "Update complete. Restarting Stability Matrix in 3 seconds..."; UpdateText = "Update complete. Restarting Stability Matrix in 3 seconds...";
await Task.Delay(1000); await Task.Delay(1000);
UpdateText = "Update complete. Restarting Stability Matrix in 2 seconds..."; UpdateText = "Update complete. Restarting Stability Matrix in 2 seconds...";

13
StabilityMatrix.Core/Updater/UpdateHelper.cs

@ -35,14 +35,14 @@ public class UpdateHelper : IUpdateHelper
this.downloadService = downloadService; this.downloadService = downloadService;
this.debugOptions = debugOptions.Value; this.debugOptions = debugOptions.Value;
timer.Elapsed += async (_, _) => { await CheckForUpdate(); }; timer.Elapsed += async (_, _) => { await CheckForUpdate().ConfigureAwait(false); };
} }
public async Task StartCheckingForUpdates() public async Task StartCheckingForUpdates()
{ {
timer.Enabled = true; timer.Enabled = true;
timer.Start(); timer.Start();
await CheckForUpdate(); await CheckForUpdate().ConfigureAwait(false);
} }
public async Task DownloadUpdate(UpdateInfo updateInfo, public async Task DownloadUpdate(UpdateInfo updateInfo,
@ -54,7 +54,7 @@ public class UpdateHelper : IUpdateHelper
// download the file from URL // download the file from URL
await downloadService.DownloadToFileAsync(downloadUrl, ExecutablePath, progress: progress, await downloadService.DownloadToFileAsync(downloadUrl, ExecutablePath, progress: progress,
httpClientName: "UpdateClient"); httpClientName: "UpdateClient").ConfigureAwait(false);
} }
@ -77,17 +77,18 @@ public class UpdateHelper : IUpdateHelper
try try
{ {
var httpClient = httpClientFactory.CreateClient("UpdateClient"); var httpClient = httpClientFactory.CreateClient("UpdateClient");
var response = await httpClient.GetAsync(UpdateManifestUrl); var response = await httpClient.GetAsync(UpdateManifestUrl).ConfigureAwait(false);
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {
logger.LogWarning("Error while checking for update {StatusCode} - {Content}", logger.LogWarning("Error while checking for update {StatusCode} - {Content}",
response.StatusCode, await response.Content.ReadAsStringAsync()); response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false));
return; return;
} }
var updateCollection = var updateCollection =
await JsonSerializer.DeserializeAsync<UpdateCollection>( await JsonSerializer.DeserializeAsync<UpdateCollection>(
await response.Content.ReadAsStreamAsync()); await response.Content.ReadAsStreamAsync()
.ConfigureAwait(false)).ConfigureAwait(false);
if (updateCollection is null) if (updateCollection is null)
{ {

Loading…
Cancel
Save