MacUpdateHelper.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Diagnostics;
  2. using PicView.Avalonia.Update;
  3. using PicView.Avalonia.WindowBehavior;
  4. using PicView.Core.DebugTools;
  5. namespace PicView.Avalonia.MacOS.PlatformUpdate;
  6. /// <summary>
  7. /// Handles macOS-specific update logic
  8. /// </summary>
  9. public static class MacUpdateHelper
  10. {
  11. /// <summary>
  12. /// Handles the update process for macOS
  13. /// </summary>
  14. public static async Task HandleMacOSUpdate(UpdateInfo updateInfo, string tempPath)
  15. {
  16. // Determine architecture - Apple Silicon (ARM) vs Intel
  17. var isArm = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture ==
  18. System.Runtime.InteropServices.Architecture.Arm64;
  19. // Select appropriate download URL based on architecture
  20. var downloadUrl = isArm ? updateInfo.MacArm64 : updateInfo.MacIntel;
  21. await DownloadAndOpenDmg(downloadUrl, tempPath);
  22. }
  23. /// <summary>
  24. /// Downloads and opens the DMG file
  25. /// </summary>
  26. private static async Task DownloadAndOpenDmg(string downloadUrl, string tempPath)
  27. {
  28. try
  29. {
  30. // Extract filename from URL
  31. var fileName = Path.GetFileName(downloadUrl);
  32. var tempFilePath = Path.Combine(tempPath, fileName);
  33. // Download the DMG file
  34. await UpdateManager.DownloadUpdateFile(downloadUrl, tempFilePath);
  35. // Open the DMG file
  36. var process = new Process
  37. {
  38. StartInfo = new ProcessStartInfo
  39. {
  40. UseShellExecute = true,
  41. FileName = "open",
  42. Arguments = $"\"{tempFilePath}\"",
  43. }
  44. };
  45. process.Start();
  46. // Give some time for the DMG to mount before exiting
  47. await Task.Delay(1000);
  48. // Close the application
  49. await WindowFunctions.WindowClosingBehavior();
  50. }
  51. catch (Exception ex)
  52. {
  53. DebugHelper.LogDebug(nameof(MacUpdateHelper), nameof(DownloadAndOpenDmg), ex);
  54. await UI.TooltipHelper.ShowTooltipMessageAsync(
  55. $"Failed to download or open update: {ex.Message}");
  56. }
  57. }
  58. }