Skip to content

Commit d1f3847

Browse files
committed
Finished check for newer releases
1 parent 4ed3f53 commit d1f3847

11 files changed

Lines changed: 167 additions & 23 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<RepositoryUrl>https://github.com/RolandKoenig/MessageCommunicator.git</RepositoryUrl>
99
<RepositoryType>git</RepositoryType>
1010
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
11-
<Version>0.6.0</Version>
12-
<PackageVersion>0.6.0</PackageVersion>
11+
<Version>0.7.0</Version>
12+
<PackageVersion>0.7.0</PackageVersion>
1313
<Product>MessageCommunicator</Product>
1414
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
1515
</PropertyGroup>

MessageCommunicator.TestGui/Assets/Icons.xaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<ResourceDictionary xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:local="clr-namespace:MessageCommunicator.TestGui;assembly=MessageCommunicator.TestGui">
4-
<SolidColorBrush x:Key="IconColorPositive" Color="Green" />
4+
<!--<SolidColorBrush x:Key="IconColorPositive" Color="Green" />
55
<SolidColorBrush x:Key="IconColorNegative" Color="Red" />
6-
<SolidColorBrush x:Key="IconColorNeutral" Color="#FF464646" />
6+
<SolidColorBrush x:Key="IconColorNeutral" Color="#FF464646" />-->
77

