Skip to content

Commit dc6f56a

Browse files
committed
fix: 完成5项核心BUG修复,提升应用稳定性
- 修复显示器选择器拒绝同步后回退索引错误 - 修复定时调度启动时Gamma前置状态未保存问题 - 修复非轻量模式下Gamma重复应用问题 - 修复轻量模式退出后UI状态未刷新问题 - 修复per-display模式下Gamma开关状态不更新问题
1 parent 601cafb commit dc6f56a

4 files changed

Lines changed: 47 additions & 11 deletions

File tree

LumiShift/BackgroundService.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ internal MonitorManager MonitorManager
6161
internal bool IsExiting => _exiting;
6262
internal bool ScheduleManualOverride => _scheduleManualOverride;
6363
private bool _lightweightMode;
64+
private bool _displayChangedInLightweight;
65+
private bool _scheduleChangedInLightweight;
6466
private Timer _lightweightGcTimer;
6567

6668
private Form1 MainForm
@@ -132,6 +134,12 @@ public BackgroundService()
132134
{
133135
_scheduleTimer.Start();
134136
ScheduleTimer_Tick(null, null);
137+
_preScheduleGammaEnabled = Settings.GammaEnabled;
138+
_preScheduleGammaRScale = Settings.GammaRScale;
139+
_preScheduleGammaGScale = Settings.GammaGScale;
140+
_preScheduleGammaBScale = Settings.GammaBScale;
141+
_preScheduleGammaValue = Settings.GammaValue;
142+
_preScheduleMasterBrightness = Settings.MasterBrightness;
135143
}
136144

137145
ApplyGammaToSystem();
@@ -833,13 +841,14 @@ internal void ScheduleTimer_Tick(object sender, EventArgs e)
833841
return;
834842
}
835843

