Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/[ApplicationNameUpperCamelCase]/App.axaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SiteMonitor.App"
xmlns:siteMonitor="clr-namespace:SiteMonitor"
x:Class="ApplicationNameUpperCamelCase.App"
xmlns:applicationNameUpperCamelCase="clr-namespace:ApplicationNameUpperCamelCase"
RequestedThemeVariant="Dark">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.DataTemplates>
<siteMonitor:ViewLocator />
<applicationNameUpperCamelCase:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
Expand All @@ -16,7 +16,7 @@
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/logo.ico"
ToolTipText="Nullinside Site Monitor">
ToolTipText="ApplicationNameUpperCamelCase">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Show" Click="ShowSettings_OnClick" />
Expand Down
8 changes: 3 additions & 5 deletions src/[ApplicationNameUpperCamelCase]/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;

using ApplicationNameUpperCamelCase.ViewModels;
using ApplicationNameUpperCamelCase.Views;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

using SiteMonitor.ViewModels;
using SiteMonitor.Views;

namespace SiteMonitor;
namespace ApplicationNameUpperCamelCase;

/// <summary>
/// Main entry point of the application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Newtonsoft.Json;

namespace SiteMonitor.Models;
namespace ApplicationNameUpperCamelCase.Models;

/// <summary>
/// The configuration of the application.
Expand Down
2 changes: 1 addition & 1 deletion src/[ApplicationNameUpperCamelCase]/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Avalonia;
using Avalonia.ReactiveUI;

namespace SiteMonitor;
namespace ApplicationNameUpperCamelCase;

