Skip to content

Commit

Permalink
Merge pull request #390 from raisingthefloor/christopher/win11-24h2
Browse files Browse the repository at this point in the history
Windows 11 v24H2 updates: revised system theme setting; update nuget refs
  • Loading branch information
christopher-rtf authored Aug 15, 2024
2 parents b501f84 + 41c09c3 commit 1b23030
Show file tree
Hide file tree
Showing 18 changed files with 941 additions and 724 deletions.
1 change: 1 addition & 0 deletions Morphic.Client/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ private void ConfigureLogging(ILoggingBuilder logging)
WindowsVersion.Win11_v21H2,
WindowsVersion.Win11_v22H2,
WindowsVersion.Win11_v23H2,
WindowsVersion.Win11_v24H2,
WindowsVersion.Win11_vFuture
};
private static bool IsOsCompatibleWithMorphic()
Expand Down
56 changes: 41 additions & 15 deletions Morphic.Client/Bar/Data/Actions/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,24 +1122,40 @@ internal async static Task<MorphicResult<bool, MorphicUnit>> GetDarkModeStateAsy
// Windows 10 v1903+

// get system dark/light theme
Setting systemThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeSystem);
var getSystemThemeValueResult = await systemThemeSetting.GetValueAsync();
if (getSystemThemeValueResult.IsError == true)
//
//Setting systemThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeSystem);
//var getSystemThemeValueResult = await systemThemeSetting.GetValueAsync();
//if (getSystemThemeValueResult.IsError == true)
//{
// return MorphicResult.ErrorResult();
//}
//var lightThemeSystemAsObject = getSystemThemeValueResult.Value!;
//var lightThemeSystemAsBool = (bool)lightThemeSystemAsObject;
//
var getSystemUsesLightThemeSettingResult = Morphic.WindowsNative.Theme.LightTheme.GetSystemUsesLightThemeSetting();
if (getSystemUsesLightThemeSettingResult.IsError == true)
{
return MorphicResult.ErrorResult();
}
var lightThemeSystemAsObject = getSystemThemeValueResult.Value!;
var lightThemeSystemAsBool = (bool)lightThemeSystemAsObject;
var lightThemeSystemAsBool = getSystemUsesLightThemeSettingResult.Value!;

// set apps dark/light theme
Setting appsThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeApps);
var getAppsThemeValueResult = await appsThemeSetting.GetValueAsync();
if (getAppsThemeValueResult.IsError == true)
// get apps dark/light theme
//
//Setting appsThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeApps);
//var getAppsThemeValueResult = await appsThemeSetting.GetValueAsync();
//if (getAppsThemeValueResult.IsError == true)
//{
// return MorphicResult.ErrorResult();
//}
//var lightThemeAppsAsObject = getAppsThemeValueResult.Value!;
//var lightThemeAppsAsBool = (bool)lightThemeAppsAsObject;
//
var getAppsUseLightThemeSettingResult = Morphic.WindowsNative.Theme.LightTheme.GetAppsUseLightThemeSetting();
if (getAppsUseLightThemeSettingResult.IsError == true)
{
return MorphicResult.ErrorResult();
}
var lightThemeAppsAsObject = getAppsThemeValueResult.Value!;
var lightThemeAppsAsBool = (bool)lightThemeSystemAsObject;
var lightThemeAppsAsBool = getAppsUseLightThemeSettingResult.Value!;

// if either apps or system theme is set to "not light", then return true
var darkModeIsEnabled = ((lightThemeSystemAsBool == false) || (lightThemeAppsAsBool == false));
Expand Down Expand Up @@ -1174,12 +1190,22 @@ internal async static Task<MorphicResult<MorphicUnit, MorphicUnit>> SetDarkModeS
*/

// set system dark/light theme
Setting systemThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeSystem);
await systemThemeSetting.SetValueAsync(!state);
//
// implementation option 1: use SystemSettings
_ = await Morphic.WindowsNative.Theme.DarkMode.SetSystemUsesDarkModeAsync(state);
//
// implementation option 2: use registry setting (NOTE: may require follow-up theme change notification broadcast message)
//Setting systemThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeSystem);
//_ = await systemThemeSetting.SetValueAsync(!state);

// set apps dark/light theme
Setting appsThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeApps);
await appsThemeSetting.SetValueAsync(!state);
//
// implementation option 1: use SystemSettings
_ = await Morphic.WindowsNative.Theme.DarkMode.SetAppsUseDarkModeAsync(state);
//
// implementation option 2: use registry setting (NOTE: may require follow-up theme change notification broadcast message)
//Setting appsThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(SettingId.LightThemeApps);
//_ = await appsThemeSetting.SetValueAsync(!state);
}