836-
ApplyGammaToSystem();
837844
if (_lightweightMode)
838845
{
839846
_lastScheduleMode = targetMode;
847+
_scheduleChangedInLightweight = true;
840848
ApplyScheduleMonitorPresets(targetSegment);
841849
return;
842850
}
851+
843852
SettingsStore.SaveSettings(Settings);
844853
UpdateTrayMenu();
845854
_lastScheduleMode = targetMode;
@@ -1100,13 +1109,15 @@ private void HandleDisplayChange()
11001109
{
11011110
if (_monitorManager == null) return;
11021111

1103-
var removedIds = _monitorManager.RefreshMonitors();
1104-
CleanupStaleSettings(removedIds);
11051112
if (_lightweightMode)
11061113
{
1114+
_displayChangedInLightweight = true;
11071115
_trayMenuNeedsRebuild = true;
11081116
return;
11091117
}
1118+
1119+
var removedIds = _monitorManager.RefreshMonitors();
1120+
CleanupStaleSettings(removedIds);
11101121
if (!Form1IsOpen())
11111122
{
11121123
if (_trayMenuOpen)
@@ -1196,19 +1207,32 @@ public void ShowMainWindow()
11961207
if (_lightweightMode)
11971208
{
11981209
_lightweightMode = false;
1210+
var displayChanged = _displayChangedInLightweight;
1211+
_displayChangedInLightweight = false;
11991212
_lightweightGcTimer?.Stop();
12001213
_lightweightGcTimer?.Dispose();
12011214
_lightweightGcTimer = null;
12021215
_microGcTimer?.Stop();
12031216
_microGcTimer?.Dispose();
12041217
_microGcTimer = null;
12051218
if (_monitorManager != null)
1206-
_monitorManager.ExitLightweightMode();
1219+
{
1220+
if (displayChanged)
1221+
_monitorManager.RefreshMonitors();
1222+
else
1223+
_monitorManager.ExitLightweightMode();
1224+
}
12071225
if (_scheduleTimer != null)
12081226
_scheduleTimer.Interval = ScheduleTimerIntervalNormal;
12091227
if (_messageWindow == null)
12101228
_messageWindow = new MessageWindow(this);
1229+
_healthCheckTimer?.Start();
12111230
GcHelper.CollectFull();
1231+
if (_scheduleChangedInLightweight)
1232+
{
1233+
_scheduleChangedInLightweight = false;
1234+
ScheduleStateChanged?.Invoke();
1235+
}
12121236
}
12131237

12141238
MainForm = new Form1(this);
@@ -1227,13 +1251,15 @@ internal void EnterAppLightweightMode()
12271251
{
12281252
if (_lightweightMode) return;
12291253
_lightweightMode = true;
1254+
_scheduleChangedInLightweight = false;
12301255
Form1.CleanupStaticFields();
12311256
Controls.GdiCache.Clear();
12321257
GammaController.TrimCache();
12331258
_parsedSegments = null;
12341259
_parsedSegmentsHash = 0;
12351260
_messageWindow?.Dispose();
12361261
_messageWindow = null;
1262+
_healthCheckTimer?.Stop();
12371263
if (_monitorManager != null)
12381264
_monitorManager.EnterLightweightMode();
12391265
if (_scheduleTimer != null)

LumiShift/Form1.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LumiShift/Form1.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public partial class Form1 : Form
8181
private bool _isPopulatingComboBox;
8282
private bool _isUpdatingSchedule;
8383
private string _currentPresetName;
84+
private int _previousMonitorSelectedIndex;
8485
private Timer _initTimer;
8586

8687
private static Icon LoadAppIcon()
@@ -1094,7 +1095,7 @@ private void GammaColorTempSlider_ValueChanged(object sender, EventArgs e)
10941095

10951096
UpdateGammaLabels();
10961097
UpdateColorTempLabel();
1097-
_gammaCheckBox.Checked = true;
1098+
SyncSlidersToSelectedMonitor();
10981099

10991100
string current = GetCurrentPresetName();
11001101
_currentPresetName = current;
@@ -1332,6 +1333,9 @@ private void MonitorSelectorComboBox_SelectedIndexChanged(object sender, EventAr
13321333
{
13331334
if (_isUpdatingGammaSliders) return;
13341335

1336+
int prevIndex = _previousMonitorSelectedIndex;
1337+
_previousMonitorSelectedIndex = _monitorSelectorComboBox.SelectedIndex;
1338+
13351339
if (IsGlobalMonitorSelected() && Settings.GammaPerDisplay.Count > 0)
13361340
{
13371341
bool hasManual = Settings.GammaPerDisplay.Any(kvp => kvp.Value.Source == "manual");
@@ -1346,7 +1350,7 @@ private void MonitorSelectorComboBox_SelectedIndexChanged(object sender, EventAr
13461350
if (MessageBox.Show(msg, "同步确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
13471351
{
13481352
_isUpdatingGammaSliders = true;
1349-
_monitorSelectorComboBox.SelectedIndex = 1;
1353+
_monitorSelectorComboBox.SelectedIndex = prevIndex;
13501354
_isUpdatingGammaSliders = false;
13511355
return;
13521356
}
@@ -1506,8 +1510,11 @@ protected override void OnFormClosing(FormClosingEventArgs e)
15061510
_bgService.OnFormClosing(this);
15071511
e.Cancel = true;
15081512
Hide();
1509-
Dispose();
1510-
_bgService.EnterAppLightweightMode();
1513+
BeginInvoke(new Action(() =>
1514+
{
1515+
_bgService.EnterAppLightweightMode();
1516+
if (!IsDisposed) Dispose();
1517+
}));
15111518
return;
15121519
}
15131520
_formDisposed = true;

LumiShift/Infrastructure/MonitorManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,10 @@ public void EnterLightweightMode()
714714
catch { }
715715
}
716716
_allControllers.Clear();
717-
_monitors.Clear();
717+
foreach (var monitor in _monitors)
718+
{
719+
monitor.Controller = null;
720+
}
718721
}
719722

720723
public void ExitLightweightMode()

0 commit comments

Comments
 (0)