Skip to content

Commit 4c4a10f

Browse files
committed
Enhance Linux AppImage update process with error handling and user feedback
1 parent 22c0aa0 commit 4c4a10f

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

StabilityMatrix.Avalonia/ViewModels/Dialogs/UpdateViewModel.cs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ await updateHelper.DownloadUpdate(
165165
// Handle Linux AppImage update
166166
if (Compat.IsLinux && Environment.GetEnvironmentVariable("APPIMAGE") is { } appImage)
167167
{
168-
var updateScriptPath = UpdateHelper.UpdateFolder.JoinFile("update_script.sh").FullPath;
169-
var newAppImage = UpdateHelper.ExecutablePath.FullPath;
168+
try
169+
{
170+
var updateScriptPath = UpdateHelper.UpdateFolder.JoinFile("update_script.sh").FullPath;
171+
var newAppImage = UpdateHelper.ExecutablePath.FullPath;
170172

171-
var scriptContent = $"""
173+
var scriptContent = $"""
172174
#!/bin/bash
173175
PID={Environment.ProcessId}
174176
NEW_APPIMAGE="{newAppImage.Replace("\"", "\\\"")}"
@@ -183,28 +185,41 @@ sleep 0.5
183185
mv -f "$NEW_APPIMAGE" "$OLD_APPIMAGE"
184186
chmod +x "$OLD_APPIMAGE"
185187
186-
# Launch the new AppImage
187-
"$OLD_APPIMAGE" &
188+
# Launch the new AppImage detached
189+
"$OLD_APPIMAGE" > /dev/null 2>&1 &
190+
disown
188191
""";
189-
await File.WriteAllTextAsync(updateScriptPath, scriptContent);
192+
await File.WriteAllTextAsync(updateScriptPath, scriptContent);
193+
194+
File.SetUnixFileMode(
195+
updateScriptPath,
196+
UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute
197+
);
198+
199+
System.Diagnostics.Process.Start(
200+
new System.Diagnostics.ProcessStartInfo
201+
{
202+
FileName = "/usr/bin/env",
203+
Arguments = $"bash \"{updateScriptPath}\"",
204+
UseShellExecute = false,
205+
CreateNoWindow = true,
206+
}
207+
);
208+
209+
App.Shutdown();
210+
return;
211+
}
212+
catch (Exception ex)
213+
{
214+
logger.LogError(ex, "Failed to execute AppImage update script");
190215

191-
File.SetUnixFileMode(
192-
updateScriptPath,
193-
UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute
194-
);
216+
var dialog = DialogHelper.CreateMarkdownDialog(
217+
"AppImage update script failed. \nCould not replace old AppImage with new version. Please check directory permissions. \nFalling back to standard update process. User intervention required: After program closes, \nplease move the new AppImage extracted in the '.StabilityMatrixUpdate' hidden directory to the old AppImage overwriting it. \n\nClose this dialog to continue with standard update process.",
218+
Resources.Label_UnexpectedErrorOccurred
219+
);
195220

196-
System.Diagnostics.Process.Start(
197-
new System.Diagnostics.ProcessStartInfo
198-
{
199-
FileName = "/bin/bash",
200-
Arguments = updateScriptPath,
201-
UseShellExecute = false,
202-
CreateNoWindow = true,
203-
}
204-
);
205-
206-
App.Shutdown();
207-
return;
221+
await dialog.ShowAsync();
222+
}
208223
}
209224

210225
// Set current version for update messages

0 commit comments

Comments
 (0)