feat(windows): honour Windows "metered connection" flag for downloading updates#16099
feat(windows): honour Windows "metered connection" flag for downloading updates#16099rc-swag wants to merge 6 commits into
Conversation
This adds a helper unit which uses the windows API to obtain a ConnectionProfile. This profile provides information about the connection status and connectivity statistics. This includes the connection costs, roaming, restricted etc. It also can check to see if background networking activity has been restricted. Using the recommened example this commit combines these to determine if a network is metered. It also provides access to the background network being restricted. Fixes: #13566
If the download has already occured before calling the pop up then there is no reason to warn about the metered connection.
Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>
| // it would be better to have this warning in a banner on the configuration | ||
| // page. | ||
| IsMetered := UtilNetworkConnection.IsMetered; | ||
| // If a restarted is required (HasKeymanRun == True) |
There was a problem hiding this comment.
| // If a restarted is required (HasKeymanRun == True) | |
| // If a restart is required (HasKeymanRun == True) |
| if HasKeymanRun OR IsMetered then | ||
| begin | ||
| frmStartInstallNow := TfrmStartInstall.Create(nil, true); | ||
| frmStartInstallNow := TfrmStartInstall.Create(nil, HasKeymanRun, IsMetered); |
There was a problem hiding this comment.
From devin.ai:
Contradictory dialog messages when IsMetered=True and HasKeymanRun=False in Update_ApplyNow
In UfrmMain.pas:831, when HasKeymanRun is False but IsMetered is True, the form is created with RestartRequired=False and ReadyToInstall=False (default). This causes FormCreate at Keyman.Configuration.UI.UfrmStartInstall.pas:72-73 to show S_Ready_To_Install ("An update to Keyman has been downloaded and is ready to install") while simultaneously displaying the metered warning S_Metered_Warning ("You're on a metered connection. Downloading now may incur data charges") at line 77. These messages directly contradict each other: one says the update has already been downloaded, while the other warns about downloading costs. Before this PR, this code path didn't exist — the old code only showed the dialog when HasKeymanRun was true, always passing RestartRequired=true, so S_Ready_To_Install was never displayed here.

This adds a helper unit which uses the windows API to obtain a ConnectionProfile. This profile provides information about the connection status and connectivity statistics. This includes the connection costs, roaming, restricted etc. It also can check to see if background networking activity has been restricted.
Using the recommened example this commit combines these to determine if a network is metered. It also provides access to the background network being restricted.
There is a call that
IsBackgroundUpdateAllowedthat will return true if a background update is allowed.This is then use in the Update State Machine and also by update pop up.
UpdateStateMachine
Before downloading
IsBackgroundUpdateAllowedis calledUpdate Pop Up
This uses the
IsMeteredcall and adds a warning if to the user who is wanting to Install Now.This message would be better as a banner in the Update Configuration tab, rather than a delphi tab. This is the most efficent place to add the message for now.
Fixes: #13566
Build-bot: release:windows
User Testing
Mark connection as metered
For this we need to use windows setting to set the test machines network to metered. Right click the network connection icon in the Windows System tray and select
network & internet settingsSelected the connected work and the change the toggle forMetered connectiontoOnWindows 11

Windwos 10

TEST_WARNING_MESSAGE
Use a keyboard update to test.
TEST_NO_WARNING_MESSAGE_PART1
This is to make sure a warning message is not present on non-metered connection.
TEST_NO_WARNING_MESSAGE_PART2
This is to make sure a warning message is not present on a metered connection when
we already have the download and are just in the WaitingRestart State.
TEST_NO_BACKGROUND_UPDATE
regeditupdate stateback tousIdlelast update check time. This needs to be done otherwise it will stay inusIdlefor 7 days.c:\Program Files (x86)\Keyman\Keyman Desktopkmshell.exe -cThis will run the configurationTEST_BACKGROUND_UPDATE
This is a regresion test.
OFFas explanined above.regeditupdate stateback tousIdlelast update check time. This needs to be done otherwise it will stay inusIdlefor 7 days.c:\Program Files (x86)\Keyman\Keyman Desktopkmshell.exe -cThis will run the configuration