Skip to content

Commit eadea84

Browse files
authored
Merge pull request #663 from emoacht/develop
Develop
2 parents 6d64cef + df66d5c commit eadea84

File tree

8 files changed

+62
-43
lines changed

8 files changed

+62
-43
lines changed

Source/Installer/Product.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
22
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui"
33
xmlns:netfx="http://wixtoolset.org/schemas/v4/wxs/netfx">
4-
<Package Name="Monitorian" Manufacturer="emoacht" Version="4.9.2"
4+
<Package Name="Monitorian" Manufacturer="emoacht" Version="4.9.4"
55
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
66
<SummaryInformation Description="Installer for Monitorian"/>
77

Source/Monitorian.Core/AppControllerCore.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public class AppControllerCore
4141
private readonly BrightnessWatcher _brightnessWatcher;
4242
private readonly BrightnessConnector _brightnessConnector;
4343

44-
protected OperationRecorder Recorder { get; } = new();
45-
4644
public AppControllerCore(AppKeeper keeper, SettingsCore settings)
4745
{
4846
this._keeper = keeper ?? throw new ArgumentNullException(nameof(keeper));
@@ -95,14 +93,20 @@ public virtual async Task InitiateAsync()
9593

9694
_sessionWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(SessionWatcher), e));
9795
_powerWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(PowerWatcher), e));
98-
_displaySettingsWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(DisplaySettingsWatcher), e));
96+
_displaySettingsWatcher.Subscribe((e) =>
97+
{
98+
if (!_powerWatcher.IsDisplayOff)
99+
{
100+
OnMonitorsChangeInferred(nameof(DisplaySettingsWatcher), e);
101+
}
102+
});
99103

100104
_displayInformationWatcher.Subscribe(async (deviceInstanceId, message) =>
101105
{
102106
if (!_sessionWatcher.IsLocked)
103107
{
104108
await UpdateMessageAsync(deviceInstanceId, message);
105-
await Recorder.RecordAsync(message);
109+
await OperationRecorder.RecordAsync(message);
106110
}
107111
});
108112

@@ -113,7 +117,7 @@ public virtual async Task InitiateAsync()
113117
if (!_sessionWatcher.IsLocked)
114118
Update(instanceName, brightness);
115119
},
116-
async (message) => await Recorder.RecordAsync(message));
120+
async (message) => await OperationRecorder.RecordAsync(message));
117121

118122
if (_brightnessConnector.IsEnabled)
119123
{
@@ -122,7 +126,7 @@ await _brightnessConnector.InitiateAsync((brightness) =>
122126
if (!_sessionWatcher.IsLocked)
123127
Update(null, brightness);
124128
},
125-
async (message) => await Recorder.RecordAsync(message),
129+
async (message) => await OperationRecorder.RecordAsync(message),
126130
() => _current.Dispatcher.Invoke(() => _current.MainWindow.Visibility is Visibility.Visible));
127131
}
128132
}
@@ -207,7 +211,7 @@ protected virtual async void OnSettingsInitiated()
207211
WindowPainter.AttachAccentColors();
208212

209213
if (Settings.MakesOperationLog)
210-
await Recorder.EnableAsync("Initiated");
214+
await OperationRecorder.EnableAsync("Initiated");
211215
}
212216

