Skip to content

Commit 79329d5

Browse files
feat: improving update process
This is a "try it in prod" situation. I need the executables to both have the new updater to a real test of the code. #6
1 parent 8c5625f commit 79329d5

File tree

5 files changed

+63
-20
lines changed

5 files changed

+63
-20
lines changed

src/TwitchStreamingTools/ViewModels/MainWindowViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class MainWindowViewModel : ViewModelBase {
4040
/// </summary>
4141
private MenuItem _selectedMenuItem;
4242

43+
private string? _error;
44+
4345
/// <summary>
4446
/// Initializes a new instance of the <see cref="MainWindowViewModel" /> class.
4547
/// </summary>
@@ -102,6 +104,14 @@ public MenuItem SelectedMenuItem {
102104
set => this.RaiseAndSetIfChanged(ref _selectedMenuItem, value);
103105
}
104106

107+
/// <summary>
108+
/// fuck
109+
/// </summary>
110+
public string? Error {
111+
get => _error;
112+
set => this.RaiseAndSetIfChanged(ref _error, value);
113+
}
114+
105115
/// <summary>
106116
/// Links the <see cref="Page" /> showing on the screen with changes to the <see cref="SelectedMenuItem" />.
107117
/// </summary>

src/TwitchStreamingTools/ViewModels/NewVersionWindowViewModel.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ private void CloseWindowCommand(Window self) {
9090
/// Launches the web browser at the new release page.
9191
/// </summary>
9292
private void LaunchBrowser() {
93-
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
94-
return;
95-
}
96-
97-
Process.Start("explorer", _newVersionUrl);
93+
GitHubUpdateManager.PrepareUpdate()
94+
.ContinueWith(_ => {
95+
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
96+
return;
97+
}
98+
99+
Process.Start("explorer", _newVersionUrl);
100+
GitHubUpdateManager.ExitApplicationToUpdate();
101+
}).ConfigureAwait(false);
98102
}
99103
}

src/TwitchStreamingTools/Views/MainWindow.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<SplitView.Pane>
5858
<StackPanel Spacing="5"
5959
Margin="5">
60+
<TextBox Text="{Binding Error}"/>
6061
<Button Command="{Binding OnToggleMenu}">
6162
<PathIcon Data="{StaticResource LineHorizontal3Regular}" />
6263
</Button>

src/TwitchStreamingTools/Views/MainWindow.axaml.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
#if !DEBUG
2+
using Avalonia.Threading;
3+
4+
using Microsoft.Extensions.DependencyInjection;
5+
#endif
6+
using TwitchStreamingTools.ViewModels;
7+
8+
using Avalonia;
9+
110
using System;
11+
using System.Linq;
212
using System.Reflection;
313
using System.Threading.Tasks;
414

515
using Avalonia.Controls;
6-
7-
using Nullinside.Api.Common.Desktop;
8-
#if !DEBUG
916
using Avalonia.Threading;
1017

11-
using Microsoft.Extensions.DependencyInjection;
12-
13-
using TwitchStreamingTools.ViewModels;
14-
#else
15-
using Avalonia;
16-
#endif
18+
using Nullinside.Api.Common.Desktop;
1719

1820
namespace TwitchStreamingTools.Views;
1921

@@ -43,6 +45,25 @@ public MainWindow() {
4345
protected override void OnInitialized() {
4446
base.OnInitialized();
4547

48+
string[] args = Environment.GetCommandLineArgs();
49+
if (args.Contains("--update")) {
50+
_ = GitHubUpdateManager.PerformUpdateAndRestart("nullinside-development-group", "twitch-streaming-tools", args[2], "windows-x64.zip").ContinueWith(t => {
51+
Dispatcher.UIThread.Invoke(() => {
52+
var fuck = (this.DataContext as MainWindowViewModel);
53+
if (null == fuck) {
54+
return;
55+
}
56+
57+
fuck.Error = t.Exception?.Message ?? "No error message was provided.";
58+
});
59+
});
60+
return;
61+
}
62+
63+
if (args.Contains("--justUpdated")) {
64+
_ = GitHubUpdateManager.CleanupUpdate();
65+
}
66+
4667
Task.Factory.StartNew(async () => {
4768
GithubLatestReleaseJson? serverVersion =
4869
await GitHubUpdateManager.GetLatestVersion("nullinside-development-group", "twitch-streaming-tools");
@@ -72,12 +93,19 @@ protected override void OnInitialized() {
7293
}
7394

7495
vm.LocalVersion = localVersion;
75-
Dispatcher.UIThread.Post(async () => {
76-
var versionWindow = new NewVersionWindow {
77-
DataContext = vm
78-
};
96+
Dispatcher.UIThread.Post(async void () => {
97+
try
98+
{
99+
var versionWindow = new NewVersionWindow {
100+
DataContext = vm
101+
};
79102

80-
await versionWindow.ShowDialog(this);
103+
await versionWindow.ShowDialog(this);
104+
}
105+
catch
106+
{
107+
// do nothing, don't crash
108+
}
81109
});
82110
#endif
83111
});

0 commit comments

Comments
 (0)