-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettings.cs
More file actions
190 lines (166 loc) · 6.33 KB
/
Copy pathSettings.cs
File metadata and controls
190 lines (166 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace FluidBar;
public enum IslandDisplayStrategy
{
LatestOnly,
Multiple
}
/// <summary>
/// FluidBar 配置模型 + JSON 持久化
/// </summary>
public sealed class FluidBarSettings
{
private static readonly string SettingsDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FluidBar");
private static readonly string SettingsPath = Path.Combine(SettingsDir, "settings.json");
private static readonly JsonSerializerOptions JsonOptions = new()
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.Never
};
// === 位置 ===
public string Position { get; set; } = "Top";
public double OffsetX { get; set; } = 0;
public double OffsetY { get; set; } = 0;
// === 尺寸 ===
public double CollapsedWidth { get; set; } = 126;
public double CollapsedHeight { get; set; } = 38;
public double ExpandedMaxWidth { get; set; } = 430;
public double ExpandedHeight { get; set; } = 76;
// === 外观 ===
public double CornerRadius { get; set; } = 24;
public double Opacity { get; set; } = 0.96;
public double BackgroundOpacity { get; set; } = 0.75;
public string BackgroundColor { get; set; } = "#F4000000";
public string AccentColor { get; set; } = "#0A84FF";
// === 行为 ===
public bool AlwaysOnTop { get; set; } = true;
public bool AlwaysVisible { get; set; } = false;
public int AutoHideDelayMs { get; set; } = 3000;
public IslandDisplayStrategy DisplayStrategy { get; set; } = IslandDisplayStrategy.LatestOnly;
public int MaxVisibleIslands { get; set; } = 4;
public double MultiIslandGap { get; set; } = 10;
// === 环绕微光 ===
// "Always" = 始终旋转, "Event" = 新状态时旋转(除时钟), "Plugin" = 仅插件状态旋转
public string RimMode { get; set; } = "Event";
// === 事件开关 ===
public bool ClipboardEnabled { get; set; } = true;
public Dictionary<string, bool> PluginEnabled { get; set; } = new();
// === 功能详情配置 ===
public Dictionary<string, MonitorFeatureSettings> MonitorFeatureSettings { get; set; } = new();
// === 杂项 ===
public bool HideTrayIcon { get; set; } = false;
public string HoldToHideKey { get; set; } = HoldToHideKeyPolicy.LeftAlt;
// === 主题 ===
// "Light" 或 "Dark",默认 Light
public string SettingsTheme { get; set; } = "Light";
// === 更新 ===
// 启动时自动检查更新并灵动岛提示,默认开启
public bool AutoUpdateCheck { get; set; } = true;
// === Agent hooks 守护 ===
public bool AgentHooksGuardEnabled { get; set; } = true;
public int AgentHooksGuardIntervalMs { get; set; } = 30_000;
// === Agent 运行时保持灵动岛显示 ===
public bool AgentKeepIslandVisible { get; set; } = true;
// === Agent hooks 守护 ===
public bool HooksGuardEnabled { get; set; } = true;
public int HooksGuardIntervalMs { get; set; } = 30_000;
public MonitorFeatureSettings GetMonitorFeatureSettings(string id)
{
if (!MonitorFeatureSettings.TryGetValue(id, out var settings))
{
settings = new MonitorFeatureSettings();
MonitorFeatureSettings[id] = settings;
}
return settings;
}
public bool IsPluginEnabled(string id, bool defaultValue = true)
{
return PluginEnabled.TryGetValue(id, out var enabled)
? enabled
: defaultValue;
}
public void SetPluginEnabled(string id, bool enabled)
{
PluginEnabled[id] = enabled;
if (id == "clipboard")
ClipboardEnabled = enabled;
}
/// <summary>
/// 保存配置到 JSON 文件
/// </summary>
public void Save()
{
try
{
Directory.CreateDirectory(SettingsDir);
var json = JsonSerializer.Serialize(this, JsonOptions);
File.WriteAllText(SettingsPath, json);
}
catch
{
// 保存失败时静默忽略
}
}
/// <summary>
/// 从 JSON 文件加载配置,不存在则返回默认值
/// </summary>
public static FluidBarSettings Load()
{
try
{
if (File.Exists(SettingsPath))
{
var json = File.ReadAllText(SettingsPath);
return JsonSerializer.Deserialize<FluidBarSettings>(json, JsonOptions) ?? new FluidBarSettings();
}
}
catch
{
// 加载失败时返回默认值
}
return new FluidBarSettings();
}
/// <summary>
/// 重置为默认值
/// </summary>
public void ResetToDefaults()
{
var defaults = new FluidBarSettings();
Position = defaults.Position;
OffsetX = defaults.OffsetX;
OffsetY = defaults.OffsetY;
CollapsedWidth = defaults.CollapsedWidth;
CollapsedHeight = defaults.CollapsedHeight;
ExpandedMaxWidth = defaults.ExpandedMaxWidth;
ExpandedHeight = defaults.ExpandedHeight;
CornerRadius = defaults.CornerRadius;
Opacity = defaults.Opacity;
BackgroundOpacity = defaults.BackgroundOpacity;
BackgroundColor = defaults.BackgroundColor;
AccentColor = defaults.AccentColor;
AlwaysOnTop = defaults.AlwaysOnTop;
AlwaysVisible = defaults.AlwaysVisible;
AutoHideDelayMs = defaults.AutoHideDelayMs;
DisplayStrategy = defaults.DisplayStrategy;
MaxVisibleIslands = defaults.MaxVisibleIslands;
MultiIslandGap = defaults.MultiIslandGap;
RimMode = defaults.RimMode;
ClipboardEnabled = defaults.ClipboardEnabled;
PluginEnabled = new Dictionary<string, bool>();
MonitorFeatureSettings = new Dictionary<string, MonitorFeatureSettings>();
HideTrayIcon = defaults.HideTrayIcon;
HoldToHideKey = defaults.HoldToHideKey;
AgentHooksGuardEnabled = defaults.AgentHooksGuardEnabled;
AgentHooksGuardIntervalMs = defaults.AgentHooksGuardIntervalMs;
AgentKeepIslandVisible = defaults.AgentKeepIslandVisible;
}
}
public sealed class MonitorFeatureSettings
{
public bool HoverCardEnabled { get; set; } = true;
public int DisplayDurationMs { get; set; } = 3000;
public bool EmphasizeTransitions { get; set; } = true;
}