From 448d63e15672be6cbb349ae2fe2400008cf698be Mon Sep 17 00:00:00 2001 From: rc-swag <58423624+rc-swag@users.noreply.github.com> Date: Thu, 25 Jun 2026 11:31:15 +1000 Subject: [PATCH] feat(windows): apply exception check Keyman currenlty only supports Windows 10 and 11 so the exception was low risk. If it is not available we return false as metered connections werent possilble before this the functionality will be the consistent with those windows versions. i.e. always updating in the background --- ...yman.Configuration.UI.UfrmStartInstall.pas | 2 +- .../kmshell/util/UtilNetworkConnection.pas | 42 ++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/windows/src/desktop/kmshell/main/Keyman.Configuration.UI.UfrmStartInstall.pas b/windows/src/desktop/kmshell/main/Keyman.Configuration.UI.UfrmStartInstall.pas index d30cf44c6a..78578e66c0 100644 --- a/windows/src/desktop/kmshell/main/Keyman.Configuration.UI.UfrmStartInstall.pas +++ b/windows/src/desktop/kmshell/main/Keyman.Configuration.UI.UfrmStartInstall.pas @@ -21,7 +21,7 @@ uses Vcl.Imaging.pngimage; type - // The 4 valid installation form scenarios + // The 4 valid installation form scenarios plus a None case for validation TInstallCase = ( icNone, // Not a valid case, can be used as check before calling creating form icRestartRequiredMetered, diff --git a/windows/src/desktop/kmshell/util/UtilNetworkConnection.pas b/windows/src/desktop/kmshell/util/UtilNetworkConnection.pas index ad3615f1cc..02952cafb2 100644 --- a/windows/src/desktop/kmshell/util/UtilNetworkConnection.pas +++ b/windows/src/desktop/kmshell/util/UtilNetworkConnection.pas @@ -51,18 +51,25 @@ var CostLevel: IConnectionCost; begin Result := False; - // Get the profile currently providing internet access - Profile := TNetworkInformation.GetInternetConnectionProfile; - - if Profile <> nil then - begin - CostLevel := Profile.GetConnectionCost; - Result := (CostLevel.NetworkCostType <> NetworkCostType.Unrestricted) - or CostLevel.Roaming - or CostLevel.OverDataLimit; + try + // Get the profile currently providing internet access + Profile := TNetworkInformation.GetInternetConnectionProfile; + if Profile <> nil then + begin + CostLevel := Profile.GetConnectionCost; + if CostLevel <> nil then + Result := (CostLevel.NetworkCostType <> NetworkCostType.Unrestricted) + or CostLevel.Roaming + or CostLevel.OverDataLimit; + end; + except + on E: Exception do + // If the WinRT network APIs are unavailable or throw (e.g. unusual + // Windows SKUs, containers, Network List Manager service stopped), + // treat the connection as non-metered so updates are not blocked. + Result := False; end; end; - function IsBackgroundDataRestricted: Boolean; var Profile: IConnectionProfile; @@ -70,15 +77,18 @@ var DataRestriction: IConnectionCost2; begin Result := False; - Profile := TNetworkInformation.GetInternetConnectionProfile; - if Profile <> nil then - begin - CostLevel := Profile.GetConnectionCost; - if (CostLevel <> nil) and Supports(CostLevel, IConnectionCost2, DataRestriction) then + try + Profile := TNetworkInformation.GetInternetConnectionProfile; + if Profile <> nil then begin + CostLevel := Profile.GetConnectionCost; + if (CostLevel <> nil) and Supports(CostLevel, IConnectionCost2, DataRestriction) then Result := DataRestriction.BackgroundDataUsageRestricted; - Exit; end; + except + on E: Exception do + // See IsMetered: default to not-restricted if the WinRT APIs throw. + Result := False; end; end;