-
Notifications
You must be signed in to change notification settings - Fork 16
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
Windows settings time #109
base: main
Are you sure you want to change the base?
Conversation
@ryfu-msft And this one. There is still an issue that I have opened at PSDesiredStateConfiguration. |
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
# Timezone values are taken from the list of timezones (Get-TimeZone -ListAvailable).Id | ||
# TODO: Track issue 125 on PSDesiredStateConfiguration repository to add a ValidateSet for time zones | ||
[DscProperty(Key)] | ||
# [ValidateSet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be a validate script; Ref your linked issue - PowerShell/PSDesiredStateConfiguration#125 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that I can think of, is create a enum without the spaces, and add another helper function to translate it. Might be a bit overkill, so I'm curious what the PS team is going to mention.
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
AliasesToExport = '*' | ||
|
||
# DSC resources to export from this module | ||
DscResourcesToExport = @('Time') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put it on #100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would implement it as a single AdditionalClock
resource, which has Properties of Ensure
, TimeZone
, DisplayName
.
For Get
-
- Fetch the values in
1
- Compare against properties
- If the properties match, set ensure present and return the current state
- If the properties don't match, fetch the values in
2
- Compare against properties
- If the properties match, set ensure present; otherwise, set ensure absent
- Return the current state
For Test
-
- Run
Get
- Compare
Ensure
of the current state toEnsure
of the desired state - Return result of comparison
For Set
it's a bit more complicated, I'd imagine you'd first want to determine if either 1
or 2
had a matching DisplayName
, if it does, set the values for that clock. If no display names match, check if either timezone matches, if it does, set the values for that clock. If neither are a match, put it in slot 1 if the enable property of the slot is not set. If slot 1 is already enabled, put it in slot 2 if the enable property of the slot is not set. If slot 2 is already enabled, throw an error that the maximum number of additional clocks have been set.
Alternatively, you could just add a parameter for Id
and restrict it to being 1
or 2
and have it be mandatory for Set
operations but optional for Get
and Test
. That's honestly probably the better option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the details. One small question, how will users be able to specify both 1 and 2 in a single configuration document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They call the resource twice - once for setting slot one, and a second time for setting slot two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lack the knowledge on this part. Either clock 1 or clock 2 can be turned on, or both. Shouldn't the user be able to say something like: AdditionalClock1Settings
and AdditionaClock2Settings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need; They can confugure like:
- resource: Microsoft.Windows.Setting.Time/AdditionalClock
directives:
description: Set clock 1
allowPrerelease: true
settings:
Slot: 1
DisplayName: UTC
Timezone: UTC
Ensure: Present
- resource: Microsoft.Windows.Setting.Time/AdditionalClock
directives:
description: Set clock 2
allowPrerelease: true
settings:
Slot: 2
DisplayName: Current time in Redmond
Timezone: Pacific Standard Time
Ensure: Present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cool. I'll pick it up after this is merged!
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psd1
Outdated
Show resolved
Hide resolved
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
…nget-dsc into windows-setting-time
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@denelon I'm adding you to the chain as well because I can remember you making a remark in the past that you were checking with the Windows team on registry keys. When spawning up a fresh machine from DevHome, I noticed something odd that I hadn't seen before. I just learned about the privacy and security settings, but they bite this PR (a bit). For now, I have added an additional check on the relevant registry keys I could capture when |
That's a great find! What settings are getting applied here, and what happens if we don't enable the location permissions? |
Users must manually enter the time if the location permissions aren't set. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
[DscProperty()] | ||
[nullable[bool]] $SetTimeAutomatically | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about moving things like SetTimeAutomatically
to a separate DSC resource called Time
.
When I look at the settings page for TimeZone, I only see SetTimeZoneAutomatically
and if that is not true, then we have the option to set the TimeZoneId and DaylightSaving. I think this DSC resource should try to replicate what we see in the settings app. I think this is the best way to prevent scope creep for this individual DSC resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's precisely why I did it into one DSC resource. They bite each other. Even if we separate them both, we have to check what options are already enabled in both cases. If we set the Timezone to automatically, we might need to clean up the manual settings and vice versa.
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
resources/Microsoft.Windows.Setting.Time/Microsoft.Windows.Setting.Time.psm1
Outdated
Show resolved
Hide resolved
if ($currentState::SupportsDaylightSavingProperty) { | ||
$currentState.AdjustForDaylightSaving = [TimeZone]::GetDayLightSavingStatus() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is not dependent on whether the time zone supports daylight saving or not. This should just be a registry check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't totally get you here. It is checking the registry with the GetDayLightSavingStatus()
method?
function Test-LocationSettingPermission { | ||
# On Windows 11, the HKLM is the location services, whereas HKCU is the Let apps access your location setting | ||
$registryKeys = @('HKLM:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location\windows.immersivecontrolpanel*') | ||
foreach ($key in $registryKeys) { | ||
$res = Get-ItemProperty -Path $key -Name 'Value' -ErrorAction SilentlyContinue | ||
if ($res.Value -ne 'Allow') { | ||
# TODO: Or should we throw an error? | ||
return $false | ||
} | ||
} | ||
|
||
return $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that this should be its own separate DSC resource for just Location. I'm sure there are other settings that will depend on this, not just Time/TimeZone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partially, as it affects the TimeZone setting, what's your suggestion? A custom module to inherit those functions?
Addresses issue #34 and #100