88
<!-- Icons copied from Avalonia.IconPacks project
99
see: https://github.com/ahopper/Avalonia.IconPacks -->
@@ -37,4 +37,16 @@
3737
<local:VectorIconGeometryDrawing x:Key="IconUncheckedList"
3838
BrushStyle="Neutral"
3939
Geometry="M2 3H1V4H2V3ZM2 6H1V7H2V6ZM1 9H2V10H1V9ZM2 12H1V13H2V12ZM4 3H15V4H4V3ZM15 6H4V7H15V6ZM4 9H15V10H4V9ZM15 12H4V13H15V12Z" />
40+
<local:VectorIconGeometryDrawing x:Key="IconCheck"
41+
BrushStyle="Positive"
42+
Geometry="F1M780.5009765625,-648.830993652344L840.831970214844,-588.5 426.6669921875,-174.335006713867 225.835006713867,-375.1669921875 286.165985107422,-435.497985839844 426.6669921875,-294.997009277344 780.5009765625,-648.830993652344z" />
43+
<local:VectorIconGeometryDrawing x:Key="IconLab"
44+
BrushStyle="Neutral"
45+
Geometry="M16.432,15C14.387,9.893,12,8.547,12,6V3h0.5C12.776,3,13,2.776,13,2.5v-1 C13,1.224,12.776,1,12.5,1h-5C7.224,1,7,1.224,7,1.5v1C7,2.776,7.224,3,7.5,3H8v3c0,2.547-2.387,3.893-4.432,9 C2.917,16.625,1.245,19,10,19S17.083,16.625,16.432,15z M14.815,16.751C14.113,16.961,12.716,17.2,10,17.2s-4.113-0.239-4.815-0.449 c-0.249-0.074-0.346-0.363-0.258-0.628c0.22-0.67,0.635-1.828,1.411-3.121c1.896-3.159,3.863,0.497,5.5,0.497 c1.637,0,1.188-1.561,1.824-0.497c0.774,1.294,1.191,2.451,1.411,3.121C15.161,16.388,15.064,16.676,14.815,16.751z" />
46+
<local:VectorIconGeometryDrawing x:Key="IconWarning"
47+
BrushStyle="NegativeSoft"
48+
Geometry="M8.44 1H7.56L1 13.26L1.44 14H14.54L14.98 13.26L8.44 1ZM2.28 13L8 2.28L13.7 13H2.28ZM7.5 6H8.5V10H7.5V6ZM7.5 11H8.5V12H7.5V11Z" />
49+
<local:VectorIconGeometryDrawing x:Key="IconRefresh"
50+
BrushStyle="Neutral"
51+
Geometry="F1M65.8210067749023,-165.25L65.8066329956055,-165.181213378906 65.7490081787109,-164.949996948242 65.8210067749023,-165.25z M303.363006591797,-237.589996337891L303.529327392578,-237.558319091797 303.658996582031,-237.526000976563 303.363006591797,-237.589996337891z M872.661010742188,-307.031005859375L872.575988769531,-306.72900390625 872.623657226563,-306.925903320313 872.661010742188,-307.031005859375z M148.429992675781,-362.933990478516C152.908996582031,-362.933990478516,157.227005004883,-362.243988037109,161.283004760742,-360.963989257813L160.981002807617,-361.045989990234 324.308990478516,-320.342010498047C343.035003662109,-315.557006835938 356.660003662109,-298.837005615234 356.660003662109,-278.933990478516 356.660003662109,-255.365005493164 337.553009033203,-236.257995605469 313.984008789063,-236.257995605469 312.150512695313,-236.257995605469 310.34423828125,-236.373504638672 308.571868896484,-236.597747802734L303.529327392578,-237.558319091797 227.455993652344,-256.513000488281C284.558990478516,-170.031997680664 381.316986083984,-113.759002685547 491.218994140625,-113.759002685547 630.97802734375,-113.759002685547 749.481994628906,-204.761993408203 790.7080078125,-330.743988037109L791.338989257813,-332.971984863281C797.005981445313,-350.346984863281 813.06298828125,-362.680999755859 832,-362.680999755859 855.572021484375,-362.680999755859 874.679992675781,-343.572998046875 874.679992675781,-320.001007080078 874.679992675781,-317.684020996094 874.495483398438,-315.410247802734 874.140258789063,-313.193634033203L872.623657226563,-306.925903320313 865.188293457031,-286.013275146484C825.171142578125,-182.387756347656,745.765625,-101.087936401367,645.755004882813,-59.2220039367676L643.114990234375,-58.2419967651367C598.226989746094,-39.3359985351563 546.046020507813,-28.3500003814697 491.299011230469,-28.3499984741211 355.658996582031,-28.3500003814697 235.768997192383,-95.7850036621094 163.32600402832,-198.957000732422L162.473999023438,-200.236999511719 162.475006103516,-200.235000610352 148.522994995117,-144.29899597168C144.091995239258,-125.097999572754 127.140998840332,-110.999000549316 106.897010803223,-110.999000549316 83.3330001831055,-110.999000549316 64.2300033569336,-130.102005004883 64.2299957275391,-153.666000366211 64.2300033569336,-155.673492431641 64.3687515258789,-157.648742675781 64.6370086669922,-159.582504272461L65.8066329956055,-165.181213378906 107.008010864258,-330.497009277344C111.758003234863,-349.265991210938,128.498001098633,-362.933990478516,148.429992675781,-362.933990478516z M820.817993164063,-495.398986816406L820.971435546875,-495.363433837891 821.119995117188,-495.317993164063 820.817993164063,-495.398986816406z M109.976005554199,-556.685974121094L109.931022644043,-556.570434570313 109.86799621582,-556.4169921875 109.976005554199,-556.685974121094z M682.880004882813,-626.817016601563L683.181030273438,-626.72900390625 683.108581542969,-626.747192382813 682.880004882813,-626.817016601563z M924.289001464844,-686.848022460938L924.206970214844,-686.546020507813 924.239624023438,-686.6865234375 924.289001464844,-686.848022460938z M491.316986083984,-831.888000488281C629.8759765625,-831.888000488281,751.991027832031,-761.481994628906,823.838012695313,-654.494995117188L824.747009277344,-653.057006835938 824.747009277344,-653.056030273438 842.6669921875,-711.807983398438C848.179992675781,-729.434997558594 864.361022949219,-742.004028320313 883.47802734375,-742.004028320313 907.046997070313,-742.004028320313 926.153991699219,-722.89697265625 926.153991699219,-699.328002929688 926.153991699219,-697.101501464844 925.983520507813,-694.914733886719 925.654846191406,-692.7802734375L924.239624023438,-686.6865234375 874.369018554688,-523.648010253906C868.856018066406,-506.026000976563 852.679016113281,-493.460998535156 833.567993164063,-493.460998535156 831.347534179688,-493.460998535156 829.16650390625,-493.630737304688 827.037353515625,-493.957885742188L820.971435546875,-495.363433837891 657.919982910156,-545.237976074219C639.825988769531,-550.452026367188 626.814025878906,-566.861022949219 626.814025878906,-586.309020996094 626.814025878906,-609.872985839844 645.9169921875,-628.976013183594 669.481018066406,-628.976013183594 671.877014160156,-628.976013183594 674.226989746094,-628.778503417969 676.515502929688,-628.398864746094L683.108581542969,-626.747192382813 754.218994140625,-605.013977050781C697.044982910156,-690.820983886719 600.684020996094,-746.591003417969 491.298004150391,-746.591003417969 360.433990478516,-746.591003417969 248.212997436523,-666.77099609375 200.664993286133,-553.161010742188L199.893997192383,-551.0830078125 188.800994873047,-524.075012207031C182.526992797852,-507.825988769531 167.033004760742,-496.509002685547 148.89599609375,-496.509002685547 125.332000732422,-496.509002685547 106.228996276855,-515.611999511719 106.228996276855,-539.176025390625 106.228996276855,-543.856018066406 106.982749938965,-548.359985351563 108.375068664551,-552.573486328125L109.931022644043,-556.570434570313 120.960998535156,-583.424987792969C182.378005981445,-730.448974609375,325.002014160156,-831.888000488281,491.316986083984,-831.888000488281z" />
4052
</ResourceDictionary>

