Skip to content

Commit

Permalink
[Updater] Updater configuration panel
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Mar 16, 2021
1 parent e062268 commit 85c5614
Show file tree
Hide file tree
Showing 32 changed files with 283 additions and 53 deletions.
4 changes: 4 additions & 0 deletions AvaloniaStyles/Styles/BigSur/Style.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml"/>

<Style Selector="TextBlock">
<Setter Property="FontSize" Value="13" />
</Style>

<StyleInclude Source="avares://AvaloniaStyles/Styles/BigSur/PopupRoot.xaml"/>
<StyleInclude Source="avares://AvaloniaStyles/Styles/BigSur/TreeView.xaml"/>
<StyleInclude Source="avares://AvaloniaStyles/Styles/BigSur/TreeViewItem.xaml"/>
Expand Down
7 changes: 5 additions & 2 deletions WDE.Common.WPF/ViewHelpers/NullToVisibilityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ namespace WDE.Common.WPF.ViewHelpers
{
public class NullToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public Visibility WhenNull { get; set; } = Visibility.Hidden;
public Visibility WhenNotNull { get; set; } = Visibility.Visible;

public object Convert(object? value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Hidden : Visibility.Visible;
return value == null ? WhenNull : WhenNotNull;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
1 change: 1 addition & 0 deletions WDE.CommonViews.Avalonia/CommonViewsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override void RegisterViews(IViewLocator viewLocator)
viewLocator.Bind<SqlEditorViewModel, SqlEditorView>();
// updater
viewLocator.Bind<ChangeLogViewModel, ChangeLogView>();
viewLocator.Bind<UpdaterConfigurationViewModel, UpdaterConfigurationView>();
}
}
}
10 changes: 5 additions & 5 deletions WDE.CommonViews.Avalonia/DbcStore/Views/DBCConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Path to DBC/DB2s" VerticalContentAlignment="Center" />
<TextBox Margin="5" Grid.Column="1" Grid.Row="0"
Text="{Binding Path, Mode=TwoWay}" Padding="5" Name="Path" />
<TextBlock Text="Path to DBC/DB2s" VerticalAlignment="Center" />
<TextBlock Margin="5" Grid.Column="1" Grid.Row="0"
Text="{Binding Path, Mode=TwoWay}" Padding="5" Name="Path" />
<Button Grid.Column="2" Grid.Row="0" Padding="5" VerticalAlignment="Center" Command="{Binding PickFolder}">...</Button>

<Label Content="DBC/DB2 Version" VerticalContentAlignment="Center" Grid.Row="1" />
<TextBlock Text="DBC/DB2 Version" VerticalAlignment="Center" Grid.Row="1" />
<ComboBox Name="dbcVersion" Grid.Row="1" Grid.Column="1" Margin="5" Padding="5" VerticalAlignment="Center"
Items="{Binding DBCVersions}"
SelectedItem="{Binding DBCVersion}" />

<Label Content="Skip loading dbc" VerticalContentAlignment="Center" Grid.Row="2" />
<TextBlock Text="Skip loading dbc" VerticalAlignment="Center" Grid.Row="2" />
<CheckBox Grid.Column="1" IsChecked="{Binding SkipLoading}" Padding="0" Margin="0" Grid.Row="2"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Host" />
<Label Content="Port" Grid.Row="1"/>
<Label Content="User" Grid.Row="2" />
<Label Content="Password" Grid.Row="3" />
<Label Content="Database" Grid.Row="4" />
<TextBlock Text="Host" VerticalAlignment="Center" />
<TextBlock Text="Port" Grid.Row="1" VerticalAlignment="Center" />
<TextBlock Text="User" Grid.Row="2" VerticalAlignment="Center" />
<TextBlock Text="Password" Grid.Row="3" VerticalAlignment="Center" />
<TextBlock Text="Database" Grid.Row="4" VerticalAlignment="Center" />
<TextBox Margin="5" Grid.Column="1" Grid.Row="0" Text="{Binding Host, Mode=TwoWay}" />
<TextBox Margin="5" Grid.Column="1" Grid.Row="1" Text="{Binding Port, Mode=TwoWay}" />
<TextBox Margin="5" Grid.Column="1" Grid.Row="2" Text="{Binding User, Mode=TwoWay}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<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"
xmlns:converters="clr-namespace:WDE.Common.Avalonia.Converters;assembly=WDE.Common.Avalonia"
xmlns:mvvm="http://prismlibrary.com/"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
mvvm:ViewModelLocator.AutoWireViewModel="False"
x:Class="WDE.CommonViews.Avalonia.Updater.Views.UpdaterConfigurationView">
<UserControl.Resources>
<converters:DataTimeToStringConverter x:Key="DateConverter" Format="f" />
</UserControl.Resources>
<Grid RowDefinitions="Auto,10,Auto,10,Auto,10,Auto,30,Auto" ColumnDefinitions="Auto,10,*">
<TextBlock Text="Current version"
Grid.Row="0" />
<TextBlock Text="{Binding CurrentVersion}"
Grid.Row="0" Grid.Column="2"/>
<TextBlock Text="Last checked updates"
Grid.Row="2"/>
<TextBlock Text="{Binding LastCheckForUpdates, Converter={StaticResource DateConverter}}"
Grid.Row="2" Grid.Column="2"/>
<Button Command="{Binding CheckForUpdatesCommand}"
Grid.Column="2"
Grid.Row="4">Check for updates</Button>
<Button Command="{Binding ShowChangelog}"
Grid.Column="2"
Grid.Row="6">Show changelog</Button>

