Skip to content

Commit 8d2fb10

Browse files
Merge pull request #391 from raisingthefloor/christopher/fix-version-numbers
Downgrade CsWinRT (vtable bug); update Windows min build for new dark mode code
2 parents 1b23030 + 4e9b2d6 commit 8d2fb10

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed

Morphic.Client/Bar/UI/BarControls/MultiButtonBarControl.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ public async Task SetControlAsync(ButtonBase control)
335335
// error
336336
//break;
337337
}
338-
else if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v24H2) == true)
338+
else if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v23H2, 4037 /* not required in build 22631.3447, but required in build 22631.4037 */) == true)
339339
{
340-
// Windows 11 v24H2+
340+
// Windows 11 v23H2 revision 4037+, Windows 11 v24H2+
341341

342342
// capture changes to system dark theme (triggering our this.InverseSettingOnChanged event handler)
343343
Setting systemThemeSetting = App.Current.MorphicSession.Solutions.GetSetting(Settings.SolutionsRegistry.SettingId.SystemTheme);

Morphic.Client/TextToSpeechHelper.cs

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Morphic.Core;
22
using System;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Media;
56
using System.Threading.Tasks;
6-
using Windows.Media.SpeechSynthesis;
77

88
namespace Morphic.Client
99
{
@@ -28,15 +28,45 @@ public async Task<MorphicResult<MorphicUnit, MorphicUnit>> Say(string text)
2828
{
2929
Stop();
3030

31-
using var synth = new SpeechSynthesizer();
32-
using var stream = await synth.SynthesizeTextToStreamAsync(text);
31+
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
32+
try
33+
{
34+
Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream;
35+
try
36+
{
37+
stream = await synth.SynthesizeTextToStreamAsync(text);
38+
}
39+
catch (Exception ex)
40+
{
41+
Debug.Assert(false, "Could not create speech synthesizer stream; ex: " + ex.Message);
42+
return MorphicResult.ErrorResult();
43+
}
44+
//
45+
try
46+
{
47+
// NOTE: we cannot use the speech synthesizer directly using SpeakAsync/SpeakAsyncCancelAll because Windows.Speech.SpeechSynthesis and these corresponding methods are not supported in .NET 5 (i.e. only in .NET Framework)
48+
_speechPlayer.Stream = stream.AsStream();
3349

34-
// NOTE: we cannot use the speech synthesizer directly using SpeakAsync/SpeakAsyncCancelAll because Windows.Speech.SpeechSynthesis and these corresponding methods are not supported in .NET 5 (i.e. only in .NET Framework)
35-
_speechPlayer.Stream = stream.AsStream();
36-
37-
// NOTE: Play() loads and plays the sound in a new thread asynchronously; we could await on LoadAsync and then call Play, but that could create a contention if
38-
// Stop() was called before the LoadAsync callback completed and therefore before Play() got called
39-
_speechPlayer.Play();
50+
// NOTE: Play() loads and plays the sound in a new thread asynchronously; we could await on LoadAsync and then call Play, but that could create a contention if
51+
// Stop() was called before the LoadAsync callback completed and therefore before Play() got called
52+
_speechPlayer.Play();
53+
}
54+
catch (Exception ex)
55+
{
56+
Debug.Assert(false, "Could not capture/play text stream; ex: " + ex.Message);
57+
return MorphicResult.ErrorResult();
58+
}
59+
finally
60+
{
61+
// NOTE: this 'always manually dispose' pattern may or may not be required; this is being kept based on the original design of this class.
62+
stream.Dispose();
63+
}
64+
}
65+
finally
66+
{
67+
// NOTE: this 'always manually dispose' pattern may or may not be required; this is being kept based on the original design of this class.
68+
synth.Dispose();
69+
}
4070

4171
return MorphicResult.OkResult();
4272
}

Morphic.WindowsNative/Morphic.WindowsNative.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
2626
<PrivateAssets>all</PrivateAssets>
2727
</PackageReference>
28-
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.1" />
28+
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.8" />
2929
<PackageReference Include="Morphic.Core" Version="1.3.1" />
3030
<PackageReference Include="PInvoke.AdvApi32" Version="0.7.124" />
3131
<PackageReference Include="PInvoke.Kernel32" Version="0.7.124" />

Morphic.WindowsNative/OsVersion/OsVersion.cs

+31-4
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public static bool IsWindows11OrLater()
194194
}
195195
}
196196

