Skip to content

Commit 19026e0

Browse files
authored
Merge pull request #131 from Rekkonnect/feature/update-check
Implement update checking
2 parents 4403e6d + c343074 commit 19026e0

File tree

239 files changed

+3330
-1163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+3330
-1163
lines changed

Syndiesis/App.axaml.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using Avalonia;
21
using Avalonia.Controls.ApplicationLifetimes;
32
using Avalonia.Markup.Xaml;
3+
using Garyon.Objects;
44
using Microsoft.CodeAnalysis;
55
using Serilog;
66
using Serilog.Events;
7+
using Syndiesis.Updating;
78
using Syndiesis.Utilities;
89
using Syndiesis.Views;
9-
using System;
1010
using System.Reflection;
1111

1212
namespace Syndiesis;
@@ -38,6 +38,11 @@ public static AppResourceManager CurrentResourceManager
3838

3939
public override void Initialize()
4040
{
41+
// Force initialize app settings on the UI thread to avoid troubles
42+
// with extra invocation handling when initializing instances from
43+
// de-/serializations or first-time accesses. Deadlocks are very
44+
// common to encounter when incorrectly using UI thread dispatches
45+
_ = AppSettings.Instance;
4146
AvaloniaXamlLoader.Load(this);
4247
ResourceManager = new(this);
4348
AppInfo = CreateAppInfo();
@@ -64,40 +69,46 @@ private static InformationalVersion InformationalVersionForAssembly(Assembly ass
6469
private static void SetupGeneral()
6570
{
6671
SetupSerilog();
67-
AppSettings.TryLoad();
72+
Task.Run(SetupGeneralAsync);
73+
}
74+
75+
private static async Task SetupGeneralAsync()
76+
{
77+
await AppSettings.TryLoad();
78+
await CheckUpdates();
6879
}
6980

7081
public override void OnFrameworkInitializationCompleted()
7182
{
7283
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
7384
{
74-
SetupDesktop(desktop);
85+
SetupDesktopLifetime(desktop);
7586
}
7687

7788
if (ApplicationLifetime is ISingleViewApplicationLifetime single)
7889
{
79-
SetupSingleView(single);
90+
SetupSingleViewLifetime(single);
8091
}
8192

8293
if (ApplicationLifetime is IControlledApplicationLifetime controlled)
8394
{
84-
SetupControlled(controlled);
95+
SetupControlledLifetime(controlled);
8596
}
8697

8798
base.OnFrameworkInitializationCompleted();
8899
}
89100

90-
private void SetupDesktop(IClassicDesktopStyleApplicationLifetime desktop)
101+
private void SetupDesktopLifetime(IClassicDesktopStyleApplicationLifetime desktop)
91102
{
92103
desktop.MainWindow = new MainWindow();
93104
}
94105

95-
private void SetupSingleView(ISingleViewApplicationLifetime single)
106+
private void SetupSingleViewLifetime(ISingleViewApplicationLifetime single)
96107
{
97108
single.MainView = new MainView();
98109
}
99110

100-
private void SetupControlled(IControlledApplicationLifetime controlled)
111+
private void SetupControlledLifetime(IControlledApplicationLifetime controlled)
101112
{
102113
SetupSerilog(controlled);
103114
controlled.Exit += HandleControlledLifetimeExit;
@@ -106,7 +117,7 @@ private void SetupControlled(IControlledApplicationLifetime controlled)
106117
private void HandleControlledLifetimeExit(
107118
object? sender, ControlledApplicationLifetimeExitEventArgs e)
108119
{
109-
AppSettings.TrySave();
120+
Task.Run(() => AppSettings.TrySave());
110121
}
111122

112123
private void SetupSerilog(IControlledApplicationLifetime lifetime)
@@ -134,4 +145,12 @@ private static void LogApplicationExit(object? sender, EventArgs e)
134145
{
135146
LoggerExtensionsEx.LogMethodInvocation(nameof(LogApplicationExit));
136147
}
148+
149+
private static async Task CheckUpdates()
150+
{
151+
if (AppSettings.Instance.UpdateOptions.AutoCheckUpdates)
152+
{
153+
await Singleton<UpdateManager>.Instance.CheckForUpdates();
154+
}
155+
}
137156
}

Syndiesis/AppResourceManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Avalonia.Controls;
2-
using Avalonia.Media;
3-
4-
namespace Syndiesis;
1+
namespace Syndiesis;
52

63
public class AppResourceManager(App app)
74
{

Syndiesis/AppSettings.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Serilog;
22
using Syndiesis.Controls.AnalysisVisualization;
33
using Syndiesis.Core.DisplayAnalysis;
4-
using System;
54
using System.IO;
65
using System.Text.Json;
76

@@ -16,6 +15,7 @@ public sealed class AppSettings
1615
#region Settings
1716
public AnalysisNodeCreationOptions NodeLineOptions = new();
1817
public IndentationOptions IndentationOptions = new();
18+
public UpdateOptions UpdateOptions = new();
1919

2020
public StylePreferences NodeColorPreferences = new();
2121
public ColorizationPreferences ColorizationPreferences = new();
@@ -39,13 +39,16 @@ public sealed class AppSettings
3939
#endregion
4040

4141
#region Persistence
42-
public static bool TryLoad(string path = DefaultPath)
42+
public static async Task<bool> TryLoad(string path = DefaultPath)
4343
{
4444
try
4545
{
46-
var json = File.ReadAllText(path);
47-
var returned = JsonSerializer.Deserialize<AppSettings>(
48-
json, AppSettingsSerialization.DefaultOptions);
46+
var json = await File.ReadAllTextAsync(path);
47+
var returned = await Dispatcher.UIThread.InvokeAsync(() =>
48+
{
49+
return JsonSerializer.Deserialize<AppSettings>(
50+
json, AppSettingsSerialization.DefaultOptions);
51+
});
4952
if (returned is null)
5053
return false;
5154

@@ -60,13 +63,13 @@ public static bool TryLoad(string path = DefaultPath)
6063
}
6164
}
6265

63-
public static bool TrySave(string path = DefaultPath)
66+
public static async Task<bool> TrySave(string path = DefaultPath)
6467
{
6568
try
6669
{
6770
var json = JsonSerializer.Serialize(
6871
Instance, AppSettingsSerialization.DefaultOptions);
69-
File.WriteAllText(path, json);
72+
await File.WriteAllTextAsync(path, json);
7073
Log.Information($"Settings saved to '{path}'");
7174
return true;
7275
}

Syndiesis/AppSettingsSerialization.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Avalonia.Media;
2-
using System;
3-
using System.Text.Json;
1+
using System.Text.Json;
42
using System.Text.Json.Serialization;
53

64
namespace Syndiesis;

Syndiesis/ColorHelpers/HslTransformation.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Avalonia.Media;
2-
3-
namespace Syndiesis.ColorHelpers;
1+
namespace Syndiesis.ColorHelpers;
42

53
public readonly record struct HslTransformation(double Alpha, double Hue, double Saturation, double Lightness)
64
: IColorTransformation<HslColor>

Syndiesis/ColorHelpers/HsvTransformation.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Avalonia.Media;
2-
3-
namespace Syndiesis.ColorHelpers;
1+
namespace Syndiesis.ColorHelpers;
42

53
public readonly record struct HsvTransformation(
64
double Alpha = 0,

Syndiesis/ColorHelpers/IColorTransformation.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Avalonia.Media;
2-
3-
namespace Syndiesis.ColorHelpers;
1+
namespace Syndiesis.ColorHelpers;
42

53
public interface IColorTransformation<TColor>
64
{

Syndiesis/ColorHelpers/LazilyUpdatedHslTransformedSolidBrush.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Avalonia.Media;
2-
3-
namespace Syndiesis.ColorHelpers;
1+
namespace Syndiesis.ColorHelpers;
42

53
public sealed class LazilyUpdatedHslTransformedSolidBrush(
64
LazilyUpdatedSolidBrush mainSolid,

Syndiesis/ColorHelpers/LazilyUpdatedHsvTransformedSolidBrush.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Avalonia.Media;
2-
3-
namespace Syndiesis.ColorHelpers;
1+
namespace Syndiesis.ColorHelpers;
42

53
public sealed class LazilyUpdatedHsvTransformedSolidBrush(
64
ILazilyUpdatedSolidBrush mainSolid,

Syndiesis/ColorHelpers/LazilyUpdatedTransformedSolidBrush.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Avalonia.Media;
2-
using Avalonia.Threading;
3-
4-
namespace Syndiesis.ColorHelpers;
1+
namespace Syndiesis.ColorHelpers;
52

63
public abstract class LazilyUpdatedTransformedSolidBrush<TColorTransformation, TColor>(
74
ILazilyUpdatedSolidBrush mainSolid,

0 commit comments

Comments
 (0)