Skip to content

Commit 7f93e2a

Browse files
authored
Merge pull request #20 from nelinory/development
Development to Main
2 parents d48a46e + bb89294 commit 7f93e2a

31 files changed

Lines changed: 472 additions & 136 deletions

AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// app, or any theme specific resource dictionaries)
1111
)]
1212

13-
[assembly: AssemblyVersion("0.3.*")]
13+
[assembly: AssemblyVersion("0.4.*")]
1414
[assembly: AssemblyTitle("Supernote Desktop Client")]
1515
[assembly: AssemblyProduct("Supernote Desktop Client")]
1616
[assembly: AssemblyCopyright("Copyright © nelinory 2023")]

Converters/BoolToVisibilityInversonConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class BoolToVisibilityInversionConverter : IValueConverter
99
{
1010
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1111
{
12-
return (bool)value ? Visibility.Hidden : Visibility.Visible;
12+
return (bool)value ? Visibility.Collapsed : Visibility.Visible;
1313
}
1414

1515
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

Core/DiagnosticLogger.cs

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

44
namespace SupernoteDesktopClient.Core
55
{
6-
static class DiagnosticLogger
6+
public static class DiagnosticLogger
77
{
88
public static void Log(string messageTemplate, [CallerMemberName] string callerName = "", params object[] args)
99
{

Core/ImageManager.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using SupernoteDesktopClient.Core.Win32Api;
22
using System.Collections.Generic;
3-
using System.Drawing;
43
using System.IO;
54
using System.Windows.Interop;
65
using System.Windows.Media;
@@ -15,37 +14,37 @@ public static class ImageManager
1514

1615
public static ImageSource GetImageSource(string filename)
1716
{
18-
return GetImageSourceFromCache(filename, new Size(24, 24), ItemType.File, ItemState.Undefined);
17+
return GetImageSourceFromCache(filename, ItemType.File, ItemState.Undefined);
1918
}
2019

2120
public static ImageSource GetImageSource(string directory, ItemState folderType)
2221
{
23-
return GetImageSourceFromCache(directory, new Size(24, 24), ItemType.Folder, folderType);
22+
return GetImageSourceFromCache(directory, ItemType.Folder, folderType);
2423
}
2524

26-
private static ImageSource GetFileImageSource(string filename, Size size)
25+
private static ImageSource GetFileImageSource(string filename)
2726
{
2827
using (var icon = NativeMethods.GetIcon(Path.GetExtension(filename), ItemType.File, IconSize.Large, ItemState.Undefined))
2928
{
3029
return Imaging.CreateBitmapSourceFromHIcon(icon.Handle,
3130
System.Windows.Int32Rect.Empty,
32-
BitmapSizeOptions.FromWidthAndHeight(size.Width, size.Height));
31+
BitmapSizeOptions.FromEmptyOptions());
3332
}
3433
}
3534

36-
private static ImageSource GetDirectoryImageSource(string directory, Size size, ItemState folderType)
35+
private static ImageSource GetDirectoryImageSource(string directory, ItemState folderType)
3736
{
3837
using (var icon = NativeMethods.GetIcon(directory, ItemType.Folder, IconSize.Large, folderType))
3938
{
4039
return Imaging.CreateBitmapSourceFromHIcon(icon.Handle,
4140
System.Windows.Int32Rect.Empty,
42-
BitmapSizeOptions.FromWidthAndHeight(size.Width, size.Height));
41+
BitmapSizeOptions.FromEmptyOptions());
4342
}
4443
}
4544

46-
private static ImageSource GetImageSourceFromCache(string itemName, Size itemSize, ItemType itemType, ItemState itemState)
45+
private static ImageSource GetImageSourceFromCache(string itemName, ItemType itemType, ItemState itemState)
4746
{
48-
string cacheKey = $"{(itemType is ItemType.Folder ? ItemType.Folder : Path.GetExtension(itemName))}#{itemSize.Width}#{itemSize.Height}";
47+
string cacheKey = $"{(itemType is ItemType.Folder ? ItemType.Folder : Path.GetExtension(itemName))}";
4948

5049
ImageSource returnValue;
5150
_imageSourceCache.TryGetValue(cacheKey, out returnValue);
@@ -59,9 +58,9 @@ private static ImageSource GetImageSourceFromCache(string itemName, Size itemSiz
5958
if (returnValue == null)
6059
{
6160
if (itemType is ItemType.Folder)
62-
returnValue = GetDirectoryImageSource(itemName, itemSize, itemState);
61+
returnValue = GetDirectoryImageSource(itemName, itemState);
6362
else
64-
returnValue = GetFileImageSource(itemName, itemSize);
63+
returnValue = GetFileImageSource(itemName);
6564

6665
if (returnValue != null)
6766
_imageSourceCache.Add(cacheKey, returnValue);

Core/UpdateManager.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
5+
namespace SupernoteDesktopClient.Core
6+
{
7+
public static class UpdateManager
8+
{
9+
private static bool _updateAvailable = false;
10+
private static string _updateMessage = String.Empty;
11+
private static string _updateDetails = String.Empty;
12+
13+
public static async Task<(bool updateAvailable, string updateMessage, string updateDetails)> CheckForUpdate()
14+
{
15+
if (_updateAvailable == true)
16+
return (_updateAvailable, _updateMessage, _updateDetails);
17+
else
18+
{
19+
_updateDetails = String.Empty;
20+
21+
using (HttpClient client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }))
22+
{
23+
// github will always redirect releases/latest to a latest version tag
24+
using (HttpResponseMessage response = await client.GetAsync(@"https://github.com/nelinory/SupernoteDesktopClient/releases/latest"))
25+
{
26+
try
27+
{
28+
string redirect = response.Headers.Location.ToString();
29+
if (String.IsNullOrWhiteSpace(redirect) == false)
30+
{
31+
string githubVersion = redirect.Substring(redirect.LastIndexOf("/") + 1);
32+
string currentVersion = ApplicationManager.GetAssemblyVersion();
33+
34+
if (String.CompareOrdinal(githubVersion, currentVersion) > 0)
35+
{
36+
_updateAvailable = true;
37+
_updateDetails = $"View {githubVersion} release details.";
38+
}
39+
}
40+
}
41+
catch (Exception)
42+
{
43+
_updateAvailable = false;
44+
}
45+
}
46+
}
47+
48+
_updateMessage = (_updateAvailable == true)
49+
? "There is a new release of Supernote Desktop Client available."
50+
: "You already have the latest version of Supernote Desktop Client installed.";
51+
52+
return (_updateAvailable, _updateMessage, _updateDetails);
53+
}
54+
}
55+
56+
public static (bool updateAvailable, string updateMessage, string updateDetails) GetUpdateDetails()
57+
{
58+
return (_updateAvailable, _updateMessage, _updateDetails);
59+
}
60+
}
61+
}

Extensions/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static string MaskSerialNumber(this string value)
1515

1616
if (value.Length > totaUnmaskedCharacters)
1717
{
18-
return value.Substring(0, unmaskedStartCharacters) + new String('X', value.Length - totaUnmaskedCharacters) + value.Substring(value.Length - unmaskedEdnCharacters);
18+
return String.Concat(value.AsSpan(0, unmaskedStartCharacters), new String('X', value.Length - totaUnmaskedCharacters), value.AsSpan(value.Length - unmaskedEdnCharacters));
1919
}
2020
else
2121
return value;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
33

4-
namespace SupernoteDesktopClient.Core
4+
namespace SupernoteDesktopClient.Extensions
55
{
66
public static class TaskExtension
77
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using CommunityToolkit.Mvvm.Messaging.Messages;
22

3-
namespace SupernoteDesktopClient.Models
3+
namespace SupernoteDesktopClient.Messages
44
{
55
public class MediaDeviceChangedMessage : ValueChangedMessage<DeviceInfo>
66
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using CommunityToolkit.Mvvm.Messaging.Messages;
22

3-
namespace SupernoteDesktopClient.Models
3+
namespace SupernoteDesktopClient.Messages
44
{
55
public class SettingsChangedMessage : ValueChangedMessage<string>
66
{

Models/FileSystemObjectInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private void OnOpenSelectedItem(object parameter)
6969
}
7070
catch (Exception)
7171
{
72+
// TODO: Error handling
7273
}
7374
}
7475

0 commit comments

Comments
 (0)