Skip to content

Commit b213958

Browse files
authored
Merge pull request #737 from emoacht/develop
Develop
2 parents 54e70cb + 1f69356 commit b213958

30 files changed

+534
-208
lines changed

Source/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<LangVersion>latest</LangVersion>
3+
<LangVersion>preview</LangVersion>
44
</PropertyGroup>
55
</Project>

Source/Installer/Product.wxs

Lines changed: 8 additions & 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.13.3"
4+
<Package Name="Monitorian" Manufacturer="emoacht" Version="4.14.0"
55
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
66
<SummaryInformation Description="Installer for Monitorian"/>
77

@@ -113,6 +113,12 @@
113113
<File Id="CoreResourcesLibrary_es" Name="$(var.Monitorian.TargetName).Core.resources.dll" KeyPath="yes"/>
114114
</Component>
115115
</Directory>
116+
<Directory Id="ResourcesFolder_faIR" Name="fa-IR"
117+
FileSource="$(var.Monitorian.TargetDir)fa-IR">
118+
<Component Id="CoreResourcesLibrary_faIR" Guid="{40146807-5D83-4620-A167-544C0C85CBE7}">
119+
<File Id="CoreResourcesLibrary_faIR" Name="$(var.Monitorian.TargetName).Core.resources.dll" KeyPath="yes"/>
120+
</Component>
121+
</Directory>
116122
<Directory Id="ResourcesFolder_fr" Name="fr"
117123
FileSource="$(var.Monitorian.TargetDir)fr">
118124
<Component Id="CoreResourcesLibrary_fr" Guid="{B7502D66-6FE8-4E0F-A8D0-42AFFBE82895}">
@@ -250,6 +256,7 @@
250256
<ComponentRef Id="CoreResourcesLibrary_de"/>
251257
<ComponentRef Id="CoreResourcesLibrary_elGR"/>
252258
<ComponentRef Id="CoreResourcesLibrary_es"/>
259+
<ComponentRef Id="CoreResourcesLibrary_faIR"/>
253260
<ComponentRef Id="CoreResourcesLibrary_fr"/>
254261
<ComponentRef Id="CoreResourcesLibrary_it"/>
255262
<ComponentRef Id="CoreResourcesLibrary_jaJP"/>

Source/Monitorian.Core/AppControllerCore.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public class AppControllerCore
3131
public ObservableCollection<MonitorViewModel> Monitors { get; }
3232
protected readonly object _monitorsLock = new();
3333

34-
public NotifyIconContainer NotifyIconContainer { get; }
3534
public WindowPainter WindowPainter { get; }
35+
public NotifyIconContainer NotifyIconContainer { get; }
3636

3737
private readonly SessionWatcher _sessionWatcher;
3838
private readonly PowerWatcher _powerWatcher;
@@ -51,8 +51,8 @@ public AppControllerCore(AppKeeper keeper, SettingsCore settings)
5151
Monitors = new ObservableCollection<MonitorViewModel>();
5252
BindingOperations.EnableCollectionSynchronization(Monitors, _monitorsLock);
5353

54-
NotifyIconContainer = new NotifyIconContainer();
5554
WindowPainter = new WindowPainter();
55+
NotifyIconContainer = new NotifyIconContainer();
5656

5757
_sessionWatcher = new SessionWatcher();
5858
_powerWatcher = new PowerWatcher();
@@ -71,16 +71,21 @@ public virtual async Task InitiateAsync()
7171
OnSettingsInitiated();
7272
await OperationRecorder.RecordAsync($"Connectable by named pipes: {_keeper.StartupAgent.IsConnectable}");
7373

74+
WindowPainter.ApplyInitialTheme();
7475
NotifyIconContainer.ShowIcon(WindowPainter.GetIconPath(), ProductInfo.Title);
7576
WindowPainter.ThemeChanged += (_, _) =>
7677
{
7778
NotifyIconContainer.ShowIcon(WindowPainter.GetIconPath());
7879
};
7980