<TextBlock Text="Disable auto updates"
Grid.Row="8"/>
<CheckBox IsChecked="{Binding DisableAutoUpdates}"
Grid.Row="8" Grid.Column="2"/>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace WDE.CommonViews.Avalonia.Updater.Views
{
public class UpdaterConfigurationView : UserControl
{
public UpdaterConfigurationView()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
1 change: 1 addition & 0 deletions WDE.CommonViews.WPF/CommonViewsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override void RegisterViews(IViewLocator viewLocator)
viewLocator.Bind<SqlEditorViewModel, SqlEditorView>();
// updater
viewLocator.Bind<ChangeLogViewModel, ChangeLogView>();
viewLocator.Bind<UpdaterConfigurationViewModel, UpdaterConfigurationView>();
}
}
}
1 change: 1 addition & 0 deletions WDE.CommonViews.WPF/Updater/ChangeLogView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModels:ChangeLogViewModel}"
Padding="15"
Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<converters:DataTimeToStringConverter Format="m" x:Key="TimeConverter"/>
Expand Down
36 changes: 36 additions & 0 deletions WDE.CommonViews.WPF/Updater/UpdaterConfigurationView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<UserControl x:Class="WDE.CommonViews.WPF.Updater.UpdaterConfigurationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mvvm:ViewModelLocator.AutoWireViewModel="False"
xmlns:converters="clr-namespace:WDE.Common.WPF.Converters;assembly=WDE.Common.WPF"
xmlns:mvvm="http://prismlibrary.com/"
xmlns:utils="clr-namespace:WDE.Common.WPF.Utils;assembly=WDE.Common.WPF"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<converters:DataTimeToStringConverter x:Key="DateConverter" Format="f" />
</UserControl.Resources>
<Grid utils:GridUtils.Rows="Auto,10,Auto,10,Auto,10,Auto,30,Auto" utils:GridUtils.Columns="Auto,10,*" VerticalAlignment="Top">
<TextBlock Text="Current version"
Grid.Row="0" />
<TextBlock Text="{Binding CurrentVersion}"
Grid.Row="0" Grid.Column="2"/>
<TextBlock Text="Last checked updates"
Grid.Row="2"/>
<TextBlock Text="{Binding LastCheckForUpdates, Converter={StaticResource DateConverter}}"
Grid.Row="2" Grid.Column="2"/>
<Button Command="{Binding CheckForUpdatesCommand}"
Grid.Column="2"
Grid.Row="4">Check for updates</Button>
<Button Command="{Binding ShowChangelog}"
Grid.Column="2"
Grid.Row="6">Show changelog</Button>

<TextBlock Text="Disable auto updates"
Grid.Row="8"/>
<CheckBox IsChecked="{Binding DisableAutoUpdates}"
Grid.Row="8" Grid.Column="2"/>
</Grid>
</UserControl>
12 changes: 12 additions & 0 deletions WDE.CommonViews.WPF/Updater/UpdaterConfigurationView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Windows.Controls;

namespace WDE.CommonViews.WPF.Updater
{
public partial class UpdaterConfigurationView : UserControl
{
public UpdaterConfigurationView()
{
InitializeComponent();
}
}
}
3 changes: 2 additions & 1 deletion WDE.Parameters/ViewModels/ParametersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public bool HasSelected
public ICommand Save { get; }

public string Name => "Parameters browser";

public string ShortDescription => null;

public bool IsModified => false;

public bool IsRestartRequired => false;
Expand Down
1 change: 1 addition & 0 deletions WDE.ThemeChanger/ViewModels/ThemeConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public List<Theme> Themes

public ICommand Save { get; }
public string Name => "Appearance";
public string ShortDescription => null;
public bool IsRestartRequired => false;

