-
-
Notifications
You must be signed in to change notification settings - Fork 141
feat(windows): honour Windows "metered connection" flag for downloading updates #16099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
a9933ab
cc8b4d2
94756fd
e92f01a
293f8ec
5e26d5d
3974f03
85da9dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,7 @@ implementation | |
| utilexecute, | ||
| utilkmshell, | ||
| utilhttp, | ||
| UtilNetworkConnection, | ||
| utiluac, | ||
| utilxml, | ||
| KeymanPaths; | ||
|
|
@@ -817,12 +818,17 @@ procedure TfrmMain.Update_ApplyNow; | |
| ShellPath : string; | ||
| FResult, InstallNow: Boolean; | ||
| frmStartInstallNow: TfrmStartInstall; | ||
| IsMetered: Boolean; | ||
| begin | ||
| InstallNow := True; | ||
| // Confirm User is ok that this will require a reset | ||
| if HasKeymanRun then | ||
| IsMetered := UtilNetworkConnection.IsMetered; | ||
| // If a restarted is required (HasKeymanRun == True) | ||
| // OR it is a Metered connection warn the user and allow | ||
| // them to cancel their request to Install Now. | ||
| // Otherwise start installing. | ||
| if HasKeymanRun OR IsMetered then | ||
|
ermshiperete marked this conversation as resolved.
Outdated
|
||
| begin | ||
| frmStartInstallNow := TfrmStartInstall.Create(nil, true); | ||
| frmStartInstallNow := TfrmStartInstall.Create(nil, HasKeymanRun, IsMetered); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From devin.ai: Contradictory dialog messages when IsMetered=True and HasKeymanRun=False in Update_ApplyNow In |
||
| try | ||
| if frmStartInstallNow.ShowModal = mrOk then | ||
| InstallNow := True | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| (* | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Notes: Enable checking for metered connection and background data restrictions. | ||
| *) | ||
| unit UtilNetworkConnection; | ||
|
|
||
| interface | ||
|
|
||
| (** | ||
| * Checks if the current internet connection is restricted, roaming, or over its | ||
| * data limit. | ||
| * This learn microsoft article shows how to combine network costs to determine | ||
| * if the connection is metered. | ||
| * https://learn.microsoft.com/en-us/uwp/api/windows.networking.connectivity.connectionprofile?view=winrt-28000 | ||
| * | ||
| * @returns True if the connection is metered, False otherwise. | ||
| *) | ||
| function IsMetered: Boolean; | ||
|
|
||
| (** | ||
| * Checks if background data usage is explicitly restricted by the current network profile. | ||
| * | ||
| * @returns True if background data usage is restricted, False otherwise. | ||
| *) | ||
| function IsBackgroundDataRestricted: Boolean; | ||
|
|
||
| (** | ||
| * Determines whether background updates are blocked. | ||
| * | ||
| * @returns True if background updates are blocked, False if allowed. | ||
| * | ||
| * Note: Currently this checks for metered connection OR background | ||
| data usage restricted. If a configuration item is added that | ||
| provides the option to download on metered connections then | ||
| this should be updated to include that logic | ||
| *) | ||
| function IsBackgroundUpdateBlocked: Boolean; | ||
|
|
||
| implementation | ||
|
|
||
| uses | ||
| System.SysUtils, | ||
| Winapi.CommonTypes, | ||
| Winapi.WinRT, | ||
| Winapi.Networking.Connectivity; | ||
|
|
||
| function IsMetered: Boolean; | ||
| var | ||
| Profile: IConnectionProfile; | ||
| 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; | ||
| end; | ||
| end; | ||
|
|
||
| function IsBackgroundDataRestricted: Boolean; | ||
| var | ||
| Profile: IConnectionProfile; | ||
| CostLevel: IConnectionCost; | ||
| 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 | ||
| begin | ||
| Result := DataRestriction.BackgroundDataUsageRestricted; | ||
| Exit; | ||
| end; | ||
| end; | ||
| end; | ||
|
|
||
| // Currently this checks for metered connection OR background | ||
| // data usage restricted. If a configuration item is added that | ||
| // provides the option to download on metered connections then | ||
| // this should be updated to include that logic | ||
| function IsBackgroundUpdateBlocked: Boolean; | ||
| begin | ||
| Result := IsMetered OR IsBackgroundDataRestricted; | ||
| end; | ||
|
ermshiperete marked this conversation as resolved.
|
||
|
|
||
| end. | ||
Uh oh!
There was an error while loading. Please reload this page.