80-
_current.MainWindow = new MainWindow(this);
81+
var mainWindow = new MainWindow(this);
82+
_current.MainWindow = mainWindow;
8183

8284
if (StartupAgent.IsWindowShowExpected())
83-
_current.MainWindow.Show();
85+
{
86+
mainWindow.CursorLocation = CursorHelper.GetCursorLocation();
87+
mainWindow.Show();
88+
}
8489

8590
await ScanAsync();
8691

@@ -167,7 +172,7 @@ protected async void OnMainWindowShowRequestedBySelf(object sender, EventArgs e)
167172

168173
protected async void OnMainWindowShowRequestedByOther(object sender, EventArgs e)
169174
{
170-
_current.Dispatcher.Invoke(() => ShowMainWindow());
175+
_current.Dispatcher.Invoke(() => ShowMainWindow(true));
171176
await CheckUpdateAsync();
172177

173178
if (_brightnessConnector.IsEnabled)
@@ -179,12 +184,13 @@ protected void OnMenuWindowShowRequested(object sender, Point e)
179184
ShowMenuWindow(e);
180185
}
181186

182-
protected virtual void ShowMainWindow()
187+
protected virtual void ShowMainWindow(bool useCursorLocation = false)
183188
{
184189
var window = (MainWindow)_current.MainWindow;
185190
if (window is { CanBeShown: false } or { Visibility: Visibility.Visible, IsForeground: true })
186191
return;
187192

193+
window.CursorLocation = useCursorLocation ? CursorHelper.GetCursorLocation() : null;
188194
window.ShowForeground();
189195
window.Activate();
190196
}
@@ -497,8 +503,9 @@ protected virtual async Task UpdateMessageAsync(string deviceInstanceId, string
497503

498504
private void ReflectMouseWheel(int delta)
499505
{
500-
var monitor = Monitors.Prepend(SelectedMonitor)
501-
.FirstOrDefault(x => x.IsTarget && x.IsControllable);
506+
var monitors = Monitors.Where(x => x.IsTarget && x.IsControllable).ToArray();
507+
var monitor = monitors.FirstOrDefault(x => ReferenceEquals(x, SelectedMonitor))
508+
?? monitors.FirstOrDefault(); // Fallback
502509
if (monitor is null)
503510
return;
504511

Source/Monitorian.Core/Models/LanguageService.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,25 @@ public class LanguageService
3737
public static IReadOnlyDictionary<string, string> ResourceDictionary => _resourceDictionary.Value;
3838
private static readonly Lazy<Dictionary<string, string>> _resourceDictionary = new(() =>
3939
{
40-
if (_culture.Value is not null)
40+
var culture = _culture.Value ?? CultureInfo.CurrentUICulture;
41+
42+
// Go back up culture hierarchy.
43+
while (culture != CultureInfo.InvariantCulture)
4144
{
42-
var resourceSet = new ResourceManager(typeof(Resources)).GetResourceSet(_culture.Value, true, false);
45+
var resourceSet = new ResourceManager(typeof(Resources)).GetResourceSet(culture, true, false);
4346
if (resourceSet is not null)
4447
{
4548
return resourceSet.Cast<DictionaryEntry>()
4649
.Where(x => x.Key is string)
4750
.ToDictionary(x => (string)x.Key, x => x.Value?.ToString());
4851
}
52+
53+
culture = culture.Parent;
4954
}
5055
return new Dictionary<string, string>();
5156
});
5257

53-
public static bool IsResourceRightToLeft => (_culture.Value?.TextInfo.IsRightToLeft is true);
58+
public static bool IsResourceRightToLeft => ((_culture.Value ?? CultureInfo.CurrentUICulture).TextInfo.IsRightToLeft is true);
5459

5560
/// <summary>
5661
/// Switches default and current thread's culture.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public static async Task<DisplayItem[]> GetDisplayMonitorsAsync()
115115
{
116116
foreach (var device in devices)
117117
{
118-
if (!device.Properties.TryGetValue(deviceInstanceIdKey, out object value))
118+
// Null check is inserted because NullReferenceException is observed in this method.
119+
if ((device is null) || !device.Properties.TryGetValue(deviceInstanceIdKey, out object value))
119120
continue;
120121

121122
var deviceInstanceId = value as string;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public enum AccessStatus
3838
None = 0,
3939
Succeeded,
4040
Failed,
41-
DdcFailed,
41+
42+
DdcNotSupported,
43+
DdcDataInvalid,
44+
DdcMessageInvalid,
45+
4246
TransmissionFailed,
4347
NoLongerExist,
4448
NotSupported

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ private static bool EnsurePhysicalMonitorHandle(SafePhysicalMonitorHandle physic
666666
private static bool CheckPossibleTransientStatus(AccessStatus oldStatus, AccessStatus newStatus)
667667
{
668668
return (oldStatus is AccessStatus.None)
669-
&& (newStatus is AccessStatus.TransmissionFailed);
669+
&& (newStatus is AccessStatus.DdcMessageInvalid or
670+
AccessStatus.TransmissionFailed);
670671
}
671672

672673
#region Error
@@ -684,11 +685,11 @@ private static AccessStatus GetStatus(int errorCode)
684685
{
685686
return unchecked((uint)errorCode) switch
686687
{
687-
ERROR_GRAPHICS_DDCCI_VCP_NOT_SUPPORTED or
688-
ERROR_GRAPHICS_DDCCI_INVALID_DATA or
688+
ERROR_GRAPHICS_DDCCI_VCP_NOT_SUPPORTED => AccessStatus.DdcNotSupported,
689+
ERROR_GRAPHICS_DDCCI_INVALID_DATA => AccessStatus.DdcDataInvalid,
689690
ERROR_GRAPHICS_DDCCI_INVALID_MESSAGE_COMMAND or
690691
ERROR_GRAPHICS_DDCCI_INVALID_MESSAGE_LENGTH or
691-
ERROR_GRAPHICS_DDCCI_INVALID_MESSAGE_CHECKSUM => AccessStatus.DdcFailed,
692+
ERROR_GRAPHICS_DDCCI_INVALID_MESSAGE_CHECKSUM => AccessStatus.DdcMessageInvalid,
692693
ERROR_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA => AccessStatus.TransmissionFailed,
693694
ERROR_GRAPHICS_MONITOR_NO_LONGER_EXISTS => AccessStatus.NoLongerExist,
694695
_ => AccessStatus.Failed

Source/Monitorian.Core/Monitorian.Core.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<Compile Include="ViewModels\ScrollWindowViewModel.cs" />
120120
<Compile Include="ViewModels\ViewModelBase.cs" />
121121
<Compile Include="Views\Behaviors\FocusElementAction.cs" />
122+
<Compile Include="Views\Behaviors\FocusControlBahavior.cs" />
122123
<Compile Include="Views\Behaviors\FocusMenuBehavior.cs" />
123124
<Compile Include="Views\Behaviors\ItemBehavior.cs" />
124125
<Compile Include="Views\Behaviors\ItemSelectorBehavior.cs" />
@@ -204,6 +205,10 @@
204205
<DependentUpon>Resources.resx</DependentUpon>
205206
<SubType>Designer</SubType>
206207
</EmbeddedResource>
208+
<EmbeddedResource Include="Properties\Resources.fa-IR.resx">
209+
<DependentUpon>Resources.resx</DependentUpon>
210+
<SubType>Designer</SubType>
211+
</EmbeddedResource>
207212
<EmbeddedResource Include="Properties\Resources.fr.resx">
208213
<DependentUpon>Resources.resx</DependentUpon>
209214
<SubType>Designer</SubType>

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.13.3.0")]
37-
[assembly: AssemblyFileVersion("4.13.3.0")]
36+
[assembly: AssemblyVersion("4.14.0.0")]
37+
[assembly: AssemblyFileVersion("4.14.0.0")]
3838
[assembly: NeutralResourcesLanguage("en-US")]
3939

4040
// For unit test

0 commit comments

Comments
 (0)