-
-
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
Open
rc-swag
wants to merge
8
commits into
master
Choose a base branch
from
feat/windows/13566/check-metered-connection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9933ab
feat(windows): add network connectivity tool
rc-swag cc8b4d2
Merge branch 'master' into feat/windows/13566/check-metered-connection
rc-swag 94756fd
feat(windows): add intstall ready flag to pop up
rc-swag e92f01a
Merge branch 'master' into feat/windows/13566/check-metered-connection
rc-swag 293f8ec
feat(windows): apply suggestions from code review
rc-swag 5e26d5d
feat(windows): address review comments
rc-swag 3974f03
feat(windows): use enum to drive installfrm layout
rc-swag 85da9dc
feat(windows): apply suggestions
rc-swag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
windows/src/desktop/kmshell/util/UtilNetworkConnection.pas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 allowed. | ||
| * | ||
| * @returns True if updates can proceed, False if blocked by network constraints. | ||
| * | ||
| * 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 IsBackgroundUpdateAllowed: 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 IsBackgroundUpdateAllowed: Boolean; | ||
| begin | ||
| Result := IsMetered OR IsBackgroundDataRestricted; | ||
| end; | ||
|
ermshiperete marked this conversation as resolved.
|
||
|
|
||
| end. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.