MessageCommunicator.TestGui/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public MainWindow()
3737
this.ViewServices.Add(new OpenFileDialogService(this));
3838
this.ViewServices.Add(new AboutDialogService(ctrlDialogHost));
3939
this.ViewServices.Add(new HelpBrowserService(this, helpRepo));
40+
this.ViewServices.Add(new ViewResourceService(this));
4041

4142
// Load initial main view model
4243
this.ViewModel = new MainWindowViewModel();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MessageCommunicator.TestGui.ViewServices
2+
{
3+
public interface IViewResourceService : IViewService
4+
{
5+
object? TryGetViewResource(string resourceName);
6+
}
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Avalonia.Controls;
2+
3+
namespace MessageCommunicator.TestGui.ViewServices
4+
{
5+
public class ViewResourceService : ViewServiceBase, IViewResourceService
6+
{
7+
private IResourceNode _rootNode;
8+
9+
public ViewResourceService(IResourceNode resourceNode)
10+
{
11+
_rootNode = resourceNode;
12+
}
13+
14+
/// <inheritdoc />
15+
public object? TryGetViewResource(string resourceName)
16+
{
17+
return _rootNode.FindResource(resourceName);
18+
}
19+
}
20+
}

MessageCommunicator.TestGui/Views/_ReleaseCheck/ReleaseCheckView.xaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
mc:Ignorable="d"
88
d:Width="400" d:Height="400"
99
x:Class="MessageCommunicator.TestGui.Views.ReleaseCheckView">
10-
<StackPanel Orientation="Horizontal">
11-
<TextBlock Text="{Binding Path=StatusText}"
12-
Margin="2"/>
13-
</StackPanel>
10+
<Menu>
11+
<MenuItem Header="{Binding Path=Icon}"
12+
ToolTip.Tip="{Binding Path=StatusText}"
13+
Command="{Binding Path=Command_GoToReleases}">
14+
15+
</MenuItem>
16+
</Menu>
1417
</UserControl>

MessageCommunicator.TestGui/Views/_ReleaseCheck/ReleaseCheckView.xaml.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Avalonia.Controls;
1+
using System.ComponentModel;
2+
using System.Reactive.Disposables;
3+
using System.Threading;
4+
using Avalonia.Controls;
25
using Avalonia.Markup.Xaml;
36

47
namespace MessageCommunicator.TestGui.Views
@@ -8,11 +11,16 @@ public class ReleaseCheckView : OwnUserControl<ReleaseCheckViewModel>
811
public ReleaseCheckView()
912
{
1013
AvaloniaXamlLoader.Load(this);
11-
14+
1215
if (!Design.IsDesignMode)
1316
{
1417
var viewModel = new ReleaseCheckViewModel();
15-
viewModel.TriggerRequest();
18+
19+
SynchronizationContext.Current!.Post((arg) =>
20+
{
21+
viewModel.TriggerRequest();
22+
}, null);
23+
1624

1725
this.DataContext = viewModel;
1826
}
Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
using System.Threading.Tasks;
1+
using System.Reactive;
2+
using System.Reflection;
3+
using System.Threading.Tasks;
4+
using Avalonia;
5+
using Avalonia.Media;
26
using Avalonia.X11;
7+
using MessageCommunicator.TestGui.ViewServices;
38
using ReactiveUI;
49

510
namespace MessageCommunicator.TestGui.Views
611
{
712
public class ReleaseCheckViewModel : OwnViewModelBase
813
{
914
private string _statusText;
15+
private VectorIconDrawingPresenter? _icon;
1016

1117
public string StatusText
1218
{
@@ -20,34 +26,110 @@ public string StatusText
2026
}
2127
}
2228
}
29+
30+
public VectorIconDrawingPresenter? Icon
31+
{
32+
get => _icon;
33+
set
34+
{
35+
if (!ReferenceEquals(_icon, value))
36+
{
37+
_icon = value;
38+
this.RaisePropertyChanged(nameof(this.Icon));
39+
}
40+
}
41+
}
42+
43+
public ReactiveCommand<Unit, Unit> Command_GoToReleases
44+
{
45+
get;
46+
}
2347

2448
public ReleaseCheckViewModel()
2549
{
2650
_statusText = "Checking for newer releases...";
51+
52+
this.Command_GoToReleases = ReactiveCommand.Create(() =>
53+
{
54+
CommonUtil.OpenUrlInBrowser("https://github.com/RolandKoenig/MessageCommunicator/releases");
55+
});
2756
}
2857

58+
/// <summary>
59+
/// Triggers the request for latest release.
60+
/// </summary>
2961
public void TriggerRequest()
3062
{
31-
ReleaseOverview.GetLatestReleaseAsync()
63+
ReleaseInformation? latestReleaseInfo = null;
64+
65+
var taskQueryReleaseInfo = ReleaseOverview.TryGetLatestReleaseAsync()
3266
.ContinueWith(task =>
3367
{
34-
if(task.IsFaulted){ this.ProcessLatestReleaseInfo(null); }
35-
else
68+
if (!task.IsFaulted)
3669
{
37-
this.ProcessLatestReleaseInfo(task.Result);
70+
latestReleaseInfo = task.Result;
3871
}
3972
}, TaskScheduler.FromCurrentSynchronizationContext());
73+
74+
// Try request latest release info for a maximum of 5 seconds
75+
Task.WhenAny(taskQueryReleaseInfo, Task.Delay(5000))
76+
.ContinueWith(task =>
77+
{
78+
this.ProcessLatestReleaseInfo(latestReleaseInfo);
79+
}, TaskScheduler.FromCurrentSynchronizationContext());
80+
81+
this.TrySetIcon("IconRefresh");
4082
}
4183

84+
/// <summary>
85+
/// Sets the given <see cref="ReleaseInformation"/> as the latest release.
86+
/// </summary>
4287
public void ProcessLatestReleaseInfo(ReleaseInformation? releaseInfo)
4388
{
4489
if (releaseInfo == null)
4590
{
4691
this.StatusText = "Unable to check for newer releases";
92+
this.TrySetIcon("IconWarning");
93+
return;
94+
}
95+
96+
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version!;
97+
if (releaseInfo.Version > currentVersion)
98+
{
99+
this.StatusText = $"You are running an older release (newest version is {releaseInfo.Version.ToString(3)}";
100+
this.TrySetIcon("IconWarning");
101+
}
102+
else if (releaseInfo.Version == currentVersion)
103+
{
104+
this.StatusText = $"You are running the newest release";
105+
this.TrySetIcon("IconCheck");
106+
}
107+
else
108+
{
109+
// Should only be possible in development environment
110+
this.StatusText = "This is a development build";
111+
this.TrySetIcon("IconLab");
112+
}
113+
}
114+
115+
private void TrySetIcon(string iconResourceName)
116+
{
117+
var iconResource = this.GetViewService<IViewResourceService>().TryGetViewResource(iconResourceName) as Drawing;
118+
if (iconResource == null)
119+
{
120+
this.Icon = null;
47121
return;
48122
}
49123

50-
this.StatusText = $"Newest: {releaseInfo.Version}";
124+
var newIcon = new VectorIconDrawingPresenter()
125+
{
126+
Drawing = iconResource,
127+
Width = 16.0,
128+
Height = 16.0,
129+
Margin = new Thickness(2.0)
130+
};
131+
newIcon.UpdateBrushes();
132+
this.Icon = newIcon;
51133
}
52134
}
53135
}

