diff --git a/PocketClient.Core/PocketClient.Core.csproj b/PocketClient.Core/PocketClient.Core.csproj index 06181b2..0c09db2 100644 --- a/PocketClient.Core/PocketClient.Core.csproj +++ b/PocketClient.Core/PocketClient.Core.csproj @@ -1,6 +1,6 @@  - net7.0 + net8.0 x86;x64;arm64 PocketClient.Core enable diff --git a/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj b/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj index 44bb9d4..3746c8a 100644 --- a/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj +++ b/PocketClient.Desktop.Tests.MSTest/PocketClient.Desktop.Tests.MSTest.csproj @@ -1,13 +1,13 @@  - net7.0-windows10.0.19041.0 + net8.0-windows10.0.22621.0 PocketClient.Desktop.Tests.MSTest x86;x64;arm64 + win-x86;win-x64;win-arm64 false enable enable true - resources.pri diff --git a/PocketClient.Desktop/App.xaml.cs b/PocketClient.Desktop/App.xaml.cs index 4afd845..844ba18 100644 --- a/PocketClient.Desktop/App.xaml.cs +++ b/PocketClient.Desktop/App.xaml.cs @@ -148,7 +148,7 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args) // The following code doesn't work // See details at https://github.com/microsoft/WindowsAppSDK/issues/3179 - // + //var mainInstance = AppInstance.FindOrRegisterForKey("pocket-desktop-app-main-exe"); //if (!mainInstance.IsCurrent) diff --git a/PocketClient.Desktop/Contracts/Services/IAuthService.cs b/PocketClient.Desktop/Contracts/Services/IAuthService.cs index 65f3cf0..886b2d6 100644 --- a/PocketClient.Desktop/Contracts/Services/IAuthService.cs +++ b/PocketClient.Desktop/Contracts/Services/IAuthService.cs @@ -9,4 +9,6 @@ public interface IAuthService public Task LaunchAuthorizationAsync(); public Task AuthorizeAsync(); + + public Task LogoutAsync(); } diff --git a/PocketClient.Desktop/Contracts/Services/IPocketDbService.cs b/PocketClient.Desktop/Contracts/Services/IPocketDbService.cs index 3d815cc..d1b8bf6 100644 --- a/PocketClient.Desktop/Contracts/Services/IPocketDbService.cs +++ b/PocketClient.Desktop/Contracts/Services/IPocketDbService.cs @@ -7,4 +7,6 @@ public interface IPocketDbService public string GetPocketDbPath(); public Task SyncItemsAsync(bool fullSync = false, bool force = false); + + public Task ClearDbAsync(); } diff --git a/PocketClient.Desktop/Models/Messages/UserLoggedOutMessage.cs b/PocketClient.Desktop/Models/Messages/UserLoggedOutMessage.cs new file mode 100644 index 0000000..73e5816 --- /dev/null +++ b/PocketClient.Desktop/Models/Messages/UserLoggedOutMessage.cs @@ -0,0 +1,5 @@ +namespace PocketClient.Desktop.Models; + +public class UserLoggedOutMessage +{ +} diff --git a/PocketClient.Desktop/PocketClient.Desktop.csproj b/PocketClient.Desktop/PocketClient.Desktop.csproj index ca38013..35472c0 100644 --- a/PocketClient.Desktop/PocketClient.Desktop.csproj +++ b/PocketClient.Desktop/PocketClient.Desktop.csproj @@ -1,13 +1,13 @@  WinExe - net7.0-windows10.0.19041.0 - 10.0.17763.0 + net8.0-windows10.0.22621.0 + 10.0.19041.0 PocketClient.Desktop Assets/WindowIcon.ico app.manifest x86;x64;arm64 - win10-x86;win10-x64;win10-arm64 + win-x86;win-x64;win-arm64 Properties\PublishProfiles\win10-$(Platform).pubxml enable enable diff --git a/PocketClient.Desktop/Properties/PublishProfiles/win10-arm64.pubxml b/PocketClient.Desktop/Properties/PublishProfiles/win10-arm64.pubxml index b2f476e..62e6e15 100644 --- a/PocketClient.Desktop/Properties/PublishProfiles/win10-arm64.pubxml +++ b/PocketClient.Desktop/Properties/PublishProfiles/win10-arm64.pubxml @@ -3,7 +3,7 @@ FileSystem arm64 - win10-arm64 + win-arm64 bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ True False diff --git a/PocketClient.Desktop/Properties/PublishProfiles/win10-x64.pubxml b/PocketClient.Desktop/Properties/PublishProfiles/win10-x64.pubxml index a8146b5..071f57c 100644 --- a/PocketClient.Desktop/Properties/PublishProfiles/win10-x64.pubxml +++ b/PocketClient.Desktop/Properties/PublishProfiles/win10-x64.pubxml @@ -3,7 +3,7 @@ FileSystem x64 - win10-x64 + win-x64 bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ True False diff --git a/PocketClient.Desktop/Properties/PublishProfiles/win10-x86.pubxml b/PocketClient.Desktop/Properties/PublishProfiles/win10-x86.pubxml index eae0948..6de977a 100644 --- a/PocketClient.Desktop/Properties/PublishProfiles/win10-x86.pubxml +++ b/PocketClient.Desktop/Properties/PublishProfiles/win10-x86.pubxml @@ -3,7 +3,7 @@ FileSystem x86 - win10-x86 + win-x86 bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ True False diff --git a/PocketClient.Desktop/Services/ActivationService.cs b/PocketClient.Desktop/Services/ActivationService.cs index 68d608b..5b42d73 100644 --- a/PocketClient.Desktop/Services/ActivationService.cs +++ b/PocketClient.Desktop/Services/ActivationService.cs @@ -1,9 +1,11 @@ -using Microsoft.Extensions.Logging; +using CommunityToolkit.Mvvm.Messaging; +using Microsoft.Extensions.Logging; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.Windows.AppLifecycle; using PocketClient.Desktop.Activation; using PocketClient.Desktop.Contracts.Services; +using PocketClient.Desktop.Models; using PocketClient.Desktop.Views; using Windows.ApplicationModel.Activation; using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs; @@ -35,6 +37,11 @@ public ActivationService( _pocketDbService = pocketDbService; _authService = authService; _logger = logger; + + WeakReferenceMessenger.Default.Register(this, (sender, message) => + { + HandleUserLoggedOutAsync(); + }); } public async Task ActivateAsync(object activationArgs) @@ -166,4 +173,10 @@ private async Task StartupAsync() } await Task.CompletedTask; } + + private void HandleUserLoggedOutAsync() + { + App.MainWindow.Content = App.GetService(); + _ = App.GetService().ClearDbAsync(); + } } diff --git a/PocketClient.Desktop/Services/AuthService.cs b/PocketClient.Desktop/Services/AuthService.cs index a5dd484..b3eb49d 100644 --- a/PocketClient.Desktop/Services/AuthService.cs +++ b/PocketClient.Desktop/Services/AuthService.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Options; +using CommunityToolkit.Mvvm.Messaging; +using Microsoft.Extensions.Options; using PocketClient.Desktop.Contracts.Services; using PocketClient.Desktop.Models; using PocketClient.HttpSdk; @@ -90,4 +91,13 @@ public async Task AuthorizeAsync() await _localSettingsService.SaveSettingAsync(_userNameKey, result.Username); _isAuthorized = true; } + + public async Task LogoutAsync() + { + await _localSettingsService.SaveSettingAsync(_userAccessTokenKey, string.Empty); + await _localSettingsService.SaveSettingAsync(_userNameKey, string.Empty); + _isAuthorized = false; + + WeakReferenceMessenger.Default.Send(new UserLoggedOutMessage()); + } } diff --git a/PocketClient.Desktop/Services/PocketDbService.cs b/PocketClient.Desktop/Services/PocketDbService.cs index a082e8c..29cdf90 100644 --- a/PocketClient.Desktop/Services/PocketDbService.cs +++ b/PocketClient.Desktop/Services/PocketDbService.cs @@ -149,4 +149,10 @@ public async Task SyncItemsAsync(bool fullSync = false, bool force = false) } } } + + public async Task ClearDbAsync() + { + await App.GetService().ClearDbAsync(); + await _localSettingsService.SaveSettingAsync(_pocketLastUpdatedAtKey, string.Empty); + } } diff --git a/PocketClient.Desktop/Strings/en-us/Resources.resw b/PocketClient.Desktop/Strings/en-us/Resources.resw index e3d3f3e..62f9554 100644 --- a/PocketClient.Desktop/Strings/en-us/Resources.resw +++ b/PocketClient.Desktop/Strings/en-us/Resources.resw @@ -437,4 +437,19 @@ Read mode + + Are you sure to log out current account? + + + Log out + + + Log out? + + + Account + + + Log out + \ No newline at end of file diff --git a/PocketClient.Desktop/Strings/zh-Hans-CN/Resources.resw b/PocketClient.Desktop/Strings/zh-Hans-CN/Resources.resw index f0d039c..40287a5 100644 --- a/PocketClient.Desktop/Strings/zh-Hans-CN/Resources.resw +++ b/PocketClient.Desktop/Strings/zh-Hans-CN/Resources.resw @@ -260,6 +260,15 @@ 欢迎使用 Nuts, 一款为 Pocket 实现的第三方桌面应用 + + 确认要登出当前账号吗? + + + 登出 + + + 登出? + 添加标签,标签之间使用分号(;)分隔 @@ -347,6 +356,9 @@ 面向 GetPocket (https://getpocket.com) 的第三方 Windows 桌面应用. + + 账号 + 数据 @@ -359,6 +371,9 @@ 默认 + + 登出 + 个性化 diff --git a/PocketClient.Desktop/ViewModels/SettingsViewModel.cs b/PocketClient.Desktop/ViewModels/SettingsViewModel.cs index d5da40a..0b5c9a8 100644 --- a/PocketClient.Desktop/ViewModels/SettingsViewModel.cs +++ b/PocketClient.Desktop/ViewModels/SettingsViewModel.cs @@ -19,6 +19,7 @@ public class SettingsViewModel : ObservableRecipient private readonly IThemeSelectorService _themeSelectorService; private readonly IPocketDbService _pocketDbService; private readonly ILogger _logger; + private readonly IAuthService _authService; private ElementTheme _elementTheme; private string _versionDescription; @@ -64,14 +65,21 @@ public ICommand SyncDataCommand get; } + public ICommand LogoutCommand + { + get; + } + public SettingsViewModel( IThemeSelectorService themeSelectorService, IPocketDbService pocketDbService, - ILogger logger) + ILogger logger, + IAuthService authService) { _themeSelectorService = themeSelectorService; _pocketDbService = pocketDbService; _logger = logger; + _authService = authService; _elementTheme = _themeSelectorService.Theme; _language = GetPreferredLanguage(); @@ -81,6 +89,7 @@ public SettingsViewModel( SwitchThemeCommand = new AsyncRelayCommand(SwitchTheme); SwitchLanguageCommand = new RelayCommand(SwitchLanguage); SyncDataCommand = new AsyncRelayCommand(SyncData); + LogoutCommand = new AsyncRelayCommand(Logout); } private static string GetVersionDescription() @@ -156,4 +165,9 @@ private async Task SyncData() Syncing = false; } } + + private async Task Logout() + { + await _authService.LogoutAsync(); + } } diff --git a/PocketClient.Desktop/Views/SettingsPage.xaml b/PocketClient.Desktop/Views/SettingsPage.xaml index 90df166..eb1d18f 100644 --- a/PocketClient.Desktop/Views/SettingsPage.xaml +++ b/PocketClient.Desktop/Views/SettingsPage.xaml @@ -107,6 +107,14 @@ + + +