return MorphicResult.OkResult();
Expand Down
35 changes: 32 additions & 3 deletions Morphic.Client/Bar/UI/BarControls/MultiButtonBarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ public async Task SetControlAsync(ButtonBase control)
switch (internalAction.FunctionName)
{
case "darkMode":
bool systemThemeIsLightTheme;

var getDarkModeStateResult = await Morphic.Client.Bar.Data.Actions.Functions.GetDarkModeStateAsync();
if (getDarkModeStateResult.IsError == true)
{
Expand All @@ -337,6 +335,22 @@ public async Task SetControlAsync(ButtonBase control)
// error
//break;
}
else if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v24H2) == true)
{
// Windows 11 v24H2+

// capture changes to system dark theme (triggering our this.InverseSettingOnChanged event handler)
Setting systemThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(Settings.SolutionsRegistry.SettingId.SystemTheme);
systemThemeSetting.Changed += this.SystemThemeChanged;
//
this.Control.Unloaded += (sender, args) => systemThemeSetting.Changed -= this.SystemThemeChanged;

// capture changes to apps dark theme (triggering our this.InverseSettingOnChanged event handler)
Setting appsThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(Settings.SolutionsRegistry.SettingId.LightThemeApps);
appsThemeSetting.Changed += this.InverseSettingOnChanged;
//
this.Control.Unloaded += (sender, args) => appsThemeSetting.Changed -= this.InverseSettingOnChanged;
}
else
{
// Windows 10 v1903+
Expand Down Expand Up @@ -404,21 +418,36 @@ public async Task SetControlAsync(ButtonBase control)
}
}

// OBSERVATION: with all of the setting/inverseSetting/systemTheme change events, we are not dealing with the dual selector nature of dark mode settings (i.e. we should not be toggling the button if only one of the two elements changes; we should instead be re-querying the dark mode state to update the button)
private void SettingOnChanged(object? sender, SettingEventArgs e)
{
if (this.Control is ToggleButton button)
{
button.IsChecked = e.NewValue as bool? ?? false;
}
}

//
private void InverseSettingOnChanged(object? sender, SettingEventArgs e)
{
if (this.Control is ToggleButton button)
{
button.IsChecked = !(e.NewValue as bool? ?? false);
}
}
//
private void SystemThemeChanged(object? sender, SettingEventArgs e)
{
if (this.Control is ToggleButton button)
{
bool? systemDarkModeEnabled = false;
if (e.NewValue is not null)
{
var systemTheme = (string)e.NewValue!;
systemDarkModeEnabled = Morphic.WindowsNative.Theme.DarkMode.TryConvertSystemThemeNameToDarkModeState(systemTheme);
}
button.IsChecked = systemDarkModeEnabled;
}
}

