add:墨迹自动保存

This commit is contained in:
CJK_mkp
2025-11-01 20:42:18 +08:00
parent 8394e99127
commit 0d790bbd80
6 changed files with 121 additions and 0 deletions
+24
View File
@@ -3083,6 +3083,30 @@
Toggled="ToggleSwitchAutoSaveStrokesAtScreenshot_Toggled" />
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#fafafa" Text="定时自动保存墨迹" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<ui:ToggleSwitch OnContent="" OffContent=""
Name="ToggleSwitchEnableAutoSaveStrokes" IsOn="False"
FontFamily="Microsoft YaHei UI" FontWeight="Bold"
Toggled="ToggleSwitchEnableAutoSaveStrokes_Toggled" />
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#a1a1aa" Text="保存间隔" VerticalAlignment="Center"
FontSize="12" Margin="0,0,16,0" />
<ComboBox Name="ComboBoxAutoSaveStrokesInterval" Width="120"
SelectionChanged="ComboBoxAutoSaveStrokesInterval_SelectionChanged">
<ComboBoxItem Content="1分钟" Tag="1" />
<ComboBoxItem Content="3分钟" Tag="3" />
<ComboBoxItem Content="5分钟" Tag="5" />
<ComboBoxItem Content="10分钟" Tag="10" />
<ComboBoxItem Content="15分钟" Tag="15" />
<ComboBoxItem Content="30分钟" Tag="30" />
<ComboBoxItem Content="60分钟" Tag="60" />
</ComboBox>
</ui:SimpleStackPanel>
<TextBlock Text="# 开启后将在设定时间间隔自动保存墨迹,仅在画布可见且有墨迹时才会保存" TextWrapping="Wrap" Foreground="#a1a1aa" />
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#fafafa" Text="墨迹全页面保存" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
+1
View File
@@ -1853,6 +1853,7 @@ namespace Ink_Canvas
// 添加定时器来维护置顶状态
private DispatcherTimer topmostMaintenanceTimer;
private DispatcherTimer autoSaveStrokesTimer;
private bool isTopmostMaintenanceEnabled;
private void ApplyNoFocusMode()
+23
View File
@@ -1877,6 +1877,29 @@ namespace Ink_Canvas
SaveSettingsToFile();
}
private void ToggleSwitchEnableAutoSaveStrokes_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Automation.IsEnableAutoSaveStrokes = ToggleSwitchEnableAutoSaveStrokes.IsOn;
SaveSettingsToFile();
// 更新定时器状态
UpdateAutoSaveStrokesTimer();
}
private void ComboBoxAutoSaveStrokesInterval_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isLoaded || ComboBoxAutoSaveStrokesInterval.SelectedItem == null) return;
var selectedItem = ComboBoxAutoSaveStrokesInterval.SelectedItem as System.Windows.Controls.ComboBoxItem;
if (selectedItem?.Tag != null && int.TryParse(selectedItem.Tag.ToString(), out int intervalMinutes))
{
Settings.Automation.AutoSaveStrokesIntervalMinutes = intervalMinutes;
SaveSettingsToFile();
// 更新定时器间隔
UpdateAutoSaveStrokesTimer();
}
}
#endregion
#region Gesture
@@ -1053,6 +1053,23 @@ namespace Ink_Canvas
ToggleSwitchSaveFullPageStrokes.IsOn = Settings.Automation.IsSaveFullPageStrokes;
// 加载定时保存墨迹设置
ToggleSwitchEnableAutoSaveStrokes.IsOn = Settings.Automation.IsEnableAutoSaveStrokes;
// 初始化保存间隔下拉框
if (ComboBoxAutoSaveStrokesInterval != null)
{
int intervalMinutes = Settings.Automation.AutoSaveStrokesIntervalMinutes;
if (intervalMinutes < 1) intervalMinutes = 5; // 默认5分钟
foreach (System.Windows.Controls.ComboBoxItem item in ComboBoxAutoSaveStrokesInterval.Items)
{
if (item.Tag != null && int.TryParse(item.Tag.ToString(), out int tagValue) && tagValue == intervalMinutes)
{
ComboBoxAutoSaveStrokesInterval.SelectedItem = item;
break;
}
}
}
SideControlMinimumAutomationSlider.Value = Settings.Automation.MinimumAutomationStrokeNumber;
AutoSavedStrokesLocation.Text = Settings.Automation.AutoSavedStrokesLocation;
+50
View File
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
namespace Ink_Canvas
{
@@ -148,6 +149,55 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"程序启动时NTP同步失败: {ex.Message}", LogHelper.LogType.Error);
}
});
// 初始化定时保存墨迹定时器
InitAutoSaveStrokesTimer();
}
// 初始化定时保存墨迹定时器
private void InitAutoSaveStrokesTimer()
{
if (autoSaveStrokesTimer == null)
{
autoSaveStrokesTimer = new DispatcherTimer();
autoSaveStrokesTimer.Tick += AutoSaveStrokesTimer_Tick;
}
// 根据设置更新定时器间隔和启动状态
UpdateAutoSaveStrokesTimer();
}
// 更新定时保存墨迹定时器状态
private void UpdateAutoSaveStrokesTimer()
{
if (autoSaveStrokesTimer == null) return;
autoSaveStrokesTimer.Stop();
if (Settings.Automation.IsEnableAutoSaveStrokes)
{
int intervalMinutes = Settings.Automation.AutoSaveStrokesIntervalMinutes;
if (intervalMinutes < 1) intervalMinutes = 1; // 最小间隔1分钟
autoSaveStrokesTimer.Interval = TimeSpan.FromMinutes(intervalMinutes);
autoSaveStrokesTimer.Start();
}
}
// 定时保存墨迹定时器事件处理
private void AutoSaveStrokesTimer_Tick(object sender, EventArgs e)
{
try
{
// 只有在画布可见且有墨迹时才保存
if (inkCanvas.Visibility == Visibility.Visible && inkCanvas.Strokes.Count > 0)
{
// 静默保存
SaveInkCanvasStrokes(false, false);
}
}
catch (Exception)
{
}
}
// NTP同步定时器事件处理
+6
View File
@@ -462,6 +462,12 @@ namespace Ink_Canvas
[JsonProperty("isAutoEnterAnnotationAfterKillHite")]
public bool IsAutoEnterAnnotationAfterKillHite { get; set; }
[JsonProperty("isEnableAutoSaveStrokes")]
public bool IsEnableAutoSaveStrokes { get; set; } = true;
[JsonProperty("autoSaveStrokesIntervalMinutes")]
public int AutoSaveStrokesIntervalMinutes { get; set; } = 5;
[JsonProperty("floatingWindowInterceptor")]
public FloatingWindowInterceptorSettings FloatingWindowInterceptor { get; set; } = new FloatingWindowInterceptorSettings();
}