Skip to content

Commit ff21e81

Browse files
committed
Merge branch 'master' of https://github.com/emoacht/Monitorian
2 parents ef6b7b9 + 9aeb423 commit ff21e81

31 files changed

+1294
-1051
lines changed

Source/Installer/Product.wxs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3-
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.4.6"
3+
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.4.8"
44
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
55
<Package Id="*" InstallerVersion="500" Compressed="yes"
66
InstallScope="perMachine" InstallPrivileges="elevated"
@@ -66,11 +66,6 @@
6666
Source="$(var.Monitorian.TargetDir)" Name="$(var.Monitorian.TargetName).Core.dll" KeyPath="yes"/>
6767
</Component>
6868

69-
<Component Id="SupplementLibrary" Guid="{E2329FC3-7343-4072-AEDD-EC020397080C}">
70-
<File Id="SupplementLibrary"
71-
Source="$(var.Monitorian.TargetDir)" Name="$(var.Monitorian.TargetName).Supplement.dll" KeyPath="yes"/>
72-
</Component>
73-
7469
<Component Id="FrameLibrary" Guid="{9BAED8CA-C9C3-4ECD-8D28-289758577A8E}">
7570
<File Id="FrameLibrary"
7671
Source="$(var.Monitorian.TargetDir)" Name="ScreenFrame.dll" KeyPath="yes"/>
@@ -223,7 +218,6 @@
223218
<ComponentRef Id="MainExecutableConfig"/>
224219
<ComponentRef Id="BehaviorsLibrary"/>
225220
<ComponentRef Id="CoreLibrary"/>
226-
<ComponentRef Id="SupplementLibrary"/>
227221
<ComponentRef Id="FrameLibrary"/>
228222
<ComponentRef Id="StartupLibrary"/>
229223
<ComponentRef Id="VisualManifest"/>

Source/Monitorian.Core/AppControllerCore.cs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public class AppControllerCore
3636
public NotifyIconContainer NotifyIconContainer { get; }
3737
public WindowPainter WindowPainter { get; }
3838

39-
private readonly DisplayWatcher _displayWatcher;
4039
private readonly SessionWatcher _sessionWatcher;
4140
private readonly PowerWatcher _powerWatcher;
41+
private readonly DisplaySettingsWatcher _displaySettingsWatcher;
42+
private readonly DisplayInformationWatcher _displayInformationWatcher;
4243
private readonly BrightnessWatcher _brightnessWatcher;
4344
private readonly BrightnessConnector _brightnessConnector;
4445

@@ -57,9 +58,10 @@ public AppControllerCore(AppKeeper keeper, SettingsCore settings)
5758
NotifyIconContainer = new NotifyIconContainer();
5859
WindowPainter = new WindowPainter();
5960

60-
_displayWatcher = new DisplayWatcher();
6161
_sessionWatcher = new SessionWatcher();
6262
_powerWatcher = new PowerWatcher();
63+
_displaySettingsWatcher = new DisplaySettingsWatcher();
64+
_displayInformationWatcher = new DisplayInformationWatcher();
6365
_brightnessWatcher = new BrightnessWatcher();
6466
_brightnessConnector = new BrightnessConnector();
6567
}
@@ -90,9 +92,18 @@ public virtual async Task InitiateAsync()
9092
NotifyIconContainer.MouseLeftButtonClick += OnMainWindowShowRequestedBySelf;
9193
NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested;
9294

93-
_displayWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(DisplayWatcher), e));
9495
_sessionWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(SessionWatcher), e));
9596
_powerWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(PowerWatcher), e));
97+
_displaySettingsWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(DisplaySettingsWatcher), e));
98+
99+
_displayInformationWatcher.Subscribe(async (deviceInstanceId, message) =>
100+
{
101+
if (!_sessionWatcher.IsLocked)
102+
{
103+
await UpdateMessageAsync(deviceInstanceId, message);
104+
await Recorder.RecordAsync(message);
105+
}
106+
});
96107

97108
if (Monitors.Any(x => x.IsInternal))
98109
{
@@ -102,17 +113,17 @@ public virtual async Task InitiateAsync()
102113
Update(instanceName, brightness);
103114
},
104115
async (message) => await Recorder.RecordAsync(message));
105-
}
106116

107-
if (_brightnessConnector.CanConnect)
108-
{
109-
await _brightnessConnector.InitiateAsync((brightness) =>
117+
if (_brightnessConnector.IsEnabled)
110118
{
111-
if (!_sessionWatcher.IsLocked)
112-
Update(null, brightness);
113-
},
114-
async (message) => await Recorder.RecordAsync(message),
115-
() => _current.Dispatcher.Invoke(() => _current.MainWindow.Visibility is Visibility.Visible));
119+
await _brightnessConnector.InitiateAsync((brightness) =>
120+
{
121+
if (!_sessionWatcher.IsLocked)
122+
Update(null, brightness);
123+
},
124+
async (message) => await Recorder.RecordAsync(message),
125+
() => _current.Dispatcher.Invoke(() => _current.MainWindow.Visibility is Visibility.Visible));
126+
}
116127
}
117128

