chocolatey / ChocolateyGUI

A delicious GUI for Chocolatey
https://docs.chocolatey.org/en-us/chocolatey-gui/
Apache License 2.0
1.61k stars 249 forks source link

(#494) Refresh sources from file #955

Open corbob opened 1 year ago

corbob commented 1 year ago

Description Of Changes

Update to get sources from the configuration file every time they're requested.

Motivation and Context

When the sources are updated outside of Chocolatey GUI (or within Chocolatey GUI when Chocolatey Licensed Extension is installed), only the sources that were present when Chocolatey GUI started are loaded, no new sources are found.

Testing

Note: Because Chocolatey GUI interacts with Chocolatey through the Chocolatey library, and because there are extensions that can change behaviour, all testing should be done with Chocolatey CLI, then with Chocolatey Licensed Extension installed, and finally with Chocolatey GUI Licensed Extension installed. The below steps were taken with each of those configurations.

Chocolatey Licensed Extension Note: I have noted in my testing that if you install Licensed Extension, then immediately open Chocolatey GUI without running choco beforehand, you end up with a duplicated list of remote sources on the left. Any action that makes changes to the Chocolatey config file will correct this duplication. I believe this is due to the list being updated on application load, and since that (effectively) runs choco, the config is updated with the Licensed Extension configurations which fires the FileSystemWatcher and results in a second refresh occurring in rapid succession. This is the only time I have been able to get this behaviour to occur since correcting it in the FileSystemWatcher.

  1. Open a PowerShell window as administrator and Chocolatey GUI
  2. Position them such that you can see Chocolatey GUI and the PowerShell window with minimal overlap
  3. Run choco sources list
  4. Note that the list of enabled sources matches the left panel of Chocolatey GUI
  5. Run choco source add -n test -s c:\
  6. Note that Chocolatey GUI left panel updates with new test source
  7. Run choco source disable -n test
  8. Note that Chocolatey GUI left panel updates without the test source
  9. Navigate to Settings > Sources in Chocolatey GUI
  10. Note that test source is there, but disabled.
  11. Enable test source and navigate back to Chocolatey GUI
  12. Note that test is back in the list
  13. Run choco source remove -n test
  14. Note that test is removed from the list on the left panel of Chocolatey GUI
  15. Navigate to Settings > Sources in Chocolatey GUI
  16. Note that test source is no longer there
  17. Close Chocolatey GUI

Chocolatey Licensed Extension specific tests

Due to some of the restrictions that the Chocolatey Licensed Extension provides, we need to test the following with the Licensed Extension, and with the Chocolatey GUI Licensed Extension. Use the following code to setup a few settings:

choco install chocolatey-agent
choco feature disable -n showNonElevatedWarnings
choco feature enable -n useBackgroundService
choco feature enable -n useBackgroundServiceWithNonAdministratorsOnly
choco source add -n admin-only -s c:\temp --adminonly
choco source add -n self-serve -s c:\temp --allowselfservice

With Chocolatey configured, perform the following tests:

  1. Launch Chocolatey GUI as a no-administrative user
  2. Verify that only self-serve source is the only source listed on the left
  3. In administrative PowerShell run: choco source disable -n self-serve
  4. Note that the source disappears on the left
  5. In administrative PowerShell run: choco source enable -n self-serve
  6. Note that the source re-appears.
  7. In administrative PowerShell run: choco source add -n new-self-serve -s c\temp --allowselfservice
  8. Note that the new source should appear on the left
  9. In administrative PowerShell run: choco source add -n admin-only -s c:\temp
  10. Note that the admin-only source should appear in the left of Chocolatey GUI

Change Types Made

Related Issue

Fixes #494

Change Checklist

corbob commented 1 year ago

After reverting commit 583b1b9f160a92df7b1ea9d39ddc46bf28a7949b I performed the tests in the PR. My observations are:

  1. With Just Chocolatey CLI installed, all existing sources in the file when Chocolatey GUI is launched successfully maintain state. If you enable or disable them outside of Chocolatey GUI, they are updated inside of Chocolatey GUI. However, if you add a new source, it fails to be detected.
  2. With Chocolatey Licensed Extension installed, the tests behaved the same as Chocolatey CLI. The Licensed specific tests however did not work as desired. The only change that was correctly picked up is enable, disable, or removal of an existing source. Changes to the Admin Only or Self Serve status does not get reflected.