private void MasterMuteStateOnChanged(object? sender, Morphic.WindowsNative.Audio.AudioEndpoint.MasterMuteStateChangedEventArgs e)
{
Expand Down
2 changes: 2 additions & 0 deletions Morphic.Client/MainMenu/MorphicMainMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private async void WindowsSettingsAllAccessibilityOptionsClicked(object sender,
case WindowsVersion.Win11_v21H2:
case WindowsVersion.Win11_v22H2:
case WindowsVersion.Win11_v23H2:
case WindowsVersion.Win11_v24H2:
case WindowsVersion.Win11_vFuture:
// Windows 11 21H2 (and assumed for the future)
settingsUrlAsPath = "ms-settings:easeofaccess";
Expand Down Expand Up @@ -241,6 +242,7 @@ private async void WindowsSettingsPointerSizeClicked(object sender, RoutedEventA
case WindowsVersion.Win11_v21H2:
case WindowsVersion.Win11_v22H2:
case WindowsVersion.Win11_v23H2:
case WindowsVersion.Win11_v24H2:
case WindowsVersion.Win11_vFuture:
// Windows 11 21H2 (and assumed for the future)
settingsUrlAsPath = "ms-settings:easeofaccess-mousepointer";
Expand Down
16 changes: 8 additions & 8 deletions Morphic.Client/Morphic.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@

<ItemGroup>
<PackageReference Include="AToD.Deployment.MSI" Version="0.9.0" />
<PackageReference Include="Autoupdater.NET.Official" Version="1.8.4" />
<PackageReference Include="Autoupdater.NET.Official" Version="1.9.2" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Morphic.Core" Version="1.3.1" />
<PackageReference Include="Morphic.OAuth.Client" Version="0.3.0" />
<PackageReference Include="Morphic.OAuth.Core" Version="1.3.0" />
Expand Down
10 changes: 10 additions & 0 deletions Morphic.Client/solutions.json5
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
}
]
},
"com.microsoft.windows.systemTheme": {
settings: [
{
type: "systemSettings",
settings: {
value: "SystemSettings_Personalize_Color_SystemTheme:string",
}
}
]
},
"com.texthelp.readandwrite": {
settings: [
{
Expand Down
2 changes: 1 addition & 1 deletion Morphic.Controls/Morphic.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Morphic.Core" Version="1.3.1" />
Expand Down
2 changes: 1 addition & 1 deletion Morphic.Core.Legacy/Morphic.Core.Legacy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Morphic.Core" Version="1.3.1" />
</ItemGroup>

Expand Down
9 changes: 6 additions & 3 deletions Morphic.Core.Tests/Morphic.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions Morphic.ManualTester/Morphic.ManualTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EO.WebBrowser" Version="20.1.45" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="EO.WebBrowser" Version="24.1.93" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Morphic.Service/Morphic.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 6 additions & 3 deletions Morphic.Settings.Tests/Morphic.Settings.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

<ItemGroup>
<PackageReference Include="DotNetWindowsRegsitry" Version="0.1.0-alpha1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions Morphic.Settings/Morphic.Settings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

<ItemGroup>
<PackageReference Include="DotNetWindowsRegsitry" Version="0.1.0-alpha1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Morphic.Core" Version="1.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Morphic.Settings/SolutionsRegistry/SettingId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ public class SettingId
public static readonly SettingId NarratorEnabled = new SettingId("com.microsoft.windows.narrator", "enabled");
public static readonly SettingId NightModeEnabled = new SettingId("com.microsoft.windows.nightMode", "enabled");
public static readonly SettingId LightThemeApps = new SettingId("com.microsoft.windows.lightTheme", "apps");
// NOTE: LightThemeSystem is deprecated as of Windows 11 24H2
public static readonly SettingId LightThemeSystem = new SettingId("com.microsoft.windows.lightTheme", "system");
//
// Windows 11 24H2+
// NOTE: SystemTheme deprecates LightThemeSystem
public static readonly SettingId SystemTheme = new SettingId("com.microsoft.windows.systemTheme", "value");

public string Solution { get; }
public string Setting { get; }
Expand Down
4 changes: 2 additions & 2 deletions Morphic.WindowsNative/Morphic.WindowsNative.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.1" />
<PackageReference Include="Morphic.Core" Version="1.3.1" />
<PackageReference Include="PInvoke.AdvApi32" Version="0.7.124" />
<PackageReference Include="PInvoke.Kernel32" Version="0.7.124" />
Expand Down
8 changes: 7 additions & 1 deletion Morphic.WindowsNative/OsVersion/OsVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum WindowsVersion
Win11_v21H2,
Win11_v22H2,
Win11_v23H2,
Win11_v24H2,
Win11_vFuture // any future release of Windows 11 we're not yet aware of
}

Expand All @@ -56,9 +57,10 @@ public struct OsVersion
private const int WIN11_21H2_BUILD = 22000;
private const int WIN11_22H2_BUILD = 22621;
private const int WIN11_23H2_BUILD = 22631;
private const int WIN11_24H2_BUILD = 26100;
private const int EARLIEST_KNOWN_WIN11_BUILD = 22000 /* WIN11_21H2_BUILD */;
private const int EARLIEST_SUPPORTED_WIN11_BUILD = WIN11_21H2_BUILD;
private const int LATEST_KNOWN_WIN11_BUILD = WIN11_23H2_BUILD;
private const int LATEST_KNOWN_WIN11_BUILD = WIN11_24H2_BUILD;

// NOTE: this function will return null for versions of Windows which are not recognized (generally either old beta builds or versions which are old and which we do not support)
public static WindowsVersion? GetWindowsVersion()
Expand Down Expand Up @@ -86,6 +88,8 @@ public struct OsVersion
return WindowsVersion.Win11_v22H2;
case WIN11_23H2_BUILD:
return WindowsVersion.Win11_v23H2;
case WIN11_24H2_BUILD:
return WindowsVersion.Win11_v24H2;
default:
// NOTE: as Microsoft is shipping both Windows 10 and Windows 11 as "10.0.###.###" releases, we may need to add some nuance to this code in the future (for 10 vs 11)
if (version.Build > LATEST_KNOWN_WIN10_BUILD && version.Build < EARLIEST_KNOWN_WIN11_BUILD)
Expand Down Expand Up @@ -180,6 +184,8 @@ public static bool IsWindows11OrLater()
return WIN11_22H2_BUILD;
case WindowsVersion.Win11_v23H2:
return WIN11_23H2_BUILD;
case WindowsVersion.Win11_v24H2:
return WIN11_24H2_BUILD;
case WindowsVersion.Win11_vFuture:
return null;
default:
Expand Down
Loading

0 comments on commit 1b23030

Please sign in to comment.