-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.ps1
96 lines (81 loc) · 2.4 KB
/
settings.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<#
Chameleon - An automated bright / dark mode toggle
service that follows the sun.
Authors:
Simon Olofsson
https://github.com/dotchetter
Michael Hällström
https://github.com/yousernaym
Date:
2021-03-17
Logic for settings dialog window
#>
Import-Module .\helpers.ps1
function initSettingsWindow()
{
#Create window
[xml]$xaml = Get-Content ".\settings.xaml"
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$script:settingsWindow = [Windows.Markup.XamlReader]::Load($reader)
#useDarkRb click event
$script:useDarkRb = $script:settingsWindow.FindName("useDarkRb")
$script:useDarkRb.Add_Click( {
$script:sunEnabled = $false
getTheme | setTheme
$script:selectedTheme = [Themes]::dark
})
#useLightRb click event
$script:useLightRb = $script:settingsWindow.FindName("useLightRb")
$script:useLightRb.Add_Click( {
$script:sunEnabled = $false
getTheme | setTheme
$script:selectedTheme = [Themes]::light
})
#sunRb click event
$script:sunRb = $script:settingsWindow.FindName("sunRb")
$script:sunRb.Add_Click( {
$script:sunEnabled = $true
[Themes]::sun | setTheme
$script:selectedTheme = [Themes]::sun
})
switch ($script:selectedTheme) {
dark { $script:useDarkRb.IsChecked = $true }
light { $script:useLightRb.IsChecked = $true }
sun { $script:sunRb.IsChecked = $true }
}
#appsCb click events
$script:appsCb = $script:settingsWindow.FindName("appsCb")
$script:appsCb.Add_Click( {
$script:appsEnabled = $script:appsCb.IsChecked
getTheme | setTheme
})
$script:appsCb.IsChecked = $script:appsEnabled
#systemCb click events
$script:systemCb = $script:settingsWindow.FindName("systemCb")
$script:systemCb.Add_Click( {
$script:systemEnabled = $script:systemCb.IsChecked
getTheme | setTheme
})
$script:systemCb.IsChecked = $script:systemEnabled
}
function getTheme()
{
if ($sunRb.IsChecked) {
$theme = [Themes]::sun
}
else {
if ($useDarkRb.IsChecked) {
$theme = [Themes]::dark
}
else{
$theme = [Themes]::light
}
}
return $theme
}
function showSettings
{
initSettingsWindow
$script:settingsWindow.ShowDialog()
}