Skip to content

Commit fd9c3c1

Browse files
Merge pull request #7 from nullinside-development-group/fix/update
feat: updating based on improvements made
2 parents dc7a5d7 + 62a063d commit fd9c3c1

18 files changed

+507
-79
lines changed

src/[ApplicationNameUpperCamelCase]/App.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Application xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
x:Class="SiteMonitor.App"
4-
xmlns:siteMonitor="clr-namespace:SiteMonitor"
3+
x:Class="ApplicationNameUpperCamelCase.App"
4+
xmlns:applicationNameUpperCamelCase="clr-namespace:ApplicationNameUpperCamelCase"
55
RequestedThemeVariant="Dark">
66
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
77

88
<Application.DataTemplates>
9-
<siteMonitor:ViewLocator />
9+
<applicationNameUpperCamelCase:ViewLocator />
1010
</Application.DataTemplates>
1111

1212
<Application.Styles>
@@ -16,7 +16,7 @@
1616
<TrayIcon.Icons>
1717
<TrayIcons>
1818
<TrayIcon Icon="/Assets/logo.ico"
19-
ToolTipText="Nullinside Site Monitor">
19+
ToolTipText="ApplicationNameUpperCamelCase">
2020
<TrayIcon.Menu>
2121
<NativeMenu>
2222
<NativeMenuItem Header="Show" Click="ShowSettings_OnClick" />

src/[ApplicationNameUpperCamelCase]/App.axaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
2-
2+
using ApplicationNameUpperCamelCase.ViewModels;
3+
using ApplicationNameUpperCamelCase.Views;
34
using Avalonia;
45
using Avalonia.Controls;
56
using Avalonia.Controls.ApplicationLifetimes;
67
using Avalonia.Markup.Xaml;
78

8-
using SiteMonitor.ViewModels;
9-
using SiteMonitor.Views;
10-
11-
namespace SiteMonitor;
9+
namespace ApplicationNameUpperCamelCase;
1210

1311
/// <summary>
1412
/// Main entry point of the application.

src/[ApplicationNameUpperCamelCase]/Models/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Newtonsoft.Json;
55

6-
namespace SiteMonitor.Models;
6+
namespace ApplicationNameUpperCamelCase.Models;
77

88
/// <summary>
99
/// The configuration of the application.

src/[ApplicationNameUpperCamelCase]/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Avalonia;
44
using Avalonia.ReactiveUI;
55

6-
namespace SiteMonitor;
6+
namespace ApplicationNameUpperCamelCase;
77