private bool isModified;
Expand Down
18 changes: 10 additions & 8 deletions WDE.Updater.Test/Services/UpdateServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class UpdateServiceTest
private IFileSystem fileSystem = null!;
private IStandaloneUpdater standaloneUpdate = null!;
private IUpdateClient updateClient = null!;
private IUpdaterSettingsProvider settings = null!;

[SetUp]
public void Init()
Expand All @@ -31,6 +32,7 @@ public void Init()
fileSystem = Substitute.For<IFileSystem>();
standaloneUpdate = Substitute.For<IStandaloneUpdater>();
updateClient = Substitute.For<IUpdateClient>();
settings = Substitute.For<IUpdaterSettingsProvider>();
clientFactory
.Create(Arg.Any<Uri>(), Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<Platforms>())
.Returns(updateClient);
Expand All @@ -42,7 +44,7 @@ public void TestNoUpdateIfNoVersion()
applicationVersion.VersionKnown.Returns(false);

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

Assert.IsFalse(updateService.CanCheckForUpdates());
}
Expand All @@ -53,7 +55,7 @@ public void TestNoUpdateIfNoUpdateData()
data.HasUpdateServerData.Returns(false);

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

Assert.IsFalse(updateService.CanCheckForUpdates());
}
Expand All @@ -65,7 +67,7 @@ public void TestCanCheckForUpdatesIfHaveData()
data.HasUpdateServerData.Returns(true);

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

Assert.IsTrue(updateService.CanCheckForUpdates());
}
Expand All @@ -80,7 +82,7 @@ public async Task TestCheckForUpdatesNoUpdateLink()
.Returns(new CheckVersionResponse() {DownloadUrl = null, LatestVersion = 2});

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

Assert.IsNull(await updateService.CheckForUpdates());
}
Expand All @@ -96,7 +98,7 @@ public async Task TestCheckForUpdatesNoUpdate()
.Returns(new CheckVersionResponse() {DownloadUrl = null, LatestVersion = 1});

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

Assert.IsNull(await updateService.CheckForUpdates());
}
Expand All @@ -111,7 +113,7 @@ public async Task TestCheckForUpdatesHasUpdate()
.Returns(new CheckVersionResponse() {DownloadUrl = "localhost", LatestVersion = 2});

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

Assert.AreEqual("localhost", await updateService.CheckForUpdates());
}
Expand All @@ -121,7 +123,7 @@ public async Task TestCloseForUpdateAsks()
{
application.CanClose().Returns(Task.FromResult(false));
var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

await updateService.CloseForUpdate();

Expand All @@ -136,7 +138,7 @@ public async Task TestCloseForUpdate()
{
application.CanClose().Returns(Task.FromResult(true));
var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate);
standaloneUpdate, settings);

await updateService.CloseForUpdate();

Expand Down
2 changes: 2 additions & 0 deletions WDE.Updater/Data/UpdaterSettings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using WDE.Common.Services;

Expand All @@ -8,5 +9,6 @@ public struct UpdaterSettings : ISettings
{
public bool DisableAutoUpdates { get; set; }
public long LastShowedChangelog { get; set; }
public DateTime LastCheckedForUpdates { get; set; }
}
}
11 changes: 8 additions & 3 deletions WDE.Updater/Services/ChangelogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ public void TryShowChangelog()
documentManager.OpenDocument(new ChangeLogViewModel(changes));
}

public bool HasChangelog()
{
return fileSystem.Exists("~/changelog.json");
}

private List<ChangeLogEntry>? LoadChanges()
{
if (!fileSystem.Exists("~/changelog.json"))
if (!HasChangelog())
return null;
try
{
return JsonConvert.DeserializeObject<List<ChangeLogEntry>>(fileSystem.ReadAllText("~/changelog.json"));
return JsonConvert.DeserializeObject<List<ChangeLogEntry>>(fileSystem.ReadAllText("changelog.json"));
}
catch (Exception)
{
return null;
}
}
}
}
}
1 change: 1 addition & 0 deletions WDE.Updater/Services/IChangelogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace WDE.Updater.Services
public interface IChangelogProvider
{
void TryShowChangelog();
bool HasChangelog();
}
}
3 changes: 2 additions & 1 deletion WDE.Updater/Services/IUpdaterSettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.ComponentModel;
using WDE.Updater.Data;

namespace WDE.Updater.Services
{
public interface IUpdaterSettingsProvider
public interface IUpdaterSettingsProvider : INotifyPropertyChanged
{
UpdaterSettings Settings { get; set; }
}
Expand Down
Loading

0 comments on commit 85c5614

Please sign in to comment.