Skip to content

Commit e527602

Browse files
authored
Merge pull request #22 from nelinory/development
Development to Main
2 parents 7f93e2a + 7b4410d commit e527602

14 files changed

Lines changed: 134 additions & 26 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.4.*")]
13+
[assembly: AssemblyVersion("0.5.*")]
1414
[assembly: AssemblyTitle("Supernote Desktop Client")]
1515
[assembly: AssemblyProduct("Supernote Desktop Client")]
1616
[assembly: AssemblyCopyright("Copyright © nelinory 2023")]

Core/FileSystemManager.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,22 @@ public static string GetApplicationDeviceFolder()
4444

4545
return returnResult;
4646
}
47+
48+
public static void CleanupTempConversionFiles()
49+
{
50+
try
51+
{
52+
string[] tempFileNames = Directory.GetFiles(Path.GetTempPath(), $"*_sdc.pdf");
53+
for (int i = 0; i < tempFileNames.Length; i++)
54+
{
55+
if (File.Exists(tempFileNames[i]) == true)
56+
File.Delete(tempFileNames[i]);
57+
}
58+
}
59+
catch (Exception)
60+
{
61+
// errors while deleting temporary files
62+
}
63+
}
4764
}
4865
}

Core/UpdateManager.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public static class UpdateManager
1818
{
1919
_updateDetails = String.Empty;
2020

21-
using (HttpClient client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }))
21+
try
2222
{
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"))
23+
using (HttpClient client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }))
2524
{
26-
try
25+
// github will always redirect releases/latest to a latest version tag
26+
using (HttpResponseMessage response = await client.GetAsync(@"https://github.com/nelinory/SupernoteDesktopClient/releases/latest"))
2727
{
2828
string redirect = response.Headers.Location.ToString();
2929
if (String.IsNullOrWhiteSpace(redirect) == false)
@@ -38,16 +38,16 @@ public static class UpdateManager
3838
}
3939
}
4040
}
41-
catch (Exception)
42-
{
43-
_updateAvailable = false;
44-
}
4541
}
4642
}
43+
catch (Exception)
44+
{
45+
_updateAvailable = false;
46+
}
4747

4848
_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.";
49+
? "There is a new release of Supernote Desktop Client available."
50+
: "You already have the latest version of Supernote Desktop Client installed.";
5151

5252
return (_updateAvailable, _updateMessage, _updateDetails);
5353
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using CommunityToolkit.Mvvm.Messaging.Messages;
2+
3+
namespace SupernoteDesktopClient.Messages
4+
{
5+
public class ProgressTrackActionMessage : ValueChangedMessage<bool>
6+
{
7+
public ProgressTrackActionMessage(bool value) : base(value) { }
8+
}
9+
}

Messages/SettingsChangedMessage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace SupernoteDesktopClient.Messages
44
{
55
public class SettingsChangedMessage : ValueChangedMessage<string>
66
{
7+
public const string MINIMIZE_TO_TRAY_ENABLED = "MinimizeToTrayEnabled";
8+
79
public SettingsChangedMessage(string value) : base(value) { }
810
}
911
}

Models/FileSystemObjectInfo.cs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
using System.IO;
1010
using System.Linq;
1111
using System.Windows.Media;
12+
using SupernoteSharp.Business;
13+
using SupernoteSharp.Common;
14+
using SupernoteSharp.Entities;
15+
using CommunityToolkit.Mvvm.Messaging;
16+
using SupernoteDesktopClient.Messages;
17+
using System.Threading.Tasks;
1218

1319
namespace SupernoteDesktopClient.Models
1420
{
@@ -54,23 +60,60 @@ public FileSystemObjectInfo(FileSystemInfo info)
5460
}
5561

