Skip to content

Commit 0cb5bc4

Browse files
committed
feat: themes and wallpapers
1 parent d7b85d3 commit 0cb5bc4

File tree

16 files changed

+200
-177
lines changed

16 files changed

+200
-177
lines changed

src/playbook/Configuration/tweaks/qol/appearance/atlas-theme.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ actions:
99
Set-ThemeMRU
1010
wait: true
1111
onUpgrade: true
12-
oobe: false
12+
oobe: true
1313
exeDir: true
1414
runas: currentUserElevated
1515

1616
- !powerShell:
1717
command: |
1818
.\AtlasModules\initPowerShell.ps1
19-
Set-Theme -Path """$([Environment]::GetFolderPath('Windows'))\Resources\Themes\atlas-v0.4.x-dark.theme"""
19+
Set-Theme -Path """$([Environment]::GetFolderPath('Windows'))\Resources\Themes\atlas-v0.5.x-dark.theme"""
2020
Set-ThemeMRU
2121
wait: true
2222
onUpgrade: false
@@ -56,9 +56,9 @@ actions:
5656

5757
# Set Atlas theme as default for new users
5858
- !registryValue:
59-
path: 'HKCU\Software\Policies\Microsoft\Windows\Personalization'
59+
path: 'HKU\AME_UserHive_Default\Software\Policies\Microsoft\Windows\Personalization'
6060
value: 'ThemeFile'
61-
data: '%windir%\Resources\Themes\atlas-v0.4.x-dark.theme'
61+
data: '%windir%\Resources\Themes\atlas-v0.5.x-dark.theme'
6262
type: REG_SZ
6363
onUpgrade: true
6464

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +0,0 @@
1-
$windir = [Environment]::GetFolderPath('Windows')
2-
3-
function Stop-ThemeProcesses {
4-
Get-Process 'SystemSettings', 'control' -EA 0 | Stop-Process -Force -EA 0
5-
}
6-
7-
function Set-Theme {
8-
param (
9-
[Parameter(Mandatory = $true)]
10-
[ValidateNotNullOrEmpty()]
11-
[string]$Path
12-
)
13-
14-
if (!((Get-Item $Path -EA 0).Extension -eq '.theme')) {
15-
throw "'$Path' is not a valid path to a theme file."
16-
}
17-
Stop-ThemeProcesses
18-
Start-Process -filepath $path ; timeout /t 3; taskkill /im "systemsettings.exe" /f
19-
Start-Sleep 10
20-
Stop-ThemeProcesses
21-
}
22-
23-
function Set-ThemeMRU {
24-
if ([System.Environment]::OSVersion.Version.Build -ge 22000) {
25-
Stop-ThemeProcesses
26-
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" -Name "ThemeMRU" -Value "$((@(
27-
"atlas-v0.4.x-dark.theme",
28-
"atlas-v0.4.x-light.theme",
29-
"atlas-v0.3.x-dark.theme",
30-
"atlas-v0.3.x-light.theme",
31-
"dark.theme",
32-
"aero.theme"
33-
) | ForEach-Object { "$windir\resources\Themes\$_" }) -join ';');" -Type String -Force
34-
}
35-
}
36-
37-
# Credit: https://superuser.com/a/1343640
38-
function Set-LockscreenImage {
39-
param (
40-
[ValidateNotNullOrEmpty()]
41-
[string]$Path = "$([Environment]::GetFolderPath('Windows'))\AtlasModules\Wallpapers\lockscreen.png"
42-
)
43-
44-
if (!(Test-Path $Path)) {
45-
throw "Path ('$Path') for lockscreen not found."
46-
}
47-
$newImagePath = [System.IO.Path]::GetTempPath() + (New-Guid).Guid + [System.IO.Path]::GetExtension($Path)
48-
Copy-Item $Path $newImagePath
49-
50-
# setup WinRT namespaces
51-
Add-Type -AssemblyName System.Runtime.WindowsRuntime
52-
[Windows.System.UserProfile.LockScreen, Windows.System.UserProfile, ContentType = WindowsRuntime] | Out-Null
53-
54-
# setup async
55-
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? {
56-
$_.Name -eq 'AsTask' -and
57-
$_.GetParameters().Count -eq 1 -and
58-
$_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1'
59-
})[0]
60-
Function Await($WinRtTask, $ResultType) {
61-
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
62-
$netTask = $asTask.Invoke($null, @($WinRtTask))
63-
$netTask.Wait(-1) | Out-Null
64-
$netTask.Result
65-
}
66-
Function AwaitAction($WinRtAction) {
67-
$asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
68-
$netTask = $asTask.Invoke($null, @($WinRtAction))
69-
$netTask.Wait(-1) | Out-Null
70-
}
71-
72-
# make image object
73-
[Windows.Storage.StorageFile, Windows.Storage, ContentType = WindowsRuntime] | Out-Null
74-
$image = Await ([Windows.Storage.StorageFile]::GetFileFromPathAsync($newImagePath)) ([Windows.Storage.StorageFile])
75-
76-
# execute
77-
AwaitAction ([Windows.System.UserProfile.LockScreen]::SetImageFileAsync($image))
78-
79-
# cleanup
80-
Remove-Item $newImagePath
81-
}
82-
83-
Export-ModuleMember -Function Set-Theme, Set-ThemeMRU, Set-LockscreenImage