197-
public static bool IsEqualOrNewerThanVersion(WindowsVersion version)
197+
public static bool IsEqualOrNewerThanVersion(WindowsVersion version, int? revision = null)
198198
{
199199
var versionBuild = OsVersion.GetBuildVersionForOsVersion(version);
200200
if (versionBuild is null)
@@ -206,15 +206,30 @@ public static bool IsEqualOrNewerThanVersion(WindowsVersion version)
206206
// for both windows 10 and windows 11, we can do straightforward build number matching
207207
if (currentVersionBuild >= versionBuild)
208208
{
209-
return true;
209+
if (currentVersionBuild == versionBuild && revision is not null)
210+
{
211+
var getUpdateBuildRevisionResult = OsVersion.GetUpdateBuildRevision();
212+
if (getUpdateBuildRevisionResult.IsError == true)
213+
{
214+
Debug.Assert(false, "Could not retrieve current OS revision");
215+
return false;
216+
}
217+
var currentVersionRevision = getUpdateBuildRevisionResult.Value!;
218+
219+
return (currentVersionRevision >= revision!.Value);
220+
}
221+
else
222+
{
223+
return true;
224+
}
210225
}
211226
else /* if (currentVersionBuild <= versionBuild) */
212227
{
213228
return false;
214229
}
215230
}
216231

217-
public static bool IsNewerThanVersion(WindowsVersion version)
232+
public static bool IsNewerThanVersion(WindowsVersion version, int? revision = null)
218233
{
219234
var versionBuild = OsVersion.GetBuildVersionForOsVersion(version);
220235
if (versionBuild is null)
@@ -224,7 +239,19 @@ public static bool IsNewerThanVersion(WindowsVersion version)
224239
var currentVersionBuild = System.Environment.OSVersion.Version.Build;
225240

226241
// for both windows 10 and windows 11, we can do straightforward build number matching
227-
if (currentVersionBuild > versionBuild)
242+
if (currentVersionBuild == versionBuild && revision is not null)
243+
{
244+
var getUpdateBuildRevisionResult = OsVersion.GetUpdateBuildRevision();
245+
if (getUpdateBuildRevisionResult.IsError == true)
246+
{
247+
Debug.Assert(false, "Could not retrieve current OS revision");
248+
return false;
249+
}
250+
var currentVersionRevision = getUpdateBuildRevisionResult.Value!;
251+
252+
return (currentVersionRevision > revision!.Value);
253+
}
254+
else if (currentVersionBuild > versionBuild)
228255
{
229256
return true;
230257
}

Morphic.WindowsNative/Theme/DarkMode.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,10 @@ public static bool TryConvertSystemThemeNameToDarkModeState(string systemTheme)
347347

348348
// get the current light theme settings for Windows (i.e. the system)
349349
bool? systemUsesLightThemeAsBool = null;
350-
if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v24H2) == true)
350+
if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v23H2, 4037 /* not required in build 22631.3447, but required in build 22631.4037 */) == true)
351351
{
352+
// Windows 11 v23H2 revision 4037+, Windows 11 v24H2+
353+
352354
var getSystemThemeResult = personalizeKey.GetValueDataOrNull<string>("SystemTheme");
353355
if (getSystemThemeResult.IsError == true)
354356
{
@@ -363,6 +365,8 @@ public static bool TryConvertSystemThemeNameToDarkModeState(string systemTheme)
363365
}
364366
else
365367
{
368+
// Windows 10 1903+
369+
366370
var getSystemUsesLightThemeResult = personalizeKey.GetValueDataOrNull<uint>("SystemUsesLightTheme");
367371
if (getSystemUsesLightThemeResult.IsError == true)
368372
{
@@ -385,9 +389,9 @@ public static async Task<MorphicResult<MorphicUnit, MorphicUnit>> SetSystemUsesD
385389
{
386390
Stopwatch stopwatch = Stopwatch.StartNew();
387391

388-
if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v24H2) == true)
392+
if (Morphic.WindowsNative.OsVersion.OsVersion.IsEqualOrNewerThanVersion(WindowsNative.OsVersion.WindowsVersion.Win11_v23H2, 4037 /* not required in build 22631.3447, but required in build 22631.4037 */) == true)
389393
{
390-
// Windows 11 24H2+
394+
// Windows 11 v23H2 revision 4037+, Windows 11 v24H2+
391395

392396
var themeName = value switch
393397
{

0 commit comments

Comments
 (0)