MessageCommunicator.TestGui/_Util/_ReleaseOverview/ReleaseOverview.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ namespace MessageCommunicator.TestGui
1212
{
1313
public class ReleaseOverview
1414
{
15-
private const string URL = "https://www.rolandk.de/releases/message_communicator.json";
16-
17-
public static async Task<ReleaseInformation?> GetLatestReleaseAsync()
15+
private const string URL = "https://www.rolandk.de/apps/message_communicator/releases.json";
16+
17+
public static async Task<ReleaseInformation?> TryGetLatestReleaseAsync()
1818
{
1919
using (HttpClient client = new HttpClient())
2020
{
2121
// Add an Accept header for JSON format.
2222
client.DefaultRequestHeaders.Accept.Add(
2323
new MediaTypeWithQualityHeaderValue("application/json"));
24-
24+
2525
// List data response.
2626
HttpResponseMessage response = await client.GetAsync(new Uri(URL)); // Blocking call! Program will wait here until a response is received or a timeout occurs.
2727
if (response.IsSuccessStatusCode)
2828
{
29-
3029
await using(var inStream = await response.Content.ReadAsStreamAsync())
3130
using (var inStreamReader = new StreamReader(inStream))
3231
using (var jsonReader = new JsonTextReader(inStreamReader))

MessageCommunicator.TestGui/_Util/_View/_Misc.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public enum IconBrushStyle
1919
Positive,
2020

2121
Negative,
22+
23+
NegativeSoft,
2224

23-
Neutral
25+
Neutral,
2426
}
2527
}

0 commit comments

Comments
 (0)