5662
[RelayCommand]
57-
private void OnOpenSelectedItem(object parameter)
63+
private async Task OnOpenSelectedItem(object parameter)
64+
{
65+
await Task.Run(() => ConvertNoteDocument(parameter));
66+
}
67+
68+
private void ConvertNoteDocument(object parameter)
5869
{
5970
FileSystemObjectInfo item = parameter as FileSystemObjectInfo;
6071
if ((item.FileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
6172
return;
6273

63-
ProcessStartInfo psi = new ProcessStartInfo();
64-
psi.FileName = item.FileSystemInfo.FullName;
65-
psi.UseShellExecute = true;
74+
// skip *.mark files until the application can support them
75+
if (item.FileSystemInfo.Extension == ".mark")
76+
return;
77+
6678
try
6779
{
80+
string selectedItemFullName = item.FileSystemInfo.FullName;
81+
82+
if (item.FileSystemInfo.Extension == ".note" && item.FileSystemInfo.Exists == true)
83+
{
84+
WeakReferenceMessenger.Default.Send(new ProgressTrackActionMessage(true)); // action started
85+
86+
selectedItemFullName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(item.FileSystemInfo.Name) + "_sdc.pdf");
87+
88+
using (FileStream fileStream = new FileStream(item.FileSystemInfo.FullName, FileMode.Open, FileAccess.Read))
89+
{
90+
Parser parser = new Parser();
91+
Notebook notebook = parser.LoadNotebook(fileStream, Policy.Strict);
92+
Converter.PdfConverter converter = new Converter.PdfConverter(notebook, DefaultColorPalette.Grayscale);
93+
94+
// convert all pages to vector PDF and build all links
95+
byte[] allPages = converter.ConvertAll(vectorize: true, enableLinks: true);
96+
// save the result
97+
File.WriteAllBytes(selectedItemFullName, allPages);
98+
}
99+
}
100+
101+
ProcessStartInfo psi = new ProcessStartInfo
102+
{
103+
FileName = selectedItemFullName,
104+
UseShellExecute = true
105+
};
106+
68107
Process process = Process.Start(psi);
69108
}
70109
catch (Exception)
71110
{
72111
// TODO: Error handling
73112
}
113+
finally
114+
{
115+
WeakReferenceMessenger.Default.Send(new ProgressTrackActionMessage(false)); // action completed
116+
}
74117
}
75118

76119
private void FileSystemObjectInfo_PropertyChanged(object sender, PropertyChangedEventArgs e)

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Supernote Desktop Client (SDC) is a desktop client for Supernote paper-like tabl
1111
### Key Features
1212
- Automatically detects Supernote device connected with an USB cable
1313
- Shows basic information for connected Supernote device
14-
- Automatic/Manual Supernote storage synchronization to local folder
15-
- Automatically archives last synchronization, have archives retention policy
16-
- Supports multiple Supernote devices, each device have an unique local sync folder
14+
- Automatic/Manual Supernote storage backup to a local folder
15+
- Automatically archives last backup, have archives retention policy
16+
- Supports multiple Supernote devices, each device have an unique local backup folder
1717
- Build-in offline mode, which allows most of the application features to be used without having Supernote device connected
18-
- Build-in explorer allows to view and open all Supernote files in the local backup folder (support for `*.note` & `*.mark` is coming soon)
18+
- Build-in explorer allows to view and open all Supernote files in the local backup folder
19+
- [X] *.note files are converted to vectorized PDF (internal/web links supported)
20+
- [ ] *.mark files support - coming soon
1921
- Automatic/Manual check for new application version
2022
- Light/Dark Theme support
2123

SupernoteDesktopClient.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
<PackageReference Include="Serilog" Version="2.12.0" />
2424
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
2525
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
26-
<PackageReference Include="System.Management" Version="7.0.1" />
26+
<PackageReference Include="SupernoteSharp" Version="0.5.8583" />
27+
<PackageReference Include="System.Management" Version="7.0.2" />
2728
<PackageReference Include="WPF-UI" Version="2.0.3" />
2829
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
2930
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />

ViewModels/ExplorerViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.Messaging;
23
using SupernoteDesktopClient.Core;
4+
using SupernoteDesktopClient.Messages;
35
using SupernoteDesktopClient.Models;
46
using SupernoteDesktopClient.Services.Contracts;
57
using System.Collections.ObjectModel;
@@ -19,6 +21,9 @@ public partial class ExplorerViewModel : ObservableObject, INavigationAware
1921
[ObservableProperty]
2022
private bool _hasItems;
2123

24+
[ObservableProperty]
25+
private bool _convertionInProgress = false;
26+
2227
public void OnNavigatedTo()
2328
{
2429
DiagnosticLogger.Log($"{this}");
@@ -33,6 +38,12 @@ public void OnNavigatedFrom()
3338
public ExplorerViewModel(IMediaDeviceService mediaDeviceService)
3439
{
3540
_mediaDeviceService = mediaDeviceService;
41+
42+
// Register a message subscriber
43+
WeakReferenceMessenger.Default.Register<ProgressTrackActionMessage>(this, (r, m) =>
44+
{
45+
ConvertionInProgress = m.Value;
46+
});
3647
}
3748

3849
private void LoadExplorer()

ViewModels/MainWindowViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public MainWindowViewModel(ISnackbarService snackbarService, IUsbHubDetector usb
5151
// Register a message subscriber
5252
WeakReferenceMessenger.Default.Register<SettingsChangedMessage>(this, (r, m) =>
5353
{
54-
MinimizeToTrayEnabled = SettingsManager.Instance.Settings.General.MinimizeToTrayEnabled;
54+
if (m.Value == SettingsChangedMessage.MINIMIZE_TO_TRAY_ENABLED)
55+
MinimizeToTrayEnabled = SettingsManager.Instance.Settings.General.MinimizeToTrayEnabled;
5556
});
5657

5758
// offline mode indicator
@@ -89,7 +90,7 @@ private void BuildNavigationMenu()
8990
PageType = typeof(ExplorerPage)
9091
}
9192
};
92-
93+
9394
NavigationFooter = new ObservableCollection<INavigationControl>
9495
{
9596
new NavigationItem()

0 commit comments

Comments
 (0)