internal sealed class Program {
// Initialization code. Don't use any Avalonia, third-party APIs or any
Expand Down
6 changes: 2 additions & 4 deletions src/[ApplicationNameUpperCamelCase]/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;

using ApplicationNameUpperCamelCase.ViewModels;
using Avalonia.Controls;
using Avalonia.Controls.Templates;

using SiteMonitor.ViewModels;

namespace SiteMonitor;
namespace ApplicationNameUpperCamelCase;

/// <summary>
/// Pre-generated for us.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
Expand All @@ -10,17 +11,29 @@

using ReactiveUI;

using SiteMonitor.Models;
using ApplicationNameUpperCamelCase.Models;

namespace SiteMonitor.ViewModels;
namespace ApplicationNameUpperCamelCase.ViewModels;

/// <summary>
/// The view model for the main UI.
/// </summary>
public class MainWindowViewModel : ViewModelBase {
/// <summary>
/// True if the application is updating, false otherwise.
/// </summary>
private bool _isUpdating;
/// <summary>
/// Initializes a new instance of the <see cref="MainWindowViewModel" /> class.
/// </summary>
public MainWindowViewModel() {
_isUpdating = Environment.GetCommandLineArgs().ToList().Contains("--update");
}
/// <summary>
/// True if the application is updating, false otherwise.
/// </summary>
public bool IsUpdating {
get => _isUpdating;
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Input;

using ApplicationNameUpperCamelCase.Views;
using Avalonia.Controls;
using Avalonia.Threading;

using Nullinside.Api.Common.Desktop;

using ReactiveUI;

using SiteMonitor.Views;

namespace SiteMonitor.ViewModels;
namespace ApplicationNameUpperCamelCase.ViewModels;

/// <summary>
/// The view model for the <seealso cref="NewVersionWindow" /> class.
/// </summary>
public class NewVersionWindowViewModel : ViewModelBase {
/// <summary>
/// True if updating the application currently, false otherwise.
/// </summary>
private bool _isUpdating;

/// <summary>
/// The local version of the software.
/// </summary>
Expand All @@ -36,12 +39,12 @@ public class NewVersionWindowViewModel : ViewModelBase {
/// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
/// </summary>
public NewVersionWindowViewModel() {
OpenBrowser = ReactiveCommand.Create(LaunchBrowser);
UpdateSoftware = ReactiveCommand.Create(StartUpdateSoftware);
CloseWindow = ReactiveCommand.Create<Window>(CloseWindowCommand);

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

if (null == version) {
return;
Expand Down Expand Up @@ -69,9 +72,17 @@ public string? ServerVersion {
}

/// <summary>
/// A command to open the browser window at the current update's location.
/// True if updating the application currently, false otherwise.
/// </summary>
public ICommand OpenBrowser { get; }
public bool IsUpdating {
get => _isUpdating;
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
}

/// <summary>
/// A command to update the software.
/// </summary>
public ICommand UpdateSoftware { get; }

/// <summary>
/// A command to close the current window.
Expand All @@ -89,11 +100,16 @@ private void CloseWindowCommand(Window self) {
/// <summary>
/// Launches the web browser at the new release page.
/// </summary>
private void LaunchBrowser() {
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
return;
}

Process.Start("explorer", _newVersionUrl);
private void StartUpdateSoftware() {
IsUpdating = true;
GitHubUpdateManager.PrepareUpdate()
.ContinueWith(_ => {
if (string.IsNullOrWhiteSpace(_newVersionUrl)) {
return;
}

Process.Start("explorer", _newVersionUrl);
GitHubUpdateManager.ExitApplicationToUpdate();
}).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ReactiveUI;

namespace SiteMonitor.ViewModels;
namespace ApplicationNameUpperCamelCase.ViewModels;

/// <summary>
/// A base class for all view models.
Expand Down
30 changes: 30 additions & 0 deletions src/[ApplicationNameUpperCamelCase]/Views/Loading.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="200" Height="200"
x:Class="ApplicationNameUpperCamelCase.Views.Loading">
<UserControl.Styles>
<Style Selector="Rectangle.textColor">
<Setter Property="Fill" Value="rgb(204, 200, 175)" />
<Style.Animations>
<Animation Duration="0:0:1" IterationCount="INFINITE">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0.0" />
<Setter Property="RotateTransform.Angle" Value="0.0" />
</KeyFrame>
<KeyFrame Cue="50%">
<Setter Property="Opacity" Value="1.0" />
<Setter Property="RotateTransform.Angle" Value="90.0" />
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="0.0" />
<Setter Property="RotateTransform.Angle" Value="180.0" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</UserControl.Styles>

<Rectangle Classes="textColor" Width="50" Height="50" />
</UserControl>
16 changes: 16 additions & 0 deletions src/[ApplicationNameUpperCamelCase]/Views/Loading.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Avalonia;
using Avalonia.Controls;

namespace ApplicationNameUpperCamelCase.Views;

/// <summary>
/// A loading icon.
/// </summary>
public partial class Loading : UserControl {
/// <summary>
/// Initializes a new instance of the <see cref="Loading" /> class.
/// </summary>
public Loading() {
InitializeComponent();
}
}
40 changes: 33 additions & 7 deletions src/[ApplicationNameUpperCamelCase]/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,52 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:SiteMonitor.ViewModels"
xmlns:viewModels="clr-namespace:ApplicationNameUpperCamelCase.ViewModels"
xmlns:views="clr-namespace:ApplicationNameUpperCamelCase.Views"
mc:Ignorable="d"
d:DesignWidth="475"
d:DesignHeight="300"
MinWidth="475"
MinHeight="300"
Width="475"
Height="300"
CanResize="False"
CanResize="True"
WindowStartupLocation="CenterScreen"
x:Class="SiteMonitor.Views.MainWindow"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="NoChrome"
ExtendClientAreaTitleBarHeightHint="-1"
x:Class="ApplicationNameUpperCamelCase.Views.MainWindow"
x:DataType="viewModels:MainWindowViewModel"
Icon="/Assets/logo.ico"
Title="Site Monitor">
Title="ApplicationNameUpperCamelCase">

<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<viewModels:MainWindowViewModel />
</Design.DataContext>

<Grid Margin="20">
<Label>Hello World</Label>
</Grid>
<DockPanel HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Name="ContentWrapper">
<views:WindowsTitleBar IsSeamless="True" />
<!-- The Application is Currently Updating and Not Usable!: This must come first because the final item always fills. -->
<DockPanel Background="Transparent" DockPanel.Dock="Top" IsVisible="{Binding IsUpdating}">
<StackPanel>
<Label HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="32"
FontWeight="Bold"
Foreground="rgb(204, 200, 175)"
Padding="0 50 0 0">
Updating
</Label>
<views:Loading Width="100" Height="100" />
</StackPanel>
</DockPanel>
<!-- The normal application: This must come last because the last item always fills. -->
<DockPanel Background="Transparent" DockPanel.Dock="Top" IsVisible="{Binding !IsUpdating}">
<Label>Hello World</Label>
</DockPanel>
</DockPanel>
</Window>
Loading
Loading