mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 00:54:26 +08:00
0.6.3
优化了文本框焦点,优化了更新体验,优化了遥测,披露了收集的数据。
This commit is contained in:
92
LanMountainDesktop/ViewModels/PrivacyPolicyViewModel.cs
Normal file
92
LanMountainDesktop/ViewModels/PrivacyPolicyViewModel.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
public sealed partial class PrivacyPolicyViewModel : ViewModelBase
|
||||
{
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly string _languageCode;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _title = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _description = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _loadingText = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _errorText = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _markdownContent = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasError;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasContent;
|
||||
|
||||
public PrivacyPolicyViewModel()
|
||||
{
|
||||
_languageCode = "zh-CN";
|
||||
RefreshLocalizedText();
|
||||
LoadPrivacyPolicy();
|
||||
}
|
||||
|
||||
private void RefreshLocalizedText()
|
||||
{
|
||||
Title = L("settings.privacy.policy_title", "Privacy Policy");
|
||||
Description = L("settings.privacy.policy_description", "Learn how we collect, use, and protect your data.");
|
||||
LoadingText = L("settings.privacy.policy_loading", "Loading privacy policy...");
|
||||
}
|
||||
|
||||
private async void LoadPrivacyPolicy()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
HasError = false;
|
||||
HasContent = false;
|
||||
|
||||
// 从嵌入资源加载隐私政策Markdown文件
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var resourceName = "LanMountainDesktop.Assets.Documents.Privacy.md";
|
||||
|
||||
using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream is null)
|
||||
{
|
||||
throw new FileNotFoundException($"Privacy policy resource not found: {resourceName}");
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
var markdown = await reader.ReadToEndAsync();
|
||||
|
||||
MarkdownContent = markdown;
|
||||
IsLoading = false;
|
||||
HasContent = true;
|
||||
|
||||
AppLogger.Info("PrivacyPolicy", "Privacy policy loaded successfully.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PrivacyPolicy", "Failed to load privacy policy.", ex);
|
||||
IsLoading = false;
|
||||
HasError = true;
|
||||
ErrorText = L("settings.privacy.policy_error", "Failed to load privacy policy. Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
=> _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public sealed partial class PrivacySettingsPageViewModel : ViewModelBase
|
||||
private readonly string _languageCode;
|
||||
private bool _isInitializing;
|
||||
|
||||
public event Action? ViewPrivacyPolicyRequested;
|
||||
|
||||
public PrivacySettingsPageViewModel(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
_settingsFacade = settingsFacade;
|
||||
@@ -59,6 +61,12 @@ public sealed partial class PrivacySettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _refreshDeviceIdText = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _viewPrivacyPolicyText = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _privacyPolicyHintPrefix = string.Empty;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var state = _settingsFacade.Privacy.Get();
|
||||
@@ -130,6 +138,25 @@ public sealed partial class PrivacySettingsPageViewModel : ViewModelBase
|
||||
DeviceIdHeader = L("settings.privacy.device_id_title", "Device ID");
|
||||
DeviceIdDescription = L("settings.privacy.device_id_description", "Unique identifier for this device. Click refresh to regenerate.");
|
||||
RefreshDeviceIdText = L("settings.privacy.refresh_device_id", "Refresh");
|
||||
PrivacyPolicyHintPrefix = L("settings.privacy.policy_hint_prefix", "For more details, please ");
|
||||
ViewPrivacyPolicyText = L("settings.privacy.view_policy", "view our privacy policy");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ViewPrivacyPolicy()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 触发隐私政策查看事件
|
||||
AppLogger.Info("PrivacySettings", "User requested to view privacy policy.");
|
||||
|
||||
// 发送事件通知显示隐私政策
|
||||
ViewPrivacyPolicyRequested?.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PrivacySettings", "Failed to view privacy policy.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
|
||||
@@ -1329,9 +1329,6 @@ public sealed partial class UpdateSettingsPageViewModel : ViewModelBase
|
||||
LoadStateFromSettings();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _autoCheckUpdates;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _selectedUpdateChannelValue = UpdateSettingsValues.ChannelStable;
|
||||
|
||||
@@ -1380,9 +1377,6 @@ public sealed partial class UpdateSettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _preferencesDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _autoCheckUpdatesLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _updateChannelLabel = string.Empty;
|
||||
|
||||
@@ -1520,16 +1514,6 @@ public sealed partial class UpdateSettingsPageViewModel : ViewModelBase
|
||||
|
||||
private bool IsBusy => IsCheckingForUpdates || IsDownloading;
|
||||
|
||||
partial void OnAutoCheckUpdatesChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SaveUpdateSettings();
|
||||
}
|
||||
|
||||
partial void OnSelectedUpdateChannelOptionChanged(SelectionOption? value)
|
||||
{
|
||||
if (value is not null &&
|
||||
@@ -1729,7 +1713,6 @@ public sealed partial class UpdateSettingsPageViewModel : ViewModelBase
|
||||
var current = _settingsFacade.Update.Get();
|
||||
_settingsFacade.Update.Save(current with
|
||||
{
|
||||
AutoCheckUpdates = AutoCheckUpdates,
|
||||
IncludePrereleaseUpdates = string.Equals(
|
||||
SelectedUpdateChannelValue,
|
||||
UpdateSettingsValues.ChannelPreview,
|
||||
@@ -1841,7 +1824,6 @@ public sealed partial class UpdateSettingsPageViewModel : ViewModelBase
|
||||
StatusCardDescription = L("settings.update.status_card_description", "Check for updates and review the latest release information.");
|
||||
PreferencesHeader = L("settings.update.preferences_header", "Update Preferences");
|
||||
PreferencesDescription = L("settings.update.preferences_description", "Choose your release channel, download source, behavior, and download speed.");
|
||||
AutoCheckUpdatesLabel = L("settings.update.auto_check_toggle", "Automatically check for updates on startup");
|
||||
UpdateChannelLabel = L("settings.update.channel_label", "Update Channel");
|
||||
UpdateSourceLabel = L("settings.update.source_label", "Download Source");
|
||||
UpdateModeLabel = L("settings.update.mode_label", "Update Mode");
|
||||
@@ -1870,7 +1852,6 @@ public sealed partial class UpdateSettingsPageViewModel : ViewModelBase
|
||||
{
|
||||
var update = _settingsFacade.Update.Get();
|
||||
_isInitializing = true;
|
||||
AutoCheckUpdates = update.AutoCheckUpdates;
|
||||
SelectedUpdateChannelValue = UpdateSettingsValues.NormalizeChannel(update.UpdateChannel, update.IncludePrereleaseUpdates);
|
||||
SelectedUpdateSourceValue = UpdateSettingsValues.NormalizeDownloadSource(update.UpdateDownloadSource);
|
||||
SelectedUpdateModeValue = UpdateSettingsValues.NormalizeMode(update.UpdateMode);
|
||||
|
||||
Reference in New Issue
Block a user