src/playbook/Executables/AtlasModules/Scripts/Modules/Utils/Utils.psm1

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function Write-Title {
22
param (
3-
[Parameter(Mandatory=$true)]
3+
[Parameter(Mandatory = $true)]
44
[string]$Text
55
)
66

@@ -35,9 +35,9 @@ enum MsgButtons {
3535
}
3636
function Read-MessageBox {
3737
param (
38-
[Parameter(Mandatory=$true)]
38+
[Parameter(Mandatory = $true)]
3939
[string]$Title,
40-
[Parameter(Mandatory=$true)]
40+
[Parameter(Mandatory = $true)]
4141
[string]$Body,
4242
[MsgIcon]$Icon = 'Info',
4343
[MsgButtons]$Buttons = 'YesNo',
@@ -50,7 +50,7 @@ function Read-MessageBox {
5050
$value += [MsgButtons].GetEnumValues().IndexOf([MsgButtons]"$Buttons") # buttons
5151
if (!$NoTopmost) { $value += 4096 } # topmost
5252

53-
$result = (New-Object -ComObject "Wscript.Shell").Popup($Body,$Timeout,$Title,$value)
53+
$result = (New-Object -ComObject "Wscript.Shell").Popup($Body, $Timeout, $Title, $value)
5454
$results = @{
5555
1 = 'Ok'
5656
2 = 'Cancel'
@@ -63,9 +63,105 @@ function Read-MessageBox {
6363

6464
if ($result) {
6565
return $results.$result
66-
} else {
66+
}
67+
else {
6768
return 'None'
6869
}
6970
}
7071

71-
Export-ModuleMember -Function Write-Title, Read-Pause, Read-MessageBox
72+
function Stop-ProcessesUnderRoots {
73+
param([string[]]$RootsLower)
74+
75+
foreach ($proc in Get-Process -ErrorAction SilentlyContinue) {
76+
if (-not $proc.Path) { continue }
77+
78+
$procPath = try {
79+
([System.IO.Path]::GetFullPath($proc.Path)).ToLowerInvariant()
80+
}
81+
catch {
82+
continue
83+
}
84+
85+
foreach ($root in $RootsLower) {
86+
if ($procPath.StartsWith($root)) {
87+
try {
88+
Stop-Process -Id $proc.Id -Force -ErrorAction Stop
89+
Wait-Process -Id $proc.Id -ErrorAction SilentlyContinue -Timeout 5
90+
}
91+
catch {
92+
continue
93+
}
94+
95+
break
96+
}
97+
}
98+
}
99+
}
100+
101+
function Stop-TasksUnderRoots {
102+
param([string[]]$RootsLower)
103+
104+
try {
105+
Import-Module ScheduledTasks -ErrorAction SilentlyContinue | Out-Null
106+
}
107+
catch {
108+
# Module may not be available on older systems; continue with fallbacks.
109+
}
110+
111+
$tasks = @()
112+
try {
113+
$tasks = Get-ScheduledTask -ErrorAction Stop
114+
}
115+
catch {
116+
$tasks = @()
117+
}
118+
119+
foreach ($task in $tasks) {
120+
$matchesRoot = $false
121+
122+
foreach ($action in $task.Actions) {
123+
$execute = $null
124+
if ($action.PSObject.Properties.Match('Execute').Count) {
125+
$execute = $action.Execute
126+
}
127+
elseif ($action.PSObject.Properties.Match('Path').Count) {
128+
$execute = $action.Path
129+
}
130+
131+
if (-not $execute) { continue }
132+
133+
$executeLower = try {
134+
([System.IO.Path]::GetFullPath($execute)).ToLowerInvariant()
135+
}
136+
catch {
137+
$null
138+
}
139+
140+
if (-not $executeLower) { continue }
141+
142+
foreach ($root in $RootsLower) {
143+
if ($executeLower.StartsWith($root)) {
144+
$matchesRoot = $true
145+
break
146+
}
147+
}
148+
149+
if ($matchesRoot) { break }
150+
}
151+
152+
if (-not $matchesRoot) { continue }
153+
154+
try {
155+
Stop-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -ErrorAction SilentlyContinue
156+
}
157+
catch {
158+
# Ignore and fall back to schtasks below.
159+
}
160+
}
161+
162+
foreach ($candidate in @('Force Timer Resolution', '\Force Timer Resolution')) {
163+
& schtasks.exe /End /TN $candidate 1>$null 2>$null
164+
}
165+
}
166+
167+
Export-ModuleMember -Function Write-Title, Read-Pause, Read-MessageBox, Stop-ProcessesUnderRoots, Stop-TasksUnderRoots

src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
2+
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
3+
}
4+
15
$windir = [Environment]::GetFolderPath('Windows')
26
& "$windir\AtlasModules\initPowerShell.ps1"
37
$atlasDesktop = "$windir\AtlasDesktop"
@@ -22,6 +26,7 @@ if ([System.Environment]::OSVersion.Version.Build -ge 22000) {
2226
& "$atlasDesktop\4. Interface Tweaks\File Explorer Customization\Gallery\Disable Gallery (default).cmd" /silent
2327

2428
# Set ThemeMRU (recent themes)
29+
Set-Theme -Path "$([Environment]::GetFolderPath('Windows'))\Resources\Themes\atlas-v0.5.x-dark.theme"
2530
Set-ThemeMRU | Out-Null
2631
}
2732

Binary file not shown.
Binary file not shown.
10.3 MB
Loading
9.99 MB
Loading
-581 KB
Binary file not shown.
10.1 MB
Loading

0 commit comments

Comments
 (0)