-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStayAwake.ps1
More file actions
144 lines (127 loc) · 4.37 KB
/
StayAwake.ps1
File metadata and controls
144 lines (127 loc) · 4.37 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Add-Type -AssemblyName PresentationFramework
function Set-PowerSettings {
param (
[bool]$Disable
)
if ($Disable) {
powercfg /change standby-timeout-ac 0
powercfg /change standby-timeout-dc 0
powercfg /change monitor-timeout-ac 0
powercfg /change monitor-timeout-dc 0
powercfg /change hibernate-timeout-ac 0
powercfg /change hibernate-timeout-dc 0
} else {
powercfg /change standby-timeout-ac 15
powercfg /change standby-timeout-dc 10
powercfg /change monitor-timeout-ac 3
powercfg /change monitor-timeout-dc 3
powercfg /change hibernate-timeout-ac 30
powercfg /change hibernate-timeout-dc 15
}
}
function Get-PowerStatus {
$output = powercfg /query SCHEME_CURRENT SUB_SLEEP STANDBYIDLE
$outputLines = $output -join "`n"
# Hole die vorletzte Zeile der Ausgabe
$lines = $outputLines.Split("`n")
$secondLastLine = $lines[$lines.Length - 2]
# Suche nach dem Wert "0x00000000" in der vorletzten Zeile
if ($secondLastLine -match "0x00000000") {
return "deaktiviert"
} else {
return "aktiviert"
}
}
# Fenster
$window = New-Object System.Windows.Window
$window.Title = "StayAwake"
$window.Width = 400
$window.Height = 300
$window.WindowStartupLocation = "CenterScreen"
$window.Background = "#f9f9f9"
# Border mit abgerundeten Ecken
$border = New-Object System.Windows.Controls.Border
$border.CornerRadius = "12"
$border.Background = "#ffffff"
$border.Padding = "20"
$border.Margin = "10"
$window.Content = $border
# Layout
$stackPanel = New-Object System.Windows.Controls.StackPanel
$stackPanel.Orientation = "Vertical"
$stackPanel.HorizontalAlignment = "Center"
$stackPanel.VerticalAlignment = "Center"
$stackPanel.Width = 300
$border.Child = $stackPanel
# Titel
$titleText = New-Object System.Windows.Controls.TextBlock
$titleText.Margin = "0,0,0,20"
$titleText.FontSize = 18
$titleText.Foreground = "#333333"
$titleText.TextAlignment = "Center"
$titleText.Text = "StayAwake"
$stackPanel.Children.Add($titleText) | Out-Null
# Button-Stil
function New-Win11Button($content, $bgColor, $borderColor) {
$btn = New-Object System.Windows.Controls.Button
$btn.Content = $content
$btn.Margin = "0,8,0,0"
$btn.Padding = "10"
$btn.Height = 42
$btn.FontSize = 14
$btn.Foreground = "White"
$btn.Background = $bgColor
$btn.BorderBrush = $borderColor
$btn.Cursor = "Hand"
$btn.Template = [Windows.Markup.XamlReader]::Parse(@"
<ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" TargetType="Button">
<Border CornerRadius="8" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
"@)
return $btn
}
# Buttons
$enableButton = New-Win11Button "Aktiviert" "#D1D5DB" "#D1D5DB"
$disableButton = New-Win11Button "Deaktiviert" "#D1D5DB" "#D1D5DB"
$stackPanel.Children.Add($enableButton) | Out-Null
$stackPanel.Children.Add($disableButton) | Out-Null
# Statusanzeige
$statusText = New-Object System.Windows.Controls.TextBlock
$statusText.Margin = "0,20,0,10"
$statusText.FontSize = 14
$statusText.Foreground = "#0F5132"
$statusText.TextAlignment = "Center"
$stackPanel.Children.Add($statusText) | Out-Null
# Button-Farben je nach Status
function Set-ButtonState($status) {
if ($status -eq "aktiviert") {
$enableButton.Background = "#2563EB"
$enableButton.BorderBrush = "#2563EB"
$disableButton.Background = "#D1D5DB"
$disableButton.BorderBrush = "#D1D5DB"
} elseif ($status -eq "deaktiviert") {
$disableButton.Background = "#2563EB"
$disableButton.BorderBrush = "#2563EB"
$enableButton.Background = "#D1D5DB"
$enableButton.BorderBrush = "#D1D5DB"
}
}
# Button-Events
$enableButton.Add_Click({
Set-PowerSettings -Disable $false
$statusText.Text = "Energieoptionen sind aktiviert."
Set-ButtonState "aktiviert"
})
$disableButton.Add_Click({
Set-PowerSettings -Disable $true
$statusText.Text = "Energieoptionen sind deaktiviert."
Set-ButtonState "deaktiviert"
})
# Initialstatus abfragen und setzen
$currentStatus = Get-PowerStatus
$statusText.Text = "Energieoptionen sind $currentStatus."
Set-ButtonState $currentStatus
# Fenster anzeigen
[void]$window.ShowDialog()