feat(windows): apply exception check
Some checks failed
Keyman Build Summary / Summarize build status checks (push) Has been cancelled

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
This commit is contained in:
rc-swag 2026-06-25 11:31:15 +10:00
parent 85da9dc03c
commit 448d63e156
2 changed files with 27 additions and 17 deletions

View file

@ -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,

View file

@ -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;