118129
await CleanAsync();
@@ -125,9 +136,10 @@ public virtual void End()
125136
NotifyIconContainer.Dispose();
126137
WindowPainter.Dispose();
127138

128-
_displayWatcher.Dispose();
129139
_sessionWatcher.Dispose();
130140
_powerWatcher.Dispose();
141+
_displaySettingsWatcher.Dispose();
142+
_displayInformationWatcher.Dispose();
131143
_brightnessWatcher.Dispose();
132144
_brightnessConnector.Dispose();
133145
}
@@ -143,7 +155,7 @@ protected async void OnMainWindowShowRequestedBySelf(object sender, EventArgs e)
143155
ShowMainWindow();
144156
await CheckUpdateAsync();
145157

146-
if (_brightnessConnector.CanConnect)
158+
if (_brightnessConnector.IsEnabled)
147159
await _brightnessConnector.ConnectAsync(true);
148160
}
149161

@@ -152,7 +164,7 @@ protected async void OnMainWindowShowRequestedByOther(object sender, EventArgs e
152164
_current.Dispatcher.Invoke(() => ShowMainWindow());
153165
await CheckUpdateAsync();
154166

155-
if (_brightnessConnector.CanConnect)
167+
if (_brightnessConnector.IsEnabled)
156168
await _brightnessConnector.ConnectAsync(true);
157169
}
158170

@@ -263,7 +275,7 @@ protected internal virtual async void OnMonitorsChangeFound()
263275
{
264276
await Recorder.RecordAsync($"{nameof(OnMonitorsChangeFound)}");
265277

266-
_displayWatcher.RaiseDisplaySettingsChanged();
278+
_displaySettingsWatcher.RaiseDisplaySettingsChanged();
267279
}
268280
}
269281

@@ -436,6 +448,16 @@ protected virtual void Update(string instanceName, int brightness)
436448
monitor?.UpdateBrightness(brightness);
437449
}
438450

451+
protected virtual async Task UpdateMessageAsync(string deviceInstanceId, string message)
452+
{
453+
var monitor = Monitors.FirstOrDefault(x => string.Equals(x.DeviceInstanceId, deviceInstanceId, StringComparison.OrdinalIgnoreCase));
454+
System.Diagnostics.Debug.WriteLine(message);
455+
if (monitor is not null)
456+
{
457+
await monitor.ShowNormalMessageAsync(message, TimeSpan.FromSeconds(30));
458+
}
459+
}
460+
439461
private void MonitorsDispose()
440462
{
441463
foreach (var m in Monitors)

Source/Monitorian.Core/AppKeeper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public static IEnumerable<string> EnumerateStandardOptions() =>
7575
MonitorManager.Options,
7676
LanguageService.Options,
7777
WindowPainter.Options,
78-
BrightnessConnector.Options
78+
BrightnessConnector.Options,
79+
DisplayInformationWatcher.Options
7980
}
8081
.SelectMany(x => x);
8182

Source/Monitorian.Core/Helper/OsVersion.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ internal static class OsVersion
4747
/// </summary>
4848
public static bool Is11OrGreater => IsEqualToOrGreaterThan(10, 0, 22000);
4949

50+
/// <summary>
51+
/// Whether OS is Windows 11 (10.0.22621) or greater
52+
/// </summary>
53+
public static bool Is11Build22621OrGreater => IsEqualToOrGreaterThan(10, 0, 22621);
54+
5055
#region Cache
5156

5257
private static readonly Dictionary<string, bool> _cache = new();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace Monitorian.Supplement
7+
namespace Monitorian.Core.Models
88
{
99
/// <summary>
1010
/// A wrapper class of <see cref="Windows.System.Launcher"/>

Source/Monitorian.Core/Models/Monitor/DdcMonitorItem.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ public DdcMonitorItem(
2727
byte monitorIndex,
2828
Rect monitorRect,
2929
SafePhysicalMonitorHandle handle,
30-
MonitorCapability capability) : base(
30+
MonitorCapability capability,
31+
Action onDisposed = null) : base(
3132
deviceInstanceId: deviceInstanceId,
3233
description: description,
3334
displayIndex: displayIndex,
3435
monitorIndex: monitorIndex,
3536
monitorRect: monitorRect,
3637
isInternal: false,
37-
isReachable: true)
38+
isReachable: true,
39+
onDisposed: onDisposed)
3840
{
3941
this._handle = handle ?? throw new ArgumentNullException(nameof(handle));
4042
this._capability = capability ?? throw new ArgumentNullException(nameof(capability));

0 commit comments

Comments
 (0)