Skip to content

Commit 7fd4f68

Browse files
authored
Add download update button (#135)
* add basic button ui * add button to go to github downloads page
1 parent bc7338d commit 7fd4f68

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Gui/ViewModels/MainWindowViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System;
1313
using System.Collections.Generic;
1414
using System.Collections.ObjectModel;
15+
using System.Diagnostics;
1516
using System.IO;
1617
using System.Linq;
1718
using System.Reactive;
@@ -55,6 +56,7 @@ public class MainWindowViewModel : ViewModelBase
5556
public ReactiveCommand<Unit, Task> UseDefaultPalette { get; }
5657
public ReactiveCommand<Unit, Task> UseCustomPalette { get; }
5758
public ReactiveCommand<Unit, Unit> EditSettingsCommand { get; }
59+
public ReactiveCommand<Unit, Process?> OpenDownloadLink { get; }
5860

5961
public const string GithubApplicationName = "ObjectEditor";
6062
public const string GithubIssuePage = "https://github.com/OpenLoco/ObjectEditor/issues";
@@ -69,6 +71,9 @@ public class MainWindowViewModel : ViewModelBase
6971
[Reactive]
7072
public string LatestVersionText { get; set; } = "Development build";
7173

74+
[Reactive]
75+
public bool IsUpdateAvailable { get; set; }
76+
7277
const string DefaultPaletteImageString = "avares://ObjectEditor/Assets/palette.png";
7378
Image<Rgba32> DefaultPaletteImage { get; init; }
7479

@@ -118,6 +123,8 @@ public MainWindowViewModel()
118123
Model.Settings.Save(ObjectEditorModel.SettingsFile, Model.Logger);
119124
});
120125

126+
OpenDownloadLink = ReactiveCommand.Create(() => Process.Start(new ProcessStartInfo(GithubLatestReleaseDownloadPage) { UseShellExecute = true }));
127+
121128
#region Version
122129

123130
_ = this.WhenAnyValue(o => o.ApplicationVersion)
@@ -137,18 +144,19 @@ public MainWindowViewModel()
137144
if (latestVersion > ApplicationVersion)
138145
{
139146
LatestVersionText = $"newer version exists: {latestVersion}";
147+
IsUpdateAvailable = true;
140148
}
141149
else
142150
{
143151
LatestVersionText = "latest version";
152+
IsUpdateAvailable = false;
144153
}
145154
}
146155
catch (Exception ex)
147156
{
148157
Model.Logger.Error(ex);
149158
}
150159
#endif
151-
152160
#endregion
153161
}
154162

Gui/Views/MainWindow.axaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,13 @@
674674
<MenuItem Header="Open downloads folder" Command="{Binding OpenDownloadFolder}" />
675675
</MenuItem>
676676
</Menu>
677-
<ToggleSwitch IsChecked="{Binding IsDarkTheme, Mode=TwoWay}" HorizontalAlignment="Right" OnContent="{materialIcons:MaterialIconExt Kind=MoonWaningCrescent}" OffContent="{materialIcons:MaterialIconExt Kind=WeatherSunny}" />
677+
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
678+
<Button Margin="4" Command="{Binding OpenDownloadLink}" IsVisible="{Binding IsUpdateAvailable}" IsEnabled="{Binding IsUpdateAvailable}">
679+
New version available!
680+
</Button>
681+
<Panel Margin="4" Width="32"/>
682+
<ToggleSwitch Margin="4" IsChecked="{Binding IsDarkTheme, Mode=TwoWay}" OnContent="{materialIcons:MaterialIconExt Kind=MoonWaningCrescent}" OffContent="{materialIcons:MaterialIconExt Kind=WeatherSunny}" />
683+
</StackPanel>
678684
</DockPanel>
679685
<Expander Header="Logs" Padding="0" ExpandDirection="Down" DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Margin="8" MaxHeight="512">
680686
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">

0 commit comments

Comments
 (0)