213217
protected virtual async void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
@@ -242,9 +246,9 @@ protected virtual async void OnSettingsChanged(object sender, PropertyChangedEve
242246

243247
case nameof(Settings.MakesOperationLog):
244248
if (Settings.MakesOperationLog)
245-
await Recorder.EnableAsync("Enabled");
249+
await OperationRecorder.EnableAsync("Enabled");
246250
else
247-
Recorder.Disable();
251+
OperationRecorder.Disable();
248252

249253
break;
250254
}
@@ -254,7 +258,7 @@ protected virtual async void OnSettingsChanged(object sender, PropertyChangedEve
254258

255259
protected virtual async void OnMonitorsChangeInferred(object sender, ICountEventArgs e = null)
256260
{
257-
await Recorder.RecordAsync($"{nameof(OnMonitorsChangeInferred)} ({sender}{e?.Description})");
261+
await OperationRecorder.RecordAsync($"{nameof(OnMonitorsChangeInferred)} ({sender}{e?.Description})");
258262

259263
await ProceedScanAsync(e);
260264
}
@@ -269,7 +273,7 @@ protected virtual async Task ProceedScanAsync(ICountEventArgs e)
269273

270274
protected internal virtual async void OnMonitorAccessFailed(AccessResult result)
271275
{
272-
await Recorder.RecordAsync($"{nameof(OnMonitorAccessFailed)}" + Environment.NewLine
276+
await OperationRecorder.RecordAsync($"{nameof(OnMonitorAccessFailed)}" + Environment.NewLine
273277
+ $"Status: {result.Status}" + Environment.NewLine
274278
+ $"Message: {result.Message}");
275279
}
@@ -278,7 +282,7 @@ protected internal virtual async void OnMonitorsChangeFound()
278282
{
279283
if (Monitors.Any())
280284
{
281-
await Recorder.RecordAsync($"{nameof(OnMonitorsChangeFound)}");
285+
await OperationRecorder.RecordAsync($"{nameof(OnMonitorsChangeFound)}");
282286

283287
_displaySettingsWatcher.RaiseDisplaySettingsChanged();
284288
}
@@ -309,7 +313,7 @@ protected virtual async Task ScanAsync(TimeSpan interval)
309313

310314
var intervalTask = (interval > TimeSpan.Zero) ? Task.Delay(interval) : Task.CompletedTask;
311315

312-
Recorder.StartGroupRecord($"{nameof(ScanAsync)} [{DateTime.Now}]");
316+
OperationRecorder.StartGroupRecord($"{nameof(ScanAsync)} [{DateTime.Now}]");
313317

314318
await Task.Run(async () =>
315319
{
@@ -318,7 +322,7 @@ await Task.Run(async () =>
318322

319323
foreach (var item in await MonitorManager.EnumerateMonitorsAsync(TimeSpan.FromSeconds(12)))
320324
{
321-
Recorder.AddGroupRecordItem("Items", item.ToString());
325+
OperationRecorder.AddGroupRecordItem("Items", item.ToString());
322326

323327
var oldMonitorExists = false;
324328

@@ -390,8 +394,8 @@ await Task.Run(async () =>
390394
foreach (var m in Monitors.Where(x => !x.IsControllable))
391395
m.IsTarget = !controllableMonitorExists;
392396

393-
Recorder.AddGroupRecordItems(nameof(Monitors), Monitors.Select(x => x.ToString()));
394-
await Recorder.EndGroupRecordAsync();
397+
OperationRecorder.AddGroupRecordItems(nameof(Monitors), Monitors.Select(x => x.ToString()));
398+
await OperationRecorder.EndGroupRecordAsync();
395399

396400
await intervalTask;
397401
}

Source/Monitorian.Core/Models/OperationRecorder.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88

99
namespace Monitorian.Core.Models;
1010

11-
public class OperationRecorder
11+
public static class OperationRecorder
1212
{
13-
public bool IsEnabled { get; private set; }
13+
public static bool IsEnabled { get; private set; }
1414

15-
public async Task EnableAsync(string message)
15+
public static async Task EnableAsync(string message)
1616
{
1717
await Logger.PrepareOperationAsync();
1818
await Logger.RecordOperationAsync(message);
1919

2020
IsEnabled = true;
2121
}
2222

23-
public void Disable()
23+
public static void Disable()
2424
{
2525
IsEnabled = false;
2626

2727
FinishLineRecord();
2828
FinishGroupRecord();
2929
}
3030

31-
public Task RecordAsync(string content)
31+
public static Task RecordAsync(string content)
3232
{
3333
return IsEnabled
3434
? Logger.RecordOperationAsync(content)
@@ -37,30 +37,30 @@ public Task RecordAsync(string content)
3737

3838
#region Line
3939

40-
private readonly Lazy<Throttle<string>> _record = new(() => new(
40+
private static readonly Lazy<Throttle<string>> _record = new(() => new(
4141
TimeSpan.FromSeconds(1),
4242
async queue => await Logger.RecordOperationAsync(string.Join(Environment.NewLine, queue))));
4343

44-
private readonly Lazy<ConcurrentDictionary<string, List<string>>> _actionLines = new(() => new());
44+
private static readonly Lazy<ConcurrentDictionary<string, List<string>>> _actionLines = new(() => new());
4545

4646
/// <summary>
4747
/// Starts a record consisting of lines (concurrent).
4848
/// </summary>
4949
/// <param name="key">Unique key</param>
5050
/// <param name="actionName">Action name</param>
51-
public void StartLineRecord(string key, string actionName)
51+
public static void StartLineRecord(string key, string actionName)
5252
{
5353
if (IsEnabled)
5454
_actionLines.Value[key] = new List<string>([actionName]);
5555
}
5656

57-
public void AddLineRecord(string key, string lineString)
57+
public static void AddLineRecord(string key, string lineString)
5858
{
5959
if (IsEnabled && _actionLines.Value.TryGetValue(key, out var lines))
6060
lines.Add(lineString);
6161
}
6262

63-
public async Task EndLineRecordAsync(string key)
63+
public static async Task EndLineRecordAsync(string key)
6464
{
6565
if (IsEnabled && _actionLines.Value.TryGetValue(key, out var lines))
6666
{
@@ -69,7 +69,7 @@ public async Task EndLineRecordAsync(string key)
6969
}
7070
}
7171

72-
private void FinishLineRecord()
72+
private static void FinishLineRecord()
7373
{
7474
_actionLines.Value.Clear();
7575
}
@@ -78,32 +78,32 @@ private void FinishLineRecord()
7878

7979
#region Group
8080

81-
private string _actionName;
82-
private readonly Lazy<List<(string groupName, StringWrapper item)>> _actionGroups = new(() => new());
81+
private static string _actionName;
82+
private static readonly Lazy<List<(string groupName, StringWrapper item)>> _actionGroups = new(() => new());
8383

8484
/// <summary>
8585
/// Starts a record consisting of groups of lines (non-concurrent).
8686
/// </summary>
8787
/// <param name="actionName">Action name</param>
88-
public void StartGroupRecord(string actionName)
88+
public static void StartGroupRecord(string actionName)
8989
{
9090
if (IsEnabled)
91-
this._actionName = actionName;
91+
_actionName = actionName;
9292
}
9393

94-
public void AddGroupRecordItem(string groupName, string itemString)
94+
public static void AddGroupRecordItem(string groupName, string itemString)
9595
{
9696
if (IsEnabled)
9797
_actionGroups.Value.Add((groupName, new StringWrapper(itemString)));
9898
}
9999

100-
public void AddGroupRecordItems(string groupName, IEnumerable<string> itemStrings)
100+
public static void AddGroupRecordItems(string groupName, IEnumerable<string> itemStrings)
101101
{
102102
if (IsEnabled)
103103
_actionGroups.Value.AddRange(itemStrings.Select(x => (groupName, new StringWrapper(x))));
104104
}
105105

106-
public async Task EndGroupRecordAsync()
106+
public static async Task EndGroupRecordAsync()
107107
{
108108
if (IsEnabled)
109109
{
@@ -114,7 +114,7 @@ public async Task EndGroupRecordAsync()
114114
}
115115
}
116116

117-
private void FinishGroupRecord()
117+
private static void FinishGroupRecord()
118118
{
119119
_actionName = null;
120120
_actionGroups.Value.Clear();

Source/Monitorian.Core/Models/Watcher/PowerWatcher.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,22 @@ private void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
7777
}
7878
}
7979

80-
private void OnDisplayStateChanged(DisplayStates state)
80+
public bool IsDisplayOff { get; private set; }
81+
82+
private async void OnDisplayStateChanged(DisplayStates state)
8183
{
84+
await OperationRecorder.RecordAsync($"Display {state}");
85+
8286
switch (state)
8387
{
8488
case DisplayStates.On:
8589
case DisplayStates.Dimmed:
90+
IsDisplayOff = false;
8691
RaiseDisplayStateChanged(state, 0);
8792
_stateWatcher.TimerStart(state);
8893
break;
8994
case DisplayStates.Off:
95+
IsDisplayOff = true;
9096
_stateWatcher.TimerStop();
9197
RaiseDisplayStateChanged(state, 0);
9298
break;

Source/Monitorian.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("4.9.2.0")]
37-
[assembly: AssemblyFileVersion("4.9.2.0")]
36+
[assembly: AssemblyVersion("4.9.4.0")]
37+
[assembly: AssemblyFileVersion("4.9.4.0")]
3838
[assembly: NeutralResourcesLanguage("en-US")]
3939

4040
// For unit test

Source/Monitorian.Core/Views/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@
673673

674674
<!-- Brightness -->
675675
<controls:CompoundSlider Grid.Column="1"
676-
Margin="12,0,4,0" VerticalAlignment="Center"
676+
Margin="12,0,4,0" VerticalAlignment="Stretch"
677677
Style="{StaticResource MainSliderHorizontal}"
678678
Minimum="0" Maximum="100"
679679
SmallChange="1"
@@ -721,7 +721,7 @@
721721
<!-- Contrast -->
722722
<controls:EnhancedSlider Grid.Column="4"
723723
x:Name="ContrastSlider"
724-
Width="100" Margin="8,0,4,0" VerticalAlignment="Center"
724+
Width="100" Margin="8,0,4,0" VerticalAlignment="Stretch"
725725
Style="{StaticResource SubSliderHorizontal}"
726726
Minimum="0" Maximum="100"
727727
SmallChange="1"

Source/Monitorian/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("4.9.2.0")]
55-
[assembly: AssemblyFileVersion("4.9.2.0")]
54+
[assembly: AssemblyVersion("4.9.4.0")]
55+
[assembly: AssemblyFileVersion("4.9.4.0")]
5656
[assembly: Guid("a4cc5362-9b08-465b-ad64-5cfabc72a4c7")]
5757
[assembly: NeutralResourcesLanguage("en-US")]

docs/TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ Probe.log & Operation.log
1717
```
1818
Could you read [Contributing Guidelines](https://github.com/emoacht/Monitorian/blob/9aeb4238af22c60ccc03051f144edd1a5ee9acdb/CONTRIBUTING.md) and post __probe.log__ and __operation.log__? How to produce these logs is explained in [Reporting](https://github.com/emoacht/Monitorian#reporting) section of readme.
1919
```
20+
21+
Details
22+
23+
```
24+
<details>
25+
<summary>caption</summary>
26+
27+
</details>
28+
```

0 commit comments

Comments
 (0)