88
internal sealed class Program {
99
// Initialization code. Don't use any Avalonia, third-party APIs or any

src/[ApplicationNameUpperCamelCase]/ViewLocator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
2-
2+
using ApplicationNameUpperCamelCase.ViewModels;
33
using Avalonia.Controls;
44
using Avalonia.Controls.Templates;
55

6-
using SiteMonitor.ViewModels;
7-
8-
namespace SiteMonitor;
6+
namespace ApplicationNameUpperCamelCase;
97

108
/// <summary>
119
/// Pre-generated for us.

src/[ApplicationNameUpperCamelCase]/ViewModels/MainWindowViewModel.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Net;
34
using System.Net.Http;
45
using System.Net.NetworkInformation;
@@ -10,17 +11,29 @@
1011

1112
using ReactiveUI;
1213

13-
using SiteMonitor.Models;
14+
using ApplicationNameUpperCamelCase.Models;
1415

15-
namespace SiteMonitor.ViewModels;
16+
namespace ApplicationNameUpperCamelCase.ViewModels;
1617

1718
/// <summary>
1819
/// The view model for the main UI.
1920
/// </summary>
2021
public class MainWindowViewModel : ViewModelBase {
22+
/// <summary>
23+
/// True if the application is updating, false otherwise.
24+
/// </summary>
25+
private bool _isUpdating;
2126
/// <summary>
2227
/// Initializes a new instance of the <see cref="MainWindowViewModel" /> class.
2328
/// </summary>
2429
public MainWindowViewModel() {
30+
_isUpdating = Environment.GetCommandLineArgs().ToList().Contains("--update");
31+
}
32+
/// <summary>
33+
/// True if the application is updating, false otherwise.
34+
/// </summary>
35+
public bool IsUpdating {
36+
get => _isUpdating;
37+
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
2538
}
2639
}

src/[ApplicationNameUpperCamelCase]/ViewModels/NewVersionWindowViewModel.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
using System.Diagnostics;
22
using System.Threading.Tasks;
33
using System.Windows.Input;
4-
4+
using ApplicationNameUpperCamelCase.Views;
55
using Avalonia.Controls;
66
using Avalonia.Threading;
77

88
using Nullinside.Api.Common.Desktop;
99

1010
using ReactiveUI;
1111

12-
using SiteMonitor.Views;
13-
14-
namespace SiteMonitor.ViewModels;
12+
namespace ApplicationNameUpperCamelCase.ViewModels;
1513

1614
/// <summary>
1715
/// The view model for the <seealso cref="NewVersionWindow" /> class.
1816
/// </summary>
1917
public class NewVersionWindowViewModel : ViewModelBase {
18+
/// <summary>
19+
/// True if updating the application currently, false otherwise.
20+
/// </summary>
21+
private bool _isUpdating;
22+
2023
/// <summary>
2124
/// The local version of the software.
2225
/// </summary>
@@ -36,12 +39,12 @@ public class NewVersionWindowViewModel : ViewModelBase {
3639
/// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
3740
/// </summary>
3841
public NewVersionWindowViewModel() {
39-
OpenBrowser = ReactiveCommand.Create(LaunchBrowser);
42+
UpdateSoftware = ReactiveCommand.Create(StartUpdateSoftware);
4043
CloseWindow = ReactiveCommand.Create<Window>(CloseWindowCommand);
4144

4245
Task.Factory.StartNew(async () => {
4346
GithubLatestReleaseJson? version =
44-
await GitHubUpdateManager.GetLatestVersion("nullinside-development-group", "nullinside-site-monitor");
47+
await GitHubUpdateManager.GetLatestVersion("nullinside-development-group", "ApplicationNameUpperCamelCase");
4548

4649
if (null == version) {
4750
return;
@@ -69,9 +72,17 @@ public string? ServerVersion {
6972
}
7073

7174
/// <summary>
72-
/// A command to open the browser window at the current update's location.
75+
/// True if updating the application currently, false otherwise.
7376
/// </summary>
74-
public ICommand OpenBrowser { get; }
77+
public bool IsUpdating {
78+
get => _isUpdating;
79+
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
80+
}
81+
82+
/// <summary>
83+
/// A command to update the software.
84+
/// </summary>
85+
public ICommand UpdateSoftware { get; }
7586

7687
/// <summary>
7788
/// A command to close the current window.
@@ -89,11 +100,16 @@ private void CloseWindowCommand(Window self) {
89100
/// <summary>
90101
/// Launches the web browser at the new release page.
91102
/// </summary>
92-
private void LaunchBrowser() {
93-
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
94-
return;
95-
}
96-
97-
Process.Start("explorer", _newVersionUrl);
103+
private void StartUpdateSoftware() {
104+
IsUpdating = true;
105+
GitHubUpdateManager.PrepareUpdate()
106+
.ContinueWith(_ => {
107+
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
108+
return;
109+
}
110+
111+
Process.Start("explorer", _newVersionUrl);
112+
GitHubUpdateManager.ExitApplicationToUpdate();
113+
}).ConfigureAwait(false);
98114
}
99115
}

src/[ApplicationNameUpperCamelCase]/ViewModels/ViewModelBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using ReactiveUI;
22

3-
namespace SiteMonitor.ViewModels;
3+
namespace ApplicationNameUpperCamelCase.ViewModels;
44

55
/// <summary>
66
/// A base class for all view models.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" Width="200" Height="200"
6+
x:Class="ApplicationNameUpperCamelCase.Views.Loading">
7+
<UserControl.Styles>
8+
<Style Selector="Rectangle.textColor">
9+
<Setter Property="Fill" Value="rgb(204, 200, 175)" />
10+
<Style.Animations>
11+
<Animation Duration="0:0:1" IterationCount="INFINITE">
12+
<KeyFrame Cue="0%">
13+
<Setter Property="Opacity" Value="0.0" />
14+
<Setter Property="RotateTransform.Angle" Value="0.0" />
15+
</KeyFrame>
16+
<KeyFrame Cue="50%">
17+
<Setter Property="Opacity" Value="1.0" />
18+
<Setter Property="RotateTransform.Angle" Value="90.0" />
19+
</KeyFrame>
20+
<KeyFrame Cue="100%">
21+
<Setter Property="Opacity" Value="0.0" />
22+
<Setter Property="RotateTransform.Angle" Value="180.0" />
23+
</KeyFrame>
24+
</Animation>
25+
</Style.Animations>
26+
</Style>
27+
</UserControl.Styles>
28+
29+
<Rectangle Classes="textColor" Width="50" Height="50" />
30+
</UserControl>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
4+
namespace ApplicationNameUpperCamelCase.Views;
5+
6+
/// <summary>
7+
/// A loading icon.
8+
/// </summary>
9+
public partial class Loading : UserControl {
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="Loading" /> class.
12+
/// </summary>
13+
public Loading() {
14+
InitializeComponent();
15+
}
16+
}

0 commit comments

Comments
 (0)