add:Dlass遥测
This commit is contained in:
@@ -426,6 +426,9 @@ namespace Ink_Canvas.Helpers
|
||||
[JsonProperty("lastModified")]
|
||||
public DateTime LastModified { get; set; }
|
||||
|
||||
[JsonProperty("updateChannel")]
|
||||
public Ink_Canvas.UpdateChannel UpdateChannel { get; set; } = Ink_Canvas.UpdateChannel.Release;
|
||||
|
||||
// 每周统计数据(秒级精度)
|
||||
[JsonProperty("weeklyLaunchCount")]
|
||||
public int WeeklyLaunchCount { get; set; }
|
||||
@@ -1003,6 +1006,40 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateUsageChannel(Ink_Canvas.UpdateChannel channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (fileLock)
|
||||
{
|
||||
var stats = LoadUsageStats();
|
||||
if (stats == null)
|
||||
{
|
||||
stats = new UsageStats
|
||||
{
|
||||
DeviceId = DeviceId,
|
||||
LastLaunchTime = DateTime.Now,
|
||||
LaunchCount = 0,
|
||||
TotalUsageSeconds = 0,
|
||||
AverageSessionSeconds = 0,
|
||||
LastUpdateCheck = DateTime.MinValue,
|
||||
UpdatePriority = UpdatePriority.Medium,
|
||||
UsageFrequency = UsageFrequency.Medium
|
||||
};
|
||||
}
|
||||
|
||||
stats.UpdateChannel = channel;
|
||||
SaveUsageStats(stats);
|
||||
|
||||
LogHelper.WriteLogToFile($"DeviceIdentifier | 更新使用统计中的通道信息: {channel}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"DeviceIdentifier | 更新通道信息到使用统计失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录更新检查时间
|
||||
/// </summary>
|
||||
|
||||
@@ -8,7 +8,7 @@ using Sentry;
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// 遥测上传辅助类:根据用户设置,通过 Sentry 上传 usage_stats.enc 和 Crashes 目录的摘要信息。
|
||||
/// 遥测上传:根据用户设置,通过 Sentry 上传 usage_stats 和 Crashes 目录的摘要信息。
|
||||
/// </summary>
|
||||
internal static class TelemetryUploader
|
||||
{
|
||||
@@ -42,24 +42,7 @@ namespace Ink_Canvas.Helpers
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取 usage_stats.enc 作为基础数据
|
||||
string usageStatsPath = Path.Combine(App.RootPath, "usage_stats.enc");
|
||||
string usageStatsContent = null;
|
||||
if (File.Exists(usageStatsPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
usageStatsContent = File.ReadAllText(usageStatsPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile(
|
||||
$"TelemetryUploader | 读取 usage_stats.enc 失败: {ex.Message}",
|
||||
LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:读取 Crashes 目录下的崩溃日志(仅在扩展模式时上传)
|
||||
// 可选:Crashes 目录下的崩溃日志
|
||||
List<object> crashFiles = null;
|
||||
if (level == TelemetryUploadLevel.Extended)
|
||||
{
|
||||
@@ -71,32 +54,28 @@ namespace Ink_Canvas.Helpers
|
||||
crashFiles = new List<object>();
|
||||
var files = Directory.GetFiles(crashDir);
|
||||
|
||||
int count = 0;
|
||||
FileInfo latestInfo = null;
|
||||
string latestContent = null;
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (count >= 10)
|
||||
{
|
||||
break; // 简单限制:最多上传最近10个文件
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var info = new FileInfo(file);
|
||||
|
||||
// 避免一次上传过大,单文件限制为 512KB
|
||||
if (info.Length > 512 * 1024)
|
||||
// 避免一次上传过大,单文件限制为 8192KB
|
||||
if (info.Length > 8192 * 1024)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string content = File.ReadAllText(file);
|
||||
crashFiles.Add(new
|
||||
{
|
||||
file_name = info.Name,
|
||||
content = content
|
||||
});
|
||||
|
||||
count++;
|
||||
if (latestInfo == null || info.LastWriteTime > latestInfo.LastWriteTime)
|
||||
{
|
||||
latestInfo = info;
|
||||
latestContent = content;
|
||||
}
|
||||
}
|
||||
catch (Exception exFile)
|
||||
{
|
||||
@@ -105,6 +84,15 @@ namespace Ink_Canvas.Helpers
|
||||
LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
if (latestInfo != null && latestContent != null)
|
||||
{
|
||||
crashFiles.Add(new
|
||||
{
|
||||
file_name = latestInfo.Name,
|
||||
content = latestContent
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -115,15 +103,6 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
SentrySdk.ConfigureScope(scope =>
|
||||
{
|
||||
if (scope.User == null)
|
||||
{
|
||||
scope.User = new Sentry.User();
|
||||
}
|
||||
scope.User.Id = deviceId;
|
||||
});
|
||||
|
||||
// 通过 Sentry 上报一个包含遥测信息的事件
|
||||
var evt = new SentryEvent
|
||||
{
|
||||
@@ -133,10 +112,10 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
evt.SetTag("telemetry_level", level.ToString());
|
||||
evt.SetTag("device_id", deviceId);
|
||||
evt.SetTag("update_channel", settings.Startup.UpdateChannel.ToString());
|
||||
evt.SetTag("app_version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
evt.SetTag("os_version", Environment.OSVersion.VersionString);
|
||||
|
||||
evt.SetExtra("usage_stats_raw", usageStatsContent);
|
||||
if (crashFiles != null)
|
||||
{
|
||||
evt.SetExtra("crash_files", crashFiles);
|
||||
@@ -147,7 +126,6 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 遥测上传失败不影响主功能
|
||||
LogHelper.WriteLogToFile($"TelemetryUploader | 遥测上传失败: {ex.Message}", LogHelper.LogType.Warning);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3902,7 +3902,7 @@
|
||||
<TextBlock Text="匿名使用数据上传:" Foreground="#a1a1aa" FontSize="12"
|
||||
VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="ComboBoxTelemetryUploadLevel"
|
||||
Width="160"
|
||||
Width="230"
|
||||
Margin="8,0,0,0"
|
||||
SelectionChanged="ComboBoxTelemetryUploadLevel_SelectionChanged">
|
||||
<ComboBoxItem Tag="0">关闭(不上传)</ComboBoxItem>
|
||||
|
||||
@@ -534,7 +534,6 @@ namespace Ink_Canvas
|
||||
// 初始化Dlass上传队列(恢复上次的上传队列)
|
||||
DlassNoteUploader.InitializeQueue();
|
||||
|
||||
// 根据用户设置上传匿名使用数据(usage_stats.enc / Crashes)
|
||||
_ = TelemetryUploader.UploadTelemetryIfNeededAsync();
|
||||
|
||||
// 检查保存路径是否可用,不可用则修正
|
||||
|
||||
@@ -3956,6 +3956,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
Settings.Startup.UpdateChannel = newChannel;
|
||||
DeviceIdentifier.UpdateUsageChannel(newChannel);
|
||||
LogHelper.WriteLogToFile($"Settings | Update channel changed to {Settings.Startup.UpdateChannel}");
|
||||
SaveSettingsToFile();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user