From 3f6baf4848fe5997b118dea88d8e56628f9af52c Mon Sep 17 00:00:00 2001 From: Qiao Wang Date: Fri, 1 Nov 2024 10:07:21 +0800 Subject: [PATCH] bugfix and upgrade to v2.0.2.0. (#39) --- PocketClient.Core/Models/Author.cs | 2 +- PocketClient.Core/PocketClient.Core.csproj | 8 ++--- .../PocketClient.Desktop.Tests.MSTest.csproj | 10 +++--- .../Models/Messages/SyncFailureMessage.cs | 8 +++++ PocketClient.Desktop/Package.appxmanifest | 2 +- .../PocketClient.Desktop.csproj | 32 +++++++++---------- .../Services/PocketDbService.cs | 24 ++++++++++++-- .../ViewModels/ItemsViewModel.cs | 15 ++++++++- .../ViewModels/SettingsViewModel.cs | 13 ++++++-- .../PocketClient.HttpSdk.csproj | 2 +- PocketClient.HttpSdk/PocketHttpClient.cs | 8 ++++- PocketClient.sln | 8 ++--- 12 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 PocketClient.Desktop/Models/Messages/SyncFailureMessage.cs diff --git a/PocketClient.Core/Models/Author.cs b/PocketClient.Core/Models/Author.cs index 1e6e593..f41fc50 100644 --- a/PocketClient.Core/Models/Author.cs +++ b/PocketClient.Core/Models/Author.cs @@ -7,7 +7,7 @@ public string Name get; set; } - public string Url + public string? Url { get; set; } diff --git a/PocketClient.Core/PocketClient.Core.csproj b/PocketClient.Core/PocketClient.Core.csproj index e22679b..d72bd5d 100644 --- a/PocketClient.Core/PocketClient.Core.csproj +++ b/PocketClient.Core/PocketClient.Core.csproj @@ -8,13 +8,13 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + diff --git a/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj b/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj index 326a2c5..60c80e7 100644 --- a/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj +++ b/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj @@ -1,6 +1,6 @@  - net8.0-windows10.0.22000.0 + net8.0-windows10.0.22621.0 PocketClient.Desktop.Tests.MSTest x86;x64;arm64 win-x86;win-x64;win-arm64 @@ -11,13 +11,13 @@ resources.pri - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/PocketClient.Desktop/Models/Messages/SyncFailureMessage.cs b/PocketClient.Desktop/Models/Messages/SyncFailureMessage.cs new file mode 100644 index 0000000..b24b085 --- /dev/null +++ b/PocketClient.Desktop/Models/Messages/SyncFailureMessage.cs @@ -0,0 +1,8 @@ +namespace PocketClient.Desktop.Models; + +public class SyncFailureMessage(string reason, Exception ex) +{ + public string Reason { get; set; } = reason; + + public Exception Exception { get; set; } = ex; +} diff --git a/PocketClient.Desktop/Package.appxmanifest b/PocketClient.Desktop/Package.appxmanifest index 6133529..39ab01a 100644 --- a/PocketClient.Desktop/Package.appxmanifest +++ b/PocketClient.Desktop/Package.appxmanifest @@ -13,7 +13,7 @@ + Version="2.0.2.0" /> Nuts - Save & Read diff --git a/PocketClient.Desktop/PocketClient.Desktop.csproj b/PocketClient.Desktop/PocketClient.Desktop.csproj index 2373b35..dab32e6 100644 --- a/PocketClient.Desktop/PocketClient.Desktop.csproj +++ b/PocketClient.Desktop/PocketClient.Desktop.csproj @@ -1,7 +1,7 @@  WinExe - net8.0-windows10.0.22000.0 + net8.0-windows10.0.22621.0 10.0.19041.0 PocketClient.Desktop Assets/WindowIcon.ico @@ -31,29 +31,29 @@ - - - - - - - - - + + + + + + + + + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/PocketClient.Desktop/Services/PocketDbService.cs b/PocketClient.Desktop/Services/PocketDbService.cs index 3467e34..7ed0899 100644 --- a/PocketClient.Desktop/Services/PocketDbService.cs +++ b/PocketClient.Desktop/Services/PocketDbService.cs @@ -105,6 +105,12 @@ public async Task SyncItemsAsync(bool fullSync = false, bool force = false) try { lastUpdatedAt = await _localSettingsService.ReadSettingAsync(_pocketLastUpdatedAtKey); + + // Indicates that the lastUpdatedAt setting is not set. + if (lastUpdatedAt.ToString() == "1/1/0001 12:00:00 AM") + { + lastUpdatedAt = null; + } } catch { } } @@ -119,7 +125,20 @@ public async Task SyncItemsAsync(bool fullSync = false, bool force = false) Since = lastUpdatedAt, }; - var items = await _pocketClient.GetItemsAsync(filter, pageSize, page * pageSize); + List items; + + try + { + items = await _pocketClient.GetItemsAsync(filter, pageSize, page * pageSize); + } + catch (Exception ex) + { + _syncing = false; + _logger.LogError(ex, "Failed to get items from server"); + WeakReferenceMessenger.Default.Send(new SyncFailureMessage("Failed to get items from server", ex)); + return; + } + hasMoreItems = items.Count == pageSize; count += items.Count; page++; @@ -140,7 +159,8 @@ public async Task SyncItemsAsync(bool fullSync = false, bool force = false) } catch (Exception ex) { - _logger.LogError(ex, "Failed to sync item"); + // In case of an error, we log the error and continue with the next item. + _logger.LogError(ex, "Failed to persist item"); } } } while (hasMoreItems); diff --git a/PocketClient.Desktop/ViewModels/ItemsViewModel.cs b/PocketClient.Desktop/ViewModels/ItemsViewModel.cs index fc9b018..6820be6 100644 --- a/PocketClient.Desktop/ViewModels/ItemsViewModel.cs +++ b/PocketClient.Desktop/ViewModels/ItemsViewModel.cs @@ -2,22 +2,26 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; -using Microsoft.UI.Dispatching; using PocketClient.Core.Contracts.Services; using PocketClient.Core.Models; using PocketClient.Core.Specifications; using PocketClient.Desktop.Contracts.ViewModels; +using PocketClient.Desktop.Helpers; using PocketClient.Desktop.Models; +using Microsoft.UI.Dispatching; namespace PocketClient.Desktop.ViewModels; public partial class ItemsViewModel : ObservableRecipient, IRecipient, + IRecipient, IRecipient, IRecipient, INavigationAware { + private readonly DispatcherQueue dispatcherQueue; + [ObservableProperty] private PocketItemOrderOption orderOption; @@ -34,6 +38,7 @@ public ItemsViewModel() { orderOption = PocketItemOrderOption.Newest; filterOption = PocketItemFilterOption.All; + dispatcherQueue = DispatcherQueue.GetForCurrentThread(); } public ObservableCollection Items = new(); @@ -138,6 +143,14 @@ public void Receive(SyncedItemsMessage message) }); } + public void Receive(SyncFailureMessage message) + { + dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, async () => + { + await App.MainWindow.ShowMessageDialogAsync(message.Reason, "Exception_DialogTitle".Format()); + }); + } + public void Receive(ItemRemovedMessage message) { UpdateSelectedItem(message.Item); diff --git a/PocketClient.Desktop/ViewModels/SettingsViewModel.cs b/PocketClient.Desktop/ViewModels/SettingsViewModel.cs index 7f77d36..ccd9469 100644 --- a/PocketClient.Desktop/ViewModels/SettingsViewModel.cs +++ b/PocketClient.Desktop/ViewModels/SettingsViewModel.cs @@ -15,7 +15,7 @@ namespace PocketClient.Desktop.ViewModels; -public partial class SettingsViewModel : ObservableRecipient, IRecipient +public partial class SettingsViewModel : ObservableRecipient, IRecipient, IRecipient { private readonly IThemeSelectorService _themeSelectorService; private readonly IPocketDbService _pocketDbService; @@ -76,6 +76,15 @@ public void Receive(SyncedItemsMessage message) Syncing = false; } + public void Receive(SyncFailureMessage message) + { + Syncing = false; + dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, async () => + { + await App.MainWindow.ShowMessageDialogAsync(message.Reason, "Exception_DialogTitle".Format()); + }); + } + private static string GetVersion() { Version version; @@ -145,8 +154,6 @@ private async Task SyncData() catch (Exception ex) { _logger.LogError(ex, "Failed to sync data in settings page"); - - await App.MainWindow.ShowMessageDialogAsync(ex.Message, "Exception_DialogTitle".Format()); } finally { diff --git a/PocketClient.HttpSdk/PocketClient.HttpSdk.csproj b/PocketClient.HttpSdk/PocketClient.HttpSdk.csproj index 21be714..cd65943 100644 --- a/PocketClient.HttpSdk/PocketClient.HttpSdk.csproj +++ b/PocketClient.HttpSdk/PocketClient.HttpSdk.csproj @@ -9,7 +9,7 @@ - + diff --git a/PocketClient.HttpSdk/PocketHttpClient.cs b/PocketClient.HttpSdk/PocketHttpClient.cs index d020b32..04c49fe 100644 --- a/PocketClient.HttpSdk/PocketHttpClient.cs +++ b/PocketClient.HttpSdk/PocketHttpClient.cs @@ -273,7 +273,13 @@ private string BuildQueryWithFilter(PocketItemFilter filter, int count, int offs if (filter.Since != null) { - queryParams.Add("since", $"{filter.Since?.ToUnixTimeSeconds()}"); + var timestamp = filter.Since.Value.ToUnixTimeSeconds(); + + // The timestamp should be greater than 0. + if (timestamp > 0) + { + queryParams.Add("since", $"{timestamp}"); + } } } diff --git a/PocketClient.sln b/PocketClient.sln index 3ebed53..099d2d3 100644 --- a/PocketClient.sln +++ b/PocketClient.sln @@ -55,8 +55,8 @@ Global {0E9B135F-BC10-4524-9C00-63766F3315FA}.Debug|x64.Build.0 = Debug|x64 {0E9B135F-BC10-4524-9C00-63766F3315FA}.Debug|x86.ActiveCfg = Debug|x86 {0E9B135F-BC10-4524-9C00-63766F3315FA}.Debug|x86.Build.0 = Debug|x86 - {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|Any CPU.Build.0 = Release|Any CPU + {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|Any CPU.ActiveCfg = Release|x64 + {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|Any CPU.Build.0 = Release|x64 {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|arm64.ActiveCfg = Release|arm64 {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|arm64.Build.0 = Release|arm64 {0E9B135F-BC10-4524-9C00-63766F3315FA}.Release|x64.ActiveCfg = Release|x64 @@ -87,8 +87,8 @@ Global {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Debug|x64.Build.0 = Debug|x64 {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Debug|x86.ActiveCfg = Debug|x86 {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Debug|x86.Build.0 = Debug|x86 - {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|Any CPU.Build.0 = Release|Any CPU + {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|Any CPU.ActiveCfg = Release|x64 + {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|Any CPU.Build.0 = Release|x64 {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|arm64.ActiveCfg = Release|arm64 {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|arm64.Build.0 = Release|arm64 {FE068BC4-6A0A-4CA8-A147-B3313D0D6998}.Release|x64.ActiveCfg = Release|x64