Skip to content

Commit c23f5bb

Browse files
authored
Add DateTime, Personalization, and USB notification settings configurations and tests (#238)
* Add DateTime and Personalization settings configurations and tests * Fix spelling * Add USB notification settings and corresponding tests * Add 'Usb' to spelling allow list * Add attribute * Fix spelling in allow list for 'Usb' * Fix up tests * Small mistake on skip * Ensure StartFolders returns an array or null in tests; update implementation to enforce array type * Fix tests
1 parent 57c7503 commit c23f5bb

File tree

10 files changed

+1408
-34
lines changed

10 files changed

+1408
-34
lines changed

.github/actions/spelling/allow.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ worktree
106106
xffff
107107
yml
108108
zhuangtongfa
109+
DWM
110+
tzautoupdate
111+
Usb

resources/GitDsc/GitDsc.psm1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ enum ConfigLocation {
1616
local
1717
}
1818

19-
# Assert once that Git is already installed on the system.
20-
Assert-Git
21-
2219
#region DSCResources
2320
[DSCResource()]
2421
class GitClone {
@@ -43,6 +40,8 @@ class GitClone {
4340
[string]$ExtraArgs
4441

4542
[GitClone] Get() {
43+
Assert-Git
44+
4645
$currentState = [GitClone]::new()
4746
$currentState.HttpsUrl = $this.HttpsUrl
4847
$currentState.RootDirectory = $this.RootDirectory

resources/Microsoft.Windows.Settings/Microsoft.Windows.Settings.psm1

Lines changed: 373 additions & 21 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
2+
3+
###########################################################################
4+
# This configuration will modify Date and Time Settings. #
5+
# PowerShell module: Microsoft.Windows.Settings (v0.1.0-alpha) #
6+
###########################################################################
7+
8+
properties:
9+
resources:
10+
- resource: Microsoft.Windows.Settings/WindowsSettings
11+
directives:
12+
allowPrerelease: true
13+
description: Configure Date and Time Settings
14+
securityContext: elevated
15+
settings:
16+
# Set to automatically update timezone based on location (true) or disable automatic updates (false)
17+
SetTimeZoneAutomatically: false
18+
# Set the timezone - use Get-TimeZone -ListAvailable to see available timezone IDs
19+
# Common examples:
20+
# - "Pacific Standard Time" (US West Coast)
21+
# - "Eastern Standard Time" (US East Coast)
22+
# - "Central Standard Time" (US Central)
23+
# - "Mountain Standard Time" (US Mountain)
24+
# - "GMT Standard Time" (London)
25+
# - "Central Europe Standard Time" (Paris, Berlin)
26+
# - "China Standard Time" (Beijing)
27+
# - "Tokyo Standard Time" (Japan)
28+
TimeZone: "Pacific Standard Time"
29+
configurationVersion: 0.2.0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
2+
3+
###########################################################################
4+
# This configuration will modify Personalization Settings. #
5+
# PowerShell module: Microsoft.Windows.Settings (v0.1.0-alpha) #
6+
###########################################################################
7+
8+
properties:
9+
resources:
10+
- resource: Microsoft.Windows.Settings/WindowsSettings
11+
directives:
12+
allowPrerelease: true
13+
description: Configure Personalization Settings
14+
securityContext: current
15+
settings:
16+
# Color Settings
17+
EnableTransparency: true
18+
ShowAccentColorOnStartAndTaskbar: true
19+
ShowAccentColorOnTitleBarsAndWindowBorders: true
20+
AutoColorization: true
21+
22+
# Start Menu Folders
23+
# Valid folder names: Documents, Downloads, Music, Pictures, Videos, Network, UserProfile, Explorer, Settings
24+
StartFolders:
25+
- Documents
26+
- Downloads
27+
- Settings
28+
- Explorer
29+
configurationVersion: 0.2.0

samples/DscResources/Microsoft.Windows.Settings/README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The [Microsoft.Windows.settings](https://www.powershellgallery.com/packages/Microsoft.Windows.Settings) PowerShell module contains the Windows Settings DSC Resource.
44

5-
> [!NOTE]
5+
> [!IMPORTANT]
66
> Changing some Windows Settings requires elevation.
77
88
## How to use the WinGet Configuration File
@@ -11,12 +11,45 @@ The following two options are available for running a WinGet Configuration file
1111

1212
### 1. File Explorer
1313

14-
1. Download the `ChangeWindowsSettings.winget` and/or `DefaultWindowsSettings.winget` file to your computer.
15-
2. Double-click the `ChangeWindowsSettings.winget` or the `DefaultWindowsSettings.winget` file (depending on which one you downloaded).
14+
1. Download the desired configuration file to your computer:
15+
- `ChangeWindowsSettings.winget` - Modifies taskbar, color mode, and developer settings
16+
- `DefaultWindowsSettings.winget` - Sets default Windows settings
17+
- `DateTimeSettings.winget` - Configures timezone and automatic timezone update settings
18+
- `PersonalizationSettings.winget` - Configures personalization colors and Start menu folders
19+
- `USBSettings.winget` - Configures USB notification settings
20+
2. Double-click the downloaded `.winget` file.
1621

1722
### 2. Windows Package Manager
1823

19-
1. Download the `ChangeWindowsSettings.winget` and/or `DefaultWindowsSettings.winget` file to your computer.
24+
1. Download the desired configuration file to your computer.
2025
2. Open your Windows Start Menu, search and launch "_Windows Terminal_".
2126
3. Type the following: `CD <C:\Users\User\Download>`
22-
4. Type the following: `winget configure --file .\ChangeWindowsSettings.winget`
27+
4. Type the following: `winget configure --file .\<filename>.winget` (replace `<filename>` with the downloaded file, e.g., `DateTimeSettings`)
28+
29+
## Configuration Files
30+
31+
### ChangeWindowsSettings.winget
32+
33+
Modifies various Windows settings including taskbar alignment, color modes, and developer mode.
34+
35+
### DefaultWindowsSettings.winget
36+
37+
Resets Windows settings to default values (centered taskbar, light mode, developer mode disabled).
38+
39+
### DateTimeSettings.winget
40+
41+
Configures date and time settings including timezone and automatic timezone updates. Requires elevated privileges.
42+
43+
> [!NOTE]
44+
> To see all available timezone IDs, run `Get-TimeZone -ListAvailable` in PowerShell.
45+
46+
### PersonalizationSettings.winget
47+
48+
Configures Windows personalization settings including transparency effects, accent colors, and Start menu folders.
49+
50+
> [!NOTE]
51+
> Valid Start folder names are: Documents, Downloads, Music, Pictures, Videos, Network, UserProfile, Explorer, Settings.
52+
53+
### USBSettings.winget
54+
55+
Configures USB notification settings including notifications for USB errors and weak charger warnings.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
2+
3+
# This configuration file enables USB notifications in Windows Settings.
4+
# It configures two settings:
5+
# 1. NotifyOnUsbErrors: Controls whether to show notifications when USB errors occur
6+
# 2. NotifyOnWeakCharger: Controls whether to show notifications when using a weak USB charger
7+
#
8+
# Registry path: HKCU:\Software\Microsoft\Shell\USB\
9+
10+
properties:
11+
resources:
12+
- resource: Microsoft.Windows.Developer/OsVersion
13+
id: osVersion
14+
directives:
15+
description: Verify OS version
16+
allowPrerelease: true
17+
- resource: Microsoft.Windows.Settings/WindowsSettings
18+
dependsOn:
19+
- osVersion
20+
directives:
21+
description: Configure USB notification settings
22+
settings:
23+
NotifyOnUsbErrors: true
24+
NotifyOnWeakCharger: true
25+
configurationVersion: 0.2.0

tests/GitDsc/GitDsc.tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ Set-StrictMode -Version Latest
99
#>
1010

1111
BeforeAll {
12-
Import-Module GitDsc -Force -ErrorAction SilentlyContinue
12+
if ((Get-Module -Name PSDesiredStateConfiguration -ListAvailable).Version -ne '2.0.7') {
13+
Write-Verbose -Message 'Installing PSDesiredStateConfiguration module.' -Verbose
14+
Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck -RequiredVersion '2.0.7'
15+
}
16+
17+
Import-Module GitDsc
1318
}
1419

1520
Describe 'List available DSC resources' {

tests/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ Describe 'VSCodeExtension' {
6969

7070
It 'Sets desired extension from path' {
7171
BeforeDiscovery {
72-
$script:out = Join-Path ([System.IO.Path]::GetTempPath()) 'ms-toolsai.jupyter-latest.vsix'
72+
$script:outFile = Join-Path ([System.IO.Path]::GetTempPath()) 'ms-toolsai.jupyter-latest.vsix'
7373
$restParams = @{
7474
Uri = 'https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-toolsai/vsextensions/jupyter/latest/vspackage'
7575
UseBasicParsing = $true
76-
OutFile = $out
76+
OutFile = $script:outFile
7777
}
7878
Invoke-RestMethod @restParams
7979
}
8080

8181
$desiredState = @{
82-
Name = $out
82+
Name = $outFile
8383
}
8484

8585
$name = 'ms-toolsai.jupyter'
8686

8787
Invoke-DscResource -Name VSCodeExtension -ModuleName Microsoft.VSCode.Dsc -Method Set -Property $desiredState
8888
$finalState = Invoke-DscResource -Name VSCodeExtension -ModuleName Microsoft.VSCode.Dsc -Method Get -Property $desiredState
8989
$finalState.Name | Should -Be $name
90-
$finalState.Exist | Should -BeTrue
90+
$finalState.Version | Should -Not -BeNullOrEmpty
9191
}
9292

9393
It 'Sets prerelease extension' {

0 commit comments

Comments
 (0)