-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[DSC] Implement Microsoft.PowerToys.Configure DSCResource & winget support #30918
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
Merged
jaimecbernardo
merged 29 commits into
microsoft:main
from
yuyoyuppe:dsc_configure_module
Apr 1, 2024
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d7663d6
[DSC] Microsoft.PowerToys.Configure module + winget configuration fil…
yuyoyuppe f8e4737
f: fix for an incorrect directory id reference
yuyoyuppe cd69d09
f: update comment
yuyoyuppe 92d373f
f: address review comments
yuyoyuppe 251e967
f: file locksmith bug fix
yuyoyuppe 1275da5
f: add explorer preview switches in samples
yuyoyuppe f3fce0e
f: remove debug
yuyoyuppe 9fcae1a
Sign DSC files
jaimecbernardo 6e3eb15
Merge branch 'main' into dsc_configure_module
yuyoyuppe 64f9fe0
f: implement docs/samples generator
yuyoyuppe b1e2286
[ci]Sign FancyZonesEditorCommon.dll
jaimecbernardo 3b61840
Sign DSC files in the Generated folder
jaimecbernardo a39158d
f: address review comments
yuyoyuppe da2ef06
Merge branch 'main' into dsc_configure_module
yuyoyuppe 4e9b334
f: update usable options
yuyoyuppe 6c00343
f: add autogenerated sample
yuyoyuppe a2f5e2f
[Installer] Don't use same GUID for different components
jaimecbernardo 6da3d6c
[Installer]Don't remove folders shared by other modules
jaimecbernardo eaee7e0
Allow configuring PTRun MaximumNumberOfResults
jaimecbernardo 54800c5
Remove all settings DSC sample. Just random data
jaimecbernardo b0285d1
Allow configuring Hosts Run as Administrator
jaimecbernardo dea50c3
Revert "[Installer]Don't remove folders shared by other modules"
jaimecbernardo dd3f35f
Add all PTRun plugins and Global and keyboard to DSC sample
jaimecbernardo 940080b
Fix issues with context menu modules not disabling
jaimecbernardo b6f0472
Fix default enabled values when setting with DSC
jaimecbernardo 5d6eeaf
Fix tests regarding default modules in Settings
jaimecbernardo c91d519
Merge branch 'main' into pr30918
jaimecbernardo f25955f
Fix merge error
jaimecbernardo b7fad12
Restart PowerToys process if we stopped it
jaimecbernardo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1029,6 +1029,7 @@ NOSIZE | |
| NOTIFICATIONSDLL | ||
| NOTIFYICONDATAW | ||
| NOTIMPL | ||
| notlike | ||
| NOTOPMOST | ||
| NOTRACK | ||
| NOTSRCCOPY | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { | ||
| "Version": "1.0.0", | ||
| "UseMinimatch": false, | ||
| "SignBatches": [ | ||
| { | ||
| "MatchedPath": [ | ||
| "Microsoft.PowerToys.Configure.psm1", | ||
| "Microsoft.PowerToys.Configure.psd1" | ||
| ], | ||
| "SigningInfo": { | ||
| "Operations": [ | ||
| { | ||
| "KeyCode": "CP-230012", | ||
| "OperationSetCode": "SigntoolSign", | ||
| "Parameters": [ | ||
| { | ||
| "parameterName": "OpusName", | ||
| "parameterValue": "Microsoft" | ||
| }, | ||
| { | ||
| "parameterName": "OpusInfo", | ||
| "parameterValue": "http://www.microsoft.com" | ||
| }, | ||
| { | ||
| "parameterName": "FileDigest", | ||
| "parameterValue": "/fd \"SHA256\"" | ||
| }, | ||
| { | ||
| "parameterName": "PageHash", | ||
| "parameterValue": "/NPH" | ||
| }, | ||
| { | ||
| "parameterName": "TimeStamp", | ||
| "parameterValue": "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" | ||
| } | ||
| ], | ||
| "ToolName": "sign", | ||
| "ToolVersion": "1.0" | ||
| }, | ||
| { | ||
| "KeyCode": "CP-230012", | ||
| "OperationSetCode": "SigntoolVerify", | ||
| "Parameters": [], | ||
| "ToolName": "sign", | ||
| "ToolVersion": "1.0" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # What is it | ||
|
|
||
| We would like to enable our users to use [`winget configure`](https://learn.microsoft.com/en-us/windows/package-manager/winget/configure) command to install PowerToys and configure its settings with a [Winget configuration file](https://learn.microsoft.com/en-us/windows/package-manager/configuration/create). For example: | ||
|
|
||
| ```yaml | ||
| properties: | ||
| resources: | ||
| - resource: Microsoft.WinGet.DSC/WinGetPackage | ||
| directives: | ||
| description: Install PowerToys | ||
| allowPrerelease: true | ||
| settings: | ||
| id: PowerToys (Preview) | ||
| source: winget | ||
|
|
||
| - resource: PowerToysConfigure | ||
| directives: | ||
| description: Configure PowerToys | ||
| settings: | ||
| ShortcutGuide: | ||
| Enabled: false | ||
| OverlayOpacity: 1 | ||
| FancyZones: | ||
| Enabled: true | ||
| FancyzonesEditorHotkey: "Shift+Ctrl+Alt+F" | ||
| configurationVersion: 0.2.0 | ||
| ``` | ||
|
|
||
| This should install PowerToys and make `PowerToysConfigure` resource available. We can use it in the same file. | ||
|
|
||
| # How it works | ||
|
|
||
| `PowerToysConfigure` is a [class-based DSC resource](https://learn.microsoft.com/en-us/powershell/dsc/concepts/class-based-resources?view=dsc-2.0). It looks up whether each setting was specified or not by checking whether it's `$null` or `0` for `enum`s and invokes `PowerToys.Settings.exe` with the updated value like so: | ||
| ``` | ||
| PowerToys.Settings.exe set <ModuleName>.<SettingName> <SettingValue> | ||
| ``` | ||
|
|
||
| So for the example the config above should perform 3 following invocations: | ||
| ``` | ||
| PowerToys.Settings.exe set ShortcutGuide.Enabled false | ||
| PowerToys.Settings.exe set FancyZones.Enabled true | ||
| PowerToys.Settings.exe set FancyZones.FancyzonesEditorHotkey "Shift+Ctrl+Alt+F" | ||
| ``` | ||
|
|
||
| `PowerToys.Settings` uses dotnet reflection capabilities to determine `SettingName` type and tries to convert the supplied `SettingValue` string accordingly. We use `ICmdReprParsable` for custom setting types. | ||
|
|
||
|
|
||
| # How DSC is implemented | ||
|
|
||
| We use `PowerToys.Settings.DSC.Schema.Generator` to generate the bulk of `PowerToysConfigure.psm1` file. It also uses dotnet reflection capabilities to inspect `PowerToys.Settings.UI.Lib.dll` assembly and generate properties for the modules we have. The actual generation is done as a `PowerToys.Settings.DSC.Schema.Generator.csproj` post-build action. | ||
|
|
||
| # Debugging DSC resources | ||
|
|
||
| First, make sure that PowerShell 7.4+ is installed. Then make sure that you have DSC installed: | ||
|
|
||
| ```ps | ||
| Install-Module -Name PSDesiredStateConfiguration -RequiredVersion 2.0.7 | ||
| ``` | ||
|
|
||
| After that, start a new `pwsh` session and `cd` to `src\dsc\Microsoft.PowerToys.Configure\Generated` directory. From there, you should execute: | ||
| ```ps | ||
| $env:PSModulePath += ";$pwd" | ||
| ``` | ||
|
|
||
| Now build `PowerToys.sln` and **move** `src\dsc\Microsoft.PowerToys.Configure\Microsoft.PowerToys.Configure.psd1` temporarily to `src\dsc\Microsoft.PowerToys.Configure\Generated\Microsoft.PowerToys.Configure\0.0.1\` folder, so it's located alongside with the generated `Microsoft.PowerToys.Configure.psm1`. | ||
|
|
||
| This will allow DSC to discover our DSC Resource module. See [PSModulePath](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4#long-description) for more info. | ||
|
|
||
| If everything works, you should see that your module is discovered by executing the following command: | ||
|
|
||
| ```ps | ||
| Get-Module -ListAvailable | grep PowerToys | ||
| ``` | ||
|
|
||
| The resource itself should also be available: | ||
| ```ps | ||
| Get-DSCResource | grep PowerToys | ||
| ``` | ||
|
|
||
| Otherwise, you can force-import the module to diagnose issues: | ||
|
|
||
| ``` | ||
| Import-Module .\Microsoft.PowerToys.Configure.psd1 | ||
| ``` | ||
|
|
||
| If it's imported successfully, you could also try to invoke it directly: | ||
|
|
||
| ```ps | ||
| Invoke-DscResource -Name PowerToysConfigure -Method Set -ModuleName Microsoft.PowerToys.Configure -Property @{ Debug = $true; Awake = @{ Enabled = $false; Mode = "TIMED"; IntervalMinutes = "10" } } | ||
| ``` | ||
|
|
||
| Note that we've supplied `Debug` option, so a `%TEMP\PowerToys.DSC.TestConfigure.txt` is created with the supplied properties, a current timestamp, and other debug output. | ||
|
|
||
| Finally, you can test it with winget by invoking it as such: | ||
|
|
||
| ```ps | ||
| winget configure .\configuration.dsc.yaml --accept-configuration-agreements --disable-interactivity | ||
| ``` |
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 |
|---|---|---|
|
|
@@ -46,6 +46,49 @@ | |
| </Component> | ||
| </DirectoryRef> | ||
|
|
||
| <?if $(var.PerUser) = "true" ?> | ||
| <DirectoryRef Id="PersonalFolder"> | ||
| <Directory Id="WindowsPowerShellFolder" Name="PowerShell"> | ||
| <Directory Id="PowerShellModulesFolder" Name="Modules"> | ||
| <Directory Id="PowerToysDscFolder" Name="Microsoft.PowerToys.Configure"> | ||
| <Directory Id="PowerToysDscVerFolder" Name="$(var.Version)"> | ||
| <Component Id="PowerToysDSC" Win64="yes" Guid="4A033E3B-6590-43FD-8FBD-27F9DF557F7F"> | ||
|
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. Can we make the component not fail the installation if the component is not able to be installed? |
||
| <RegistryValue Root="HKCU" | ||
| Key="Software\[Manufacturer]\[ProductName]" | ||
| Name="DSCInstalled" | ||
| Type="integer" | ||
| Value="1" | ||
| KeyPath="yes"/> | ||
| <File Source="$(var.RepoDir)\src\dsc\Microsoft.PowerToys.Configure\Microsoft.PowerToys.Configure.psd1" Id="PTConf.psd1" /> | ||
| <File Source="$(var.RepoDir)\src\dsc\Microsoft.PowerToys.Configure\Generated\Microsoft.PowerToys.Configure\$(var.Version)\Microsoft.PowerToys.Configure.psm1" Id="PTConf.psm1" /> | ||
| <RemoveFolder Id="RemoveThisFolder" On="uninstall" /> | ||
| <RemoveFolder Id="RemovePowerToysDscVerFolder" Directory="PowerToysDscVerFolder" On="uninstall" /> | ||
| <RemoveFolder Id="RemovePowerToysDscFolder" Directory="PowerToysDscFolder" On="uninstall" /> | ||
| <RemoveFolder Id="RemovePowerShellModulesFolder" Directory="PowerShellModulesFolder" On="uninstall" /> | ||
| <RemoveFolder Id="RemoveWindowsPowerShellFolder" Directory="WindowsPowerShellFolder" On="uninstall" /> | ||
jaimecbernardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </Component> | ||
| </Directory> | ||
| </Directory> | ||
| </Directory> | ||
| </Directory> | ||
| </DirectoryRef> | ||
| <?else?> | ||
| <DirectoryRef Id="ProgramFiles64Folder"> | ||
| <Directory Id="WindowsPowerShellFolder" Name="WindowsPowerShell"> | ||
| <Directory Id="PowerShellModulesFolder" Name="Modules"> | ||
| <Directory Id="PowerToysDscFolder" Name="Microsoft.PowerToys.Configure"> | ||
| <Directory Id="PowerToysDscVerFolder" Name="$(var.Version)"> | ||
| <Component Id="PowerToysDSC" Win64="yes" Guid="C52AECA0-DA73-49B8-BB49-31EF6640FF1F"> | ||
| <File Source="$(var.RepoDir)\src\dsc\Microsoft.PowerToys.Configure\Microsoft.PowerToys.Configure.psd1" Id="PTConf.psd1" /> | ||
| <File Source="$(var.RepoDir)\src\dsc\Microsoft.PowerToys.Configure\Generated\Microsoft.PowerToys.Configure\$(var.Version)\Microsoft.PowerToys.Configure.psm1" Id="PTConf.psm1" /> | ||
| </Component> | ||
| </Directory> | ||
| </Directory> | ||
| </Directory> | ||
| </Directory> | ||
| </DirectoryRef> | ||
| <?endif?> | ||
|
|
||
| <DirectoryRef Id="ApplicationProgramsFolder"> | ||
| <Component Id="PowerToysStartMenuShortcut" > | ||
| <Shortcut Id="ApplicationStartMenuShortcut" | ||
|
|
@@ -101,6 +144,7 @@ | |
| <ComponentRef Id="License_rtf" /> | ||
| <ComponentRef Id="Notice_md" /> | ||
| <ComponentRef Id="DesktopShortcut" /> | ||
| <ComponentRef Id="PowerToysDSC" /> | ||
| </ComponentGroup> | ||
| </Fragment> | ||
| </Wix> | ||
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
Oops, something went wrong.
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.