Skip to content

Commit 9528fb1

Browse files
Add AppImage updating
1 parent d8dd073 commit 9528fb1

File tree

6 files changed

+80
-19
lines changed

6 files changed

+80
-19
lines changed

src/TrackerCouncil.Smz3.UI/App.axaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using System.Runtime.Versioning;
55
using System.Threading.Tasks;
6-
using AppImageDesktopFileCreator;
6+
using AppImageManager;
77
using Avalonia;
88
using Avalonia.Controls.ApplicationLifetimes;
99
using Avalonia.Markup.Xaml;
@@ -17,6 +17,9 @@ namespace TrackerCouncil.Smz3.UI;
1717

1818
public partial class App : Application
1919
{
20+
public const string AppId = "org.trackercouncil.smz3";
21+
public const string AppName = "SMZ3 Cas' Randomizer";
22+
2023
private IGlobalHook? _hook;
2124
private Task? _hookRunner;
2225
private static readonly string? s_versionOverride = null;
@@ -71,7 +74,7 @@ private void NativeMenuItem_OnClick(object? sender, EventArgs e)
7174
[SupportedOSPlatform("linux")]
7275
internal static CreateDesktopFileResponse BuildLinuxDesktopFile()
7376
{
74-
return new DesktopFileBuilder("org.trackercouncil.smz3", "SMZ3 Cas' Randomizer")
77+
return new DesktopFileBuilder(AppId, AppName)
7578
.AddUninstallAction(Directories.AppDataFolder)
7679
.Build();
7780
}

src/TrackerCouncil.Smz3.UI/Services/MainWindowService.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
2-
using System.Diagnostics;
32
using System.IO;
43
using System.Linq;
5-
using System.Reflection;
64
using System.Threading.Tasks;
7-
using AppImageDesktopFileCreator;
5+
using AppImageManager;
86
using Avalonia.Threading;
97
using AvaloniaControls.Controls;
108
using AvaloniaControls.ControlServices;
@@ -16,7 +14,6 @@
1614
using PySpeechService.Client;
1715
using PySpeechService.TextToSpeech;
1816
using TrackerCouncil.Smz3.Chat.Integration;
19-
using TrackerCouncil.Smz3.Data;
2017
using TrackerCouncil.Smz3.Data.Configuration;
2118
using TrackerCouncil.Smz3.Data.Options;
2219
using TrackerCouncil.Smz3.Data.Services;
@@ -48,7 +45,7 @@ public MainWindowViewModel InitializeModel(MainWindow window)
4845

4946
if (!_model.OpenSetupWindow && OperatingSystem.IsLinux() && !_options.GeneralOptions.SkipDesktopFile)
5047
{
51-
_model.OpenDesktopFileWindow = !DesktopFileCreator.DoesDesktopFileExist("org.trackercouncil.smz3");
48+
_model.OpenDesktopFileWindow = !AppImage.DoesDesktopFileExist(App.AppId);
5249
}
5350

5451
ITaskService.Run(CheckForUpdates);
@@ -231,6 +228,13 @@ private async Task CheckForUpdates()
231228
{
232229
_model.DisplayNewVersionBanner = true;
233230
_model.NewVersionGitHubUrl = gitHubRelease.Url;
231+
232+
if (OperatingSystem.IsLinux())
233+
{
234+
_model.NewVersionDownloadUrl = gitHubRelease.Asset
235+
.FirstOrDefault(x => x.Url.ToLower().EndsWith(".appimage"))?.Url;
236+
_model.DisplayDownloadLink = !string.IsNullOrEmpty(_model.NewVersionDownloadUrl);
237+
}
234238
}
235239
}
236240
catch (Exception ex)

src/TrackerCouncil.Smz3.UI/TrackerCouncil.Smz3.UI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
below is needed to remove Avalonia.Diagnostics package from build output in Release
2222
configuration.-->
2323
<PackageReference Include="Avalonia_Gif" Version="1.0.0" />
24-
<PackageReference Include="MattEqualsCoder.AppImageDesktopFileCreator" Version="0.3.6" />
24+
<PackageReference Include="MattEqualsCoder.AppImageManager" Version="0.1.2" />
2525
<PackageReference Include="MattEqualsCoder.AvaloniaControls" Version="1.5.3" />
2626
<PackageReference Include="MattEqualsCoder.DynamicForms.Avalonia" Version="1.2.0" />
2727
<PackageReference Include="MattEqualsCoder.MSURandomizer.Avalonia" Version="3.0.1" />

src/TrackerCouncil.Smz3.UI/ViewModels/MainWindowViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ public MainWindowViewModel()
1010
}
1111

1212
[Reactive] public bool DisplayNewVersionBanner { get; set; }
13+
[Reactive] public bool DisplayDownloadLink { get; set; }
1314

1415
public string NewVersionGitHubUrl { get; set; } = "";
16+
public string? NewVersionDownloadUrl { get; set; }
1517

1618
public bool OpenSetupWindow { get; set; }
1719

src/TrackerCouncil.Smz3.UI/Views/MainWindow.axaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@
1818
<Design.DataContext>
1919
<!-- This only sets the DataContext for the previewer in an IDE,
2020
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
21-
<viewModels:MainWindowViewModel/>
21+
<viewModels:MainWindowViewModel DisplayNewVersionBanner="True" DisplayDownloadLink="True" />
2222
</Design.DataContext>
2323

2424
<LayoutTransformControl x:Name="MainLayout">
2525
<Grid RowDefinitions="Auto, *">
2626
<controls:HeaderFooter BorderSize="0 0 0 2" Grid.Row="0" IsVisible="{Binding DisplayNewVersionBanner}">
2727
<StackPanel Orientation="Vertical">
2828

29-
<Grid ColumnDefinitions="*, Auto">
30-
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="5">
31-
<TextBlock>A new version of SMZ3 is now available!</TextBlock>
32-
<controls:LinkControl Margin="5 0 0 0" Name="GitHubUrlLink" Click="GitHubUrlLink_OnClick">Click here to go to the download page.</controls:LinkControl>
33-
</StackPanel>
29+
<Grid ColumnDefinitions="*, Auto, *">
30+
<Border Grid.Column="0"></Border>
31+
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Margin="0 2 0 0">A new version of SMZ3 is now available!</TextBlock>
3432

35-
<controls:ImageButton Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Name="CloseUpdateButton" Click="CloseUpdateButton_OnClick">
33+
<controls:ImageButton Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Top" Name="CloseUpdateButton" Click="CloseUpdateButton_OnClick">
3634
<avalonia:MaterialIcon Kind="Close" Width="12" Height="12" Background="Transparent"></avalonia:MaterialIcon>
3735
</controls:ImageButton>
3836
</Grid>
3937

40-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 0 3 3">
41-
<controls:LinkControl FontSize="10" Name="IgnoreVersionLink" Click="IgnoreVersionLink_OnClick">Ignore this Version</controls:LinkControl>
42-
<controls:LinkControl FontSize="10" Margin="5 0 0 0" Name="DisableUpdatesLink" Click="DisableUpdatesLink_OnClick">Don't Check for Updates</controls:LinkControl>
43-
</StackPanel>
38+
<Grid ColumnDefinitions="*, Auto" Margin="3 0 3 3">
39+
<StackPanel Grid.Column="0" Orientation="Horizontal">
40+
<controls:LinkControl FontSize="10" Click="DownloadReleaseButton_OnClick" IsVisible="{Binding DisplayDownloadLink}">
41+
<avalonia:MaterialIcon Kind="ArrowBottomBold" Margin="0 0 0 -1" Background="Transparent"/>
42+
</controls:LinkControl>
43+
<controls:LinkControl FontSize="10" Name="DownloadReleaseLink" Click="DownloadReleaseButton_OnClick" Margin="0 0 10 0" IsVisible="{Binding DisplayDownloadLink}">
44+
Download Update
45+
</controls:LinkControl>
46+
47+
<controls:LinkControl FontSize="10" Click="GitHubUrlLink_OnClick">
48+
<avalonia:MaterialIcon Kind="Link" />
49+
</controls:LinkControl>
50+
<controls:LinkControl FontSize="10" Name="GitHubUrlLink" Click="GitHubUrlLink_OnClick" Background="Transparent">View On GitHub</controls:LinkControl>
51+
</StackPanel>
52+
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
53+
<controls:LinkControl FontSize="10" Name="IgnoreVersionLink" Click="IgnoreVersionLink_OnClick">Ignore this Version</controls:LinkControl>
54+
<controls:LinkControl FontSize="10" Margin="10 0 0 0" Name="DisableUpdatesLink" Click="DisableUpdatesLink_OnClick">Don't Check for Updates</controls:LinkControl>
55+
</StackPanel>
56+
</Grid>
4457
</StackPanel>
4558

4659
</controls:HeaderFooter>

src/TrackerCouncil.Smz3.UI/Views/MainWindow.axaml.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.IO;
33
using System.Threading.Tasks;
4+
using AppImageManager;
5+
using Avalonia.Controls;
46
using Avalonia.Interactivity;
57
using Avalonia.Threading;
68
using AvaloniaControls;
@@ -130,4 +132,41 @@ private void AboutButton_OnClick(object? sender, RoutedEventArgs e)
130132
{
131133
_serviceProvider?.GetRequiredService<AboutWindow>().ShowDialog(this);
132134
}
135+
136+
private async void DownloadReleaseButton_OnClick(object? sender, RoutedEventArgs e)
137+
{
138+
try
139+
{
140+
if (string.IsNullOrEmpty(_model.NewVersionDownloadUrl))
141+
{
142+
return;
143+
}
144+
145+
if (OperatingSystem.IsLinux())
146+
{
147+
var downloadResult = await AppImage.DownloadAsync(new DownloadAppImageRequest
148+
{
149+
Url = _model.NewVersionDownloadUrl
150+
});
151+
152+
if (downloadResult.Success)
153+
{
154+
Close();
155+
}
156+
else if (downloadResult.DownloadedSuccessfully)
157+
{
158+
await MessageWindow.ShowErrorDialog("AppImage was downloaded, but it could not be launched.");
159+
}
160+
else
161+
{
162+
await MessageWindow.ShowErrorDialog("Failed downloading AppImage");
163+
}
164+
}
165+
}
166+
catch (Exception exception)
167+
{
168+
Console.WriteLine(exception);
169+
throw;
170+
}
171+
}
133172
}

0 commit comments

Comments
 (0)