From f6ddf114b7e82aa019e72cb4514ea8dd4188e207 Mon Sep 17 00:00:00 2001 From: Wang Haoyu Date: Mon, 20 Jul 2026 19:49:30 +0800 Subject: [PATCH 1/3] Fix floating window profile persistence --- Actions/ToggleFloatingWindowLayerAction.cs | 10 ++- ConfigHandlers/FloatingWindowProfile.cs | 44 +--------- .../FloatingWindowProfileManager.cs | 19 ----- Services/FloatingWindowService.cs | 83 ++++++++++++------- .../FloatingWindowEditorSettingsPage.axaml | 32 +++---- .../FloatingWindowEditorSettingsPage.axaml.cs | 38 ++++++--- 6 files changed, 103 insertions(+), 123 deletions(-) diff --git a/Actions/ToggleFloatingWindowLayerAction.cs b/Actions/ToggleFloatingWindowLayerAction.cs index d1edcd35..f910f275 100644 --- a/Actions/ToggleFloatingWindowLayerAction.cs +++ b/Actions/ToggleFloatingWindowLayerAction.cs @@ -26,7 +26,11 @@ protected override async Task OnInvoke() try { var service = IAppHost.GetService(); - var profile = service.ProfileManager.CurrentProfile; + var config = GlobalConstants.MainConfig?.Data; + if (config == null) + { + return; + } // 根据设置决定是切换还是设置到指定层级 // TargetLayer: -1=切换, 0=置底, 1=置顶 @@ -34,7 +38,7 @@ protected override async Task OnInvoke() { if (IsRevertable) { - PreviousLayers[ActionSet.Guid] = profile.FloatingWindowLayer; + PreviousLayers[ActionSet.Guid] = config.FloatingWindowLayer; } service.SetWindowLayer(Settings.TargetLayer); @@ -44,7 +48,7 @@ protected override async Task OnInvoke() { if (IsRevertable) { - PreviousLayers[ActionSet.Guid] = profile.FloatingWindowLayer; + PreviousLayers[ActionSet.Guid] = config.FloatingWindowLayer; } service.ToggleWindowLayer(); diff --git a/ConfigHandlers/FloatingWindowProfile.cs b/ConfigHandlers/FloatingWindowProfile.cs index 3a4f88ae..01422b15 100644 --- a/ConfigHandlers/FloatingWindowProfile.cs +++ b/ConfigHandlers/FloatingWindowProfile.cs @@ -6,8 +6,8 @@ namespace SystemTools.ConfigHandlers; /// -/// 悬浮窗配置方案,保存一套完整的悬浮窗布局和外观配置。 -/// 注意:显示状态(ShowFloatingWindow)和规则集(HideOnRule/HidingRules)是全局设置,不随方案切换。 +/// 悬浮窗配置方案,仅保存悬浮窗按钮布局以及按钮/行规则集。 +/// 注意:外观、位置、层级、显示状态和整窗规则集是全局设置,不随方案切换。 /// public partial class FloatingWindowProfile : ObservableObject { @@ -25,46 +25,6 @@ public partial class FloatingWindowProfile : ObservableObject [JsonPropertyName("floatingWindowButtonRows")] public List> FloatingWindowButtonRows { get; set; } = new(); - [ObservableProperty] - [JsonPropertyName("floatingWindowScale")] - private double _floatingWindowScale = 1.0; - - [ObservableProperty] - [JsonPropertyName("floatingWindowIconSize")] - private int _floatingWindowIconSize = 22; - - [ObservableProperty] - [JsonPropertyName("floatingWindowTextSize")] - private int _floatingWindowTextSize = 12; - - [ObservableProperty] - [JsonPropertyName("floatingWindowOpacity")] - private int _floatingWindowOpacity = 80; - - [ObservableProperty] - [JsonPropertyName("floatingWindowPositionX")] - private int _floatingWindowPositionX = 100; - - [ObservableProperty] - [JsonPropertyName("floatingWindowPositionY")] - private int _floatingWindowPositionY = 100; - - [ObservableProperty] - [JsonPropertyName("floatingWindowLayer")] - private int _floatingWindowLayer = 1; - - [ObservableProperty] - [JsonPropertyName("floatingWindowLayerRecheckMode")] - private int _floatingWindowLayerRecheckMode = 1; - - [ObservableProperty] - [JsonPropertyName("floatingWindowShadowEnabled")] - private bool _floatingWindowShadowEnabled = true; - - [ObservableProperty] - [JsonPropertyName("floatingWindowDragHandleAlwaysVisible")] - private bool _floatingWindowDragHandleAlwaysVisible; - [JsonPropertyName("floatingWindowButtonRulesets")] public Dictionary FloatingWindowButtonRulesets { get; set; } = new(); diff --git a/ConfigHandlers/FloatingWindowProfileManager.cs b/ConfigHandlers/FloatingWindowProfileManager.cs index 3d1dc585..a87ff642 100644 --- a/ConfigHandlers/FloatingWindowProfileManager.cs +++ b/ConfigHandlers/FloatingWindowProfileManager.cs @@ -19,15 +19,6 @@ public class FloatingWindowProfileManager public static FloatingWindowProfile DefaultProfile { get; } = new() { Name = "Default", - FloatingWindowScale = 1.0, - FloatingWindowIconSize = 22, - FloatingWindowTextSize = 12, - FloatingWindowOpacity = 80, - FloatingWindowPositionX = 100, - FloatingWindowPositionY = 100, - FloatingWindowLayer = 1, - FloatingWindowLayerRecheckMode = 1, - FloatingWindowShadowEnabled = true, FloatingWindowButtonOrder = new List(), FloatingWindowButtonRows = new List>(), FloatingWindowButtonRulesets = new Dictionary(), @@ -60,16 +51,6 @@ public void MigrateFromLegacyConfig(MainConfigData legacyData) FloatingWindowHorizontal = legacyData.FloatingWindowHorizontal, FloatingWindowButtonOrder = new List(legacyData.FloatingWindowButtonOrder ?? []), FloatingWindowButtonRows = (legacyData.FloatingWindowButtonRows ?? []).Select(r => new List(r)).ToList(), - FloatingWindowScale = legacyData.FloatingWindowScale, - FloatingWindowIconSize = legacyData.FloatingWindowIconSize, - FloatingWindowTextSize = legacyData.FloatingWindowTextSize, - FloatingWindowOpacity = legacyData.FloatingWindowOpacity, - FloatingWindowPositionX = legacyData.FloatingWindowPositionX, - FloatingWindowPositionY = legacyData.FloatingWindowPositionY, - FloatingWindowLayer = legacyData.FloatingWindowLayer, - FloatingWindowLayerRecheckMode = legacyData.FloatingWindowLayerRecheckMode, - FloatingWindowShadowEnabled = legacyData.FloatingWindowShadowEnabled, - FloatingWindowDragHandleAlwaysVisible = legacyData.FloatingWindowDragHandleAlwaysVisible, FloatingWindowButtonRulesets = new Dictionary(legacyData.FloatingWindowButtonRulesets ?? []), FloatingWindowRowRulesets = new List(legacyData.FloatingWindowRowRulesets ?? []) }; diff --git a/Services/FloatingWindowService.cs b/Services/FloatingWindowService.cs index 308db0e5..68346ab7 100644 --- a/Services/FloatingWindowService.cs +++ b/Services/FloatingWindowService.cs @@ -307,7 +307,7 @@ private void EnsureWindow() Width = 64, Height = 64, ShowActivated = false, - Topmost = _profileManager.CurrentProfile.FloatingWindowLayer == 1, + Topmost = _configHandler.Data.FloatingWindowLayer == 1, SystemDecorations = SystemDecorations.None, Background = Brushes.Transparent, CanResize = false, @@ -598,10 +598,11 @@ private void RefreshWindowButtons() } var profile = _profileManager.CurrentProfile; - var scale = Math.Clamp(profile.FloatingWindowScale, 0.5, 2.0); - var iconSize = Math.Clamp(profile.FloatingWindowIconSize, 15, 50) * scale; - var textSize = Math.Clamp(profile.FloatingWindowTextSize, 8, 30) * scale; - var opacity = Math.Clamp(profile.FloatingWindowOpacity, 10, 100); + var config = _configHandler.Data; + var scale = Math.Clamp(config.FloatingWindowScale, 0.5, 2.0); + var iconSize = Math.Clamp(config.FloatingWindowIconSize, 15, 50) * scale; + var textSize = Math.Clamp(config.FloatingWindowTextSize, 8, 30) * scale; + var opacity = Math.Clamp(config.FloatingWindowOpacity, 10, 100); var alpha = (byte)Math.Round(255 * (opacity / 100.0)); var isLightTheme = IsLightTheme(); var windowBackground = isLightTheme @@ -612,7 +613,7 @@ private void RefreshWindowButtons() if (_windowContainer != null) { _windowContainer.Background = windowBackground; - _windowContainer.BoxShadow = profile.FloatingWindowShadowEnabled + _windowContainer.BoxShadow = config.FloatingWindowShadowEnabled ? new BoxShadows(new BoxShadow { OffsetX = 0, @@ -753,7 +754,7 @@ private void RefreshWindowButtons() // 仅在"至少有一个可见按钮"时才显示拖拽把手,避免孤零零一个把手 var hasVisibleButtons = _stackPanel.Children.Count > 0; - var showDragHandle = (_isTouchDeviceDetected || _profileManager.CurrentProfile.FloatingWindowDragHandleAlwaysVisible) + var showDragHandle = (_isTouchDeviceDetected || _configHandler.Data.FloatingWindowDragHandleAlwaysVisible) && hasVisibleButtons; if (showDragHandle) @@ -795,7 +796,7 @@ private bool HasAnyVisibleButton() } int rowIndex = 0; - foreach (var row in profile.FloatingWindowButtonRows ?? []) + foreach (var row in GetConfiguredButtonRowsWithFallback(profile)) { if (!hiddenRowSet.Contains(rowIndex)) { @@ -838,7 +839,7 @@ private List> GetOrderedRows() var rows = new List>(); - foreach (var row in profile.FloatingWindowButtonRows ?? []) + foreach (var row in GetConfiguredButtonRowsWithFallback(profile)) { var items = new List(); foreach (var id in row) @@ -857,6 +858,39 @@ private List> GetOrderedRows() return rows; } + + private List> GetConfiguredButtonRowsWithFallback(FloatingWindowProfile profile) + { + var validButtonIds = _entries.Values.Select(x => x.ButtonId).Distinct().ToList(); + var validSet = validButtonIds.ToHashSet(); + var rows = (profile.FloatingWindowButtonRows ?? []) + .Select(row => row.Where(validSet.Contains).Distinct().ToList()) + .Where(row => row.Count > 0) + .ToList(); + + var configuredIds = rows.SelectMany(row => row).ToHashSet(); + var missingIds = validButtonIds + .Where(id => !configuredIds.Contains(id)) + .Where(id => !profile.FloatingWindowButtonRulesets.ContainsKey(id)) + .ToList(); + + if (missingIds.Count == 0) + { + return rows; + } + + if (rows.Count == 0) + { + rows.Add(missingIds); + } + else + { + rows[0].AddRange(missingIds); + } + + return rows; + } + private void PruneButtonWidthCache() { if (_buttonWidthCache.Count == 0) @@ -1304,8 +1338,7 @@ private void RemoveLayerRecheckHooks() private void RefreshLayerRecheckMode() { - var profile = _profileManager.CurrentProfile; - var mode = profile.FloatingWindowLayerRecheckMode; + var mode = _configHandler.Data.FloatingWindowLayerRecheckMode; var useReorderHook = mode == 0; var useForegroundHook = mode == 1; @@ -1399,7 +1432,7 @@ private void OnPostMainTimerTicked(object? sender, EventArgs e) private void OnLayerRecheck50MsTimerTick(object? sender, EventArgs e) { - if (_profileManager.CurrentProfile.FloatingWindowLayerRecheckMode == 2) + if (_configHandler.Data.FloatingWindowLayerRecheckMode == 2) { RecheckWindowLayer(); } @@ -1407,7 +1440,7 @@ private void OnLayerRecheck50MsTimerTick(object? sender, EventArgs e) private void OnLayerRecheck1MsTimerTick(object? sender, EventArgs e) { - if (_profileManager.CurrentProfile.FloatingWindowLayerRecheckMode == 3) + if (_configHandler.Data.FloatingWindowLayerRecheckMode == 3) { RecheckWindowLayer(); } @@ -1421,7 +1454,7 @@ private void OnWinEvent(IntPtr hWinEventHook, uint @event, IntPtr hwnd, int idOb return; } - var mode = _profileManager.CurrentProfile.FloatingWindowLayerRecheckMode; + var mode = _configHandler.Data.FloatingWindowLayerRecheckMode; var shouldRecheck = (@event == EventObjectReorder && mode == 0) || (@event == EventSystemForeground && mode == 1); if (!shouldRecheck) @@ -1454,7 +1487,7 @@ private void RecheckWindowLayer() SET_WINDOW_POS_FLAGS.SWP_NOSENDCHANGING; var hwnd = new HWND(handle); - if (_profileManager.CurrentProfile.FloatingWindowLayer == 0) + if (_configHandler.Data.FloatingWindowLayer == 0) { _window.Topmost = false; PInvoke.SetWindowPos(hwnd, HwndBottom, 0, 0, 0, 0, flags); @@ -1467,30 +1500,18 @@ private void RecheckWindowLayer() public void ToggleWindowLayer() { - var profile = _profileManager.CurrentProfile; - profile.FloatingWindowLayer = profile.FloatingWindowLayer == 1 ? 0 : 1; - _profileManager.SaveProfile(); - Dispatcher.UIThread.Post(() => - { - if (_window != null) - { - _window.Topmost = profile.FloatingWindowLayer == 1; - } - RecheckWindowLayer(); - RefreshLayerRecheckMode(); - }); + SetWindowLayer(_configHandler.Data.FloatingWindowLayer == 1 ? 0 : 1); } public void SetWindowLayer(int layer) { - var profile = _profileManager.CurrentProfile; - profile.FloatingWindowLayer = layer == 1 ? 1 : 0; - _profileManager.SaveProfile(); + _configHandler.Data.FloatingWindowLayer = layer == 1 ? 1 : 0; + _configHandler.Save(); Dispatcher.UIThread.Post(() => { if (_window != null) { - _window.Topmost = profile.FloatingWindowLayer == 1; + _window.Topmost = _configHandler.Data.FloatingWindowLayer == 1; } RecheckWindowLayer(); RefreshLayerRecheckMode(); diff --git a/SettingsPage/FloatingWindowEditorSettingsPage.axaml b/SettingsPage/FloatingWindowEditorSettingsPage.axaml index 605f167b..ee8023f5 100644 --- a/SettingsPage/FloatingWindowEditorSettingsPage.axaml +++ b/SettingsPage/FloatingWindowEditorSettingsPage.axaml @@ -201,10 +201,10 @@ Maximum="2" TickFrequency="0.1" IsSnapToTickEnabled="True" - ToolTip.Tip="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowScale, StringFormat='{}{0:F1}x'}" - Value="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowScale, Mode=TwoWay}" /> + ToolTip.Tip="{Binding ViewModel.Settings.FloatingWindowScale, StringFormat='{}{0:F1}x'}" + Value="{Binding ViewModel.Settings.FloatingWindowScale, Mode=TwoWay}" /> @@ -221,10 +221,10 @@ Maximum="50" TickFrequency="1" IsSnapToTickEnabled="True" - ToolTip.Tip="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowIconSize, StringFormat='{}{0}px'}" - Value="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowIconSize, Mode=TwoWay}" /> + ToolTip.Tip="{Binding ViewModel.Settings.FloatingWindowIconSize, StringFormat='{}{0}px'}" + Value="{Binding ViewModel.Settings.FloatingWindowIconSize, Mode=TwoWay}" /> @@ -241,10 +241,10 @@ Maximum="25" TickFrequency="1" IsSnapToTickEnabled="True" - ToolTip.Tip="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowTextSize, StringFormat='{}{0}px'}" - Value="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowTextSize, Mode=TwoWay}" /> + ToolTip.Tip="{Binding ViewModel.Settings.FloatingWindowTextSize, StringFormat='{}{0}px'}" + Value="{Binding ViewModel.Settings.FloatingWindowTextSize, Mode=TwoWay}" /> @@ -261,9 +261,9 @@ Maximum="100" TickFrequency="1" IsSnapToTickEnabled="True" - ToolTip.Tip="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowOpacity, StringFormat='{}{0}%'}" - Value="{Binding ViewModel.CurrentFloatingWindowProfile.FloatingWindowOpacity, Mode=TwoWay}" /> - + @@ -292,7 +292,7 @@ Content="阴影效果" Description="悬浮窗阴影效果"> - + @@ -300,7 +300,7 @@ Content="一直显示拖动把手" Description="即使未检测到触摸设备也显示拖动把手"> - + @@ -311,7 +311,7 @@ Description="悬浮窗在屏幕上的层级。置底则会显示在所有窗口的后方,置顶则将显示在所有窗口的前方。" IsExpanded="False"> - + @@ -325,7 +325,7 @@ Description="在什么时候重新设置悬浮窗层级。请注意,较高的频率可能会产生较高的性能占用并导致悬浮窗闪烁。"> + SelectedIndex="{Binding ViewModel.Settings.FloatingWindowLayerRecheckMode, Mode=TwoWay}"> 窗口层级变化时 前台窗口变化时 diff --git a/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs b/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs index 76091727..4d69cd23 100644 --- a/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs +++ b/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs @@ -100,15 +100,7 @@ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e private void OnProfilePropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(FloatingWindowProfile.FloatingWindowScale) - or nameof(FloatingWindowProfile.FloatingWindowIconSize) - or nameof(FloatingWindowProfile.FloatingWindowTextSize) - or nameof(FloatingWindowProfile.FloatingWindowOpacity) - or nameof(FloatingWindowProfile.FloatingWindowShadowEnabled) - or nameof(FloatingWindowProfile.FloatingWindowLayer) - or nameof(FloatingWindowProfile.FloatingWindowLayerRecheckMode) - or nameof(FloatingWindowProfile.FloatingWindowDragHandleAlwaysVisible) - or nameof(FloatingWindowProfile.FloatingWindowHorizontal)) + if (e.PropertyName is nameof(FloatingWindowProfile.FloatingWindowHorizontal)) { IAppHost.GetService().ProfileManager.SaveProfile(); IAppHost.GetService().UpdateWindowState(); @@ -146,7 +138,15 @@ private void UnregisterHidingRulesEvents() private void OnSettingsPropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(MainConfigData.FloatingWindowTheme)) + if (e.PropertyName is nameof(MainConfigData.FloatingWindowTheme) + or nameof(MainConfigData.FloatingWindowScale) + or nameof(MainConfigData.FloatingWindowIconSize) + or nameof(MainConfigData.FloatingWindowTextSize) + or nameof(MainConfigData.FloatingWindowOpacity) + or nameof(MainConfigData.FloatingWindowShadowEnabled) + or nameof(MainConfigData.FloatingWindowDragHandleAlwaysVisible) + or nameof(MainConfigData.FloatingWindowLayer) + or nameof(MainConfigData.FloatingWindowLayerRecheckMode)) { GlobalConstants.MainConfig?.Save(); IAppHost.GetService().UpdateWindowState(); @@ -394,7 +394,7 @@ private void OnDrawerIsVisibleChanged(object? sender, RoutedEventArgs e) break; } - IAppHost.GetService().ProfileManager.SaveProfile(); + SaveCurrentRulesetTarget(); IAppHost.GetService().UpdateWindowState(); NotifyRulesetStatusChanged(); } @@ -417,7 +417,7 @@ private void OnDrawerHideOnRuleChanged(object? sender, RoutedEventArgs e) break; } - IAppHost.GetService().ProfileManager.SaveProfile(); + SaveCurrentRulesetTarget(); IAppHost.GetService().UpdateWindowState(); NotifyRulesetStatusChanged(); } @@ -427,6 +427,17 @@ private void NotifyRulesetStatusChanged() IAppHost.TryGetService()?.NotifyStatusChanged(); } + private void SaveCurrentRulesetTarget() + { + if (_currentRulesetTarget == RulesetTargetType.Window) + { + GlobalConstants.MainConfig?.Save(); + return; + } + + IAppHost.GetService().ProfileManager.SaveProfile(); + } + private void AttachRulesetListeners(Ruleset ruleset) { DetachRulesetListeners(); @@ -489,6 +500,7 @@ private void OnRulesetPropertyChanged(object? sender, PropertyChangedEventArgs e return; } + SaveCurrentRulesetTarget(); NotifyRulesetStatusChanged(); IAppHost.TryGetService()?.UpdateWindowState(); } @@ -504,6 +516,7 @@ private void OnRulesetGroupsCollectionChanged(object? sender, NotifyCollectionCh DetachRulesetListeners(); AttachRulesetListeners(ruleset); + SaveCurrentRulesetTarget(); NotifyRulesetStatusChanged(); IAppHost.TryGetService()?.UpdateWindowState(); } @@ -519,6 +532,7 @@ private void OnRulesetRulesCollectionChanged(object? sender, NotifyCollectionCha DetachRulesetListeners(); AttachRulesetListeners(ruleset); + SaveCurrentRulesetTarget(); NotifyRulesetStatusChanged(); IAppHost.TryGetService()?.UpdateWindowState(); } From 944dc6fed9bf5b36ef026c53cfe09f4cdcd0771f Mon Sep 17 00:00:00 2001 From: Programmer_MrWang Date: Mon, 20 Jul 2026 20:21:14 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=92=8C=E6=9B=B4=E6=94=B9=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Actions/ToggleFloatingWindowLayerAction.cs | 1 + .../FloatingWindowEditorSettingsPage.axaml.cs | 27 +++++-------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Actions/ToggleFloatingWindowLayerAction.cs b/Actions/ToggleFloatingWindowLayerAction.cs index f910f275..d4dad2ca 100644 --- a/Actions/ToggleFloatingWindowLayerAction.cs +++ b/Actions/ToggleFloatingWindowLayerAction.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using SystemTools.Services; using SystemTools.Settings; +using SystemTools.Shared; namespace SystemTools.Actions; diff --git a/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs b/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs index 4d69cd23..976f8092 100644 --- a/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs +++ b/SettingsPage/FloatingWindowEditorSettingsPage.axaml.cs @@ -52,7 +52,6 @@ public FloatingWindowEditorSettingsPage() ViewModel.Settings.PropertyChanged += OnSettingsPropertyChanged; ViewModel.ProfileChanged += OnViewModelProfileChanged; - // 注册全局设置变更监听(ShowFloatingWindow 和规则集不随方案切换) RegisterHidingRulesEvents(); } @@ -69,12 +68,10 @@ private enum RulesetTargetType { Button, Row, Window } private FloatingTriggerItem? _currentButtonTarget; private FloatingTriggerRow? _currentRowTarget; - // Drawer 内的控件引用 private ToggleSwitch? _drawerIsVisibleToggle; private ToggleSwitch? _drawerHideOnRuleToggle; private RulesetControl? _drawerRulesetControl; - // 当前 Drawer 中正在编辑的规则集,用于实时监听其变化 private Ruleset? _currentDrawerRuleset; private readonly List _rulesetPropertyListeners = new(); @@ -115,7 +112,6 @@ public void ReattachProfilePropertyChanged() ViewModel.CurrentFloatingWindowProfile.PropertyChanged -= OnProfilePropertyChanged; ViewModel.CurrentFloatingWindowProfile.PropertyChanged += OnProfilePropertyChanged; - // 重新注册悬浮窗规则集变更监听 UnregisterHidingRulesEvents(); RegisterHidingRulesEvents(); } @@ -160,7 +156,6 @@ or nameof(MainConfigData.FloatingWindowRulesetEnabled)) } else if (e.PropertyName == nameof(MainConfigData.FloatingWindowRuleset)) { - // Ruleset 对象被替换时,重新注册事件 UnregisterHidingRulesEvents(); RegisterHidingRulesEvents(); GlobalConstants.MainConfig?.Save(); @@ -175,7 +170,6 @@ private void OnViewModelProfileChanged(object? sender, EventArgs e) private void OnHidingRulesPropertyChanged(object? sender, PropertyChangedEventArgs e) { - // 规则集求值时会写入 State(Ruleset/RuleGroup/Rule),避免因此递归触发通知 if (IsRulesetStateProperty(e.PropertyName)) { return; @@ -195,11 +189,9 @@ private void OnFloatingWindowVisibleToggleChanged(object? sender, RoutedEventArg var service = IAppHost.GetService(); var config = ViewModel.Settings; - // 没有可用按钮时强制隐藏 var shouldShow = toggle.IsChecked == true && service.Entries.Count > 0; config.ShowFloatingWindow = shouldShow; - // 同步 ToggleSwitch 状态(可能被强制隐藏) if (toggle.IsChecked != shouldShow) { toggle.IsChecked = shouldShow; @@ -308,17 +300,14 @@ private void ButtonOpenFloatingWindowRuleset_OnClick(object? sender, RoutedEvent } /// - /// 打开规则集 Drawer,包含 IsVisible/HideOnRule 开关和规则集编辑器(参照 ClassIsland) + /// 打开规则集 Drawer /// private void OpenRulesetDrawer(ClassIsland.Core.Models.Ruleset.Ruleset ruleset, bool isVisible, bool hideOnRule) { - // 先清理上一次 Drawer 的规则集监听,避免内存泄漏和重复通知 DetachRulesetListeners(); - // 每次打开时动态构建 Drawer 内容,避免资源单例问题 var panel = new StackPanel { Spacing = 8, Margin = new Thickness(0, 8, 0, 0) }; - // Window 目标下,IsVisible 由顶栏的"显示"总开关控制,这里仅显示提示 if (_currentRulesetTarget == RulesetTargetType.Window) { var hint = new TextBlock @@ -333,7 +322,12 @@ private void OpenRulesetDrawer(ClassIsland.Core.Models.Ruleset.Ruleset ruleset, } // 开关面板 - var togglesPanel = new StackPanel { Orientation = Avalonia.Layout.Orientation.Horizontal, Spacing = 16, Margin = new Thickness(0, 0, 0, 8) }; + var togglesPanel = new StackPanel + { + Orientation = Avalonia.Layout.Orientation.Horizontal, + Spacing = 16, + Margin = new Thickness(22, 0, 0, -15) + }; _drawerIsVisibleToggle = new ToggleSwitch { @@ -362,10 +356,8 @@ private void OpenRulesetDrawer(ClassIsland.Core.Models.Ruleset.Ruleset ruleset, _drawerRulesetControl = new RulesetControl { Classes = { "in-drawer" }, Ruleset = ruleset }; panel.Children.Add(_drawerRulesetControl); - // 监听规则集内容变化,编辑时实时刷新悬浮窗状态 AttachRulesetListeners(ruleset); - // 将内容放入 Resources 并打开 Drawer this.Resources["RulesetDrawerContent"] = panel; OpenDrawer("RulesetDrawerContent"); } @@ -482,9 +474,6 @@ private void AddRulesetPropertyListener(INotifyPropertyChanged listener) _rulesetPropertyListeners.Add(listener); } - /// - /// 判断属性名是否为规则集求值写入的 State(避免递归通知) - /// private static bool IsRulesetStateProperty(string? propertyName) { return propertyName == nameof(Ruleset.State) @@ -494,7 +483,6 @@ private static bool IsRulesetStateProperty(string? propertyName) private void OnRulesetPropertyChanged(object? sender, PropertyChangedEventArgs e) { - // 规则集求值时会写入 State(Ruleset/RuleGroup/Rule),避免因此递归触发通知 if (IsRulesetStateProperty(e.PropertyName)) { return; @@ -655,7 +643,6 @@ private async void OnFloatingTriggerItemPointerMoved(object? sender, PointerEven _floatingDragSourceBorder = null; _floatingDragStartPoint = null; - // 在 await 之前缓存 Pointer.Type,避免事件参数被回收后访问 var isTouchOrPen = e.Pointer.Type is PointerType.Touch or PointerType.Pen; await DragDrop.DoDragDrop(e, data, DragDropEffects.Move); e.Handled = isTouchOrPen; From f2e04fcf742e3d9b529be2058df650fddb665fcf Mon Sep 17 00:00:00 2001 From: Programmer_MrWang Date: Mon, 20 Jul 2026 20:29:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=20-=202.5.1.101?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-2.md | 5 ++++- manifest.yml | 2 +- version.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README-2.md b/README-2.md index 6c782f3a..4decb89e 100644 --- a/README-2.md +++ b/README-2.md @@ -1,4 +1,7 @@ -## SystemTools v2.5.1.0 - 2026.6.22更新 +## 这是一个自动构建提交! + + +## SystemTools v2.5.1.0 - 2026.6.22更新 ### 🚀 新增: diff --git a/manifest.yml b/manifest.yml index 7a450a34..a33345b2 100644 --- a/manifest.yml +++ b/manifest.yml @@ -8,7 +8,7 @@ name: SystemTools description: 提供多彩而丰富的更多 组件/行动/触发器/实用工具 entranceAssembly: "SystemTools.dll" url: https://github.com/Programmer-MrWang/SystemTools -version: 2.5.1.0 +version: 2.5.1.101 apiVersion: 2.0.0.0 author: Programmer-MrWang readme: README.md diff --git a/version.json b/version.json index ca3f2281..b89f4062 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "Version": "2.5.0.0", + "Version": "2.5.1.0", "LastCheckDate": "2000-01-01T00:00:00.7067237+08:00" } \ No newline at end of file