Hook Theme Switcher

Product: PowerShell Universal
Version: 5.5.5

Is there a way we can hook into the event handler for the light/dark theme toggle to update our own styles? I don’t want to adjust the theme because we have multiple different groups of people that will be viewing the same app, with color schemes depending on which group they’re in. The theme would set the style globally for the app which is far from ideal.

I can use Invoke-UDJavaScript to get the current selected theme from the browser cache, but I have no way to trigger that call dynamically. Any ideas?

@adam any ideas? Should I give up this plan?

Hi parzog,

maybe we could override the current theme with a switch case on specific user claims.
This may be not the best way, as you said you would like to not set the theme itself but I also tried different stuff with custom css and so on which didn’t worked so well but maybe its easier like this.

Maybe something like this:

$claims = # crazy stuff here to get the claims of a user
switch($claims) {
"Accounting" {
$currentTheme = Get-UDTheme -Name "AntDesign"
# do styling stuff here
$currentTheme.light.overrides.... = # new style here
}
"Some other group" { ... }
}
$newTheme = $currentTheme.Clone()
Set-UDTheme -Theme $newTheme

I’ll have a try later because this would be also a usefull thing for us.

Edit:
You need to copy the current theme, otherwise you will override the AntDesign Theme itself

Edit2:
It works but it’s a bit squishy

That’s a great way to put it! Squishy.

I understand how the dark/light theme toggle works under the hood and was just wanting to update my own CSS to react at the same time. The only way we can approximate this is with the currentcolor keyword, it seems, which IS theme reactive, but it relies on the parent’s attributes and as such is quite limiting.

I’m still looking for something that may work, but I’m not optimistic at this point in time. Thanks for your input, though!