mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-21 16:14:28 +08:00
0.6.0.1
应用遥测,插件市场
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
@@ -28,6 +32,9 @@ public sealed partial class PrivacySettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private bool _uploadAnonymousUsageData;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _deviceId = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _privacyHeader = string.Empty;
|
||||
|
||||
@@ -43,11 +50,47 @@ public sealed partial class PrivacySettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _usageUploadDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _deviceIdHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _deviceIdDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _refreshDeviceIdText = string.Empty;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var state = _settingsFacade.Privacy.Get();
|
||||
UploadAnonymousCrashData = state.UploadAnonymousCrashData;
|
||||
UploadAnonymousUsageData = state.UploadAnonymousUsageData;
|
||||
DeviceId = DeviceIdService.Instance.DeviceId;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RefreshDeviceId()
|
||||
{
|
||||
try
|
||||
{
|
||||
var deviceInfo = $"{Environment.MachineName}|{Environment.ProcessorCount}|{Environment.OSVersion}|{Environment.UserName}|{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
|
||||
using var sha = System.Security.Cryptography.SHA256.Create();
|
||||
var hash = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(deviceInfo));
|
||||
var newDeviceId = Convert.ToHexString(hash)[..32].ToLower();
|
||||
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<Models.AppSettingsSnapshot>(SettingsScope.App);
|
||||
snapshot.DeviceId = newDeviceId;
|
||||
_settingsFacade.Settings.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
snapshot,
|
||||
changedKeys: [nameof(Models.AppSettingsSnapshot.DeviceId)]);
|
||||
|
||||
DeviceId = newDeviceId;
|
||||
AppLogger.Info("PrivacySettings", $"Device ID refreshed: {newDeviceId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PrivacySettings", "Failed to refresh device ID.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnUploadAnonymousCrashDataChanged(bool value)
|
||||
@@ -84,6 +127,9 @@ public sealed partial class PrivacySettingsPageViewModel : ViewModelBase
|
||||
CrashUploadDescription = L("settings.privacy.crash_upload_description", "Help us improve application stability.");
|
||||
UsageUploadHeader = L("settings.privacy.usage_upload_title", "Anonymous usage data uploads");
|
||||
UsageUploadDescription = L("settings.privacy.usage_upload_description", "Help us improve application features.");
|
||||
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");
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
|
||||
Reference in New Issue
Block a user