Skip to content

Commit 9befa95

Browse files
Merge pull request #27 from nullinside-development-group/feat/update
feat: improving update process
2 parents 8c5625f + 4afcecc commit 9befa95

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
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: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
#if !DEBUG
2+
using Microsoft.Extensions.DependencyInjection;
3+
#else
4+
using Avalonia;
5+
#endif
16
using System;
7+
using System.Linq;
28
using System.Reflection;
39
using System.Threading.Tasks;
410

511
using Avalonia.Controls;
6-
7-
using Nullinside.Api.Common.Desktop;
8-
#if !DEBUG
912
using Avalonia.Threading;
1013

11-
using Microsoft.Extensions.DependencyInjection;
14+
using Nullinside.Api.Common.Desktop;
1215

1316
using TwitchStreamingTools.ViewModels;
14-
#else
15-
using Avalonia;
16-
#endif
1717

1818
namespace TwitchStreamingTools.Views;
1919

@@ -43,6 +43,25 @@ public MainWindow() {
4343
protected override void OnInitialized() {
4444
base.OnInitialized();
4545

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

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

80-
await versionWindow.ShowDialog(this);
101+
await versionWindow.ShowDialog(this);
102+
}
103+
catch
104+
{
105+
// do nothing, don't crash
106+
}
81107
});
82108
#endif
83109
});

0 commit comments

Comments
 (0)