Skip to content

Commit

Permalink
refactor: move lockscreen.ps1 to module
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Aug 28, 2024
1 parent 89d3102 commit 9a6a018
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ actions:
exeDir: true
wait: true
- !powerShell:
command: '& ".\AtlasModules\Scripts\LOCKSCREEN.ps1"'
command: |
.\AtlasModules\initPowerShell.ps1
Set-LockscreenImage
exeDir: true
wait: true
runas: currentUserElevated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,50 @@ function Set-ThemeMRU {
}
}

Export-ModuleMember -Function Set-Theme, Set-ThemeMRU
# Credit: https://superuser.com/a/1343640
function Set-LockscreenImage {
param (
[ValidateNotNullOrEmpty()]
[string]$Path = "$([Environment]::GetFolderPath('Windows'))\AtlasModules\Wallpapers\lockscreen.png"
)

if (!(Test-Path $Path)) {
throw "Path ('$Path') for lockscreen not found."
}
$newImagePath = [System.IO.Path]::GetTempPath() + (New-Guid).Guid + [System.IO.Path]::GetExtension($Path)
Copy-Item $Path $newImagePath

# setup WinRT namespaces
Add-Type -AssemblyName System.Runtime.WindowsRuntime
[Windows.System.UserProfile.LockScreen, Windows.System.UserProfile, ContentType = WindowsRuntime] | Out-Null

# setup async
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? {
$_.Name -eq 'AsTask' -and
$_.GetParameters().Count -eq 1 -and
$_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1'
})[0]
Function Await($WinRtTask, $ResultType) {
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
$netTask.Result
}
Function AwaitAction($WinRtAction) {
$asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
$netTask = $asTask.Invoke($null, @($WinRtAction))
$netTask.Wait(-1) | Out-Null
}

# make image object
[Windows.Storage.StorageFile, Windows.Storage, ContentType = WindowsRuntime] | Out-Null
$image = Await ([Windows.Storage.StorageFile]::GetFileFromPathAsync($newImagePath)) ([Windows.Storage.StorageFile])

# execute
AwaitAction ([Windows.System.UserProfile.LockScreen]::SetImageFileAsync($image))

# cleanup
Remove-Item $newImagePath
}

Export-ModuleMember -Function Set-Theme, Set-ThemeMRU, Set-LockscreenImage
27 changes: 0 additions & 27 deletions src/playbook/Executables/AtlasModules/Scripts/lockscreen.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if ([System.Environment]::OSVersion.Version.Build -ge 22000) {
}

# Set lockscreen wallpaper
& "$atlasModules\Scripts\lockscreen.ps1"
Set-LockscreenImage

# Disable 'Network' in navigation pane
reg import "$atlasDesktop\3. General Configuration\File Sharing\Network Navigation Pane\Disable Network Navigation Pane (default).reg" *>$null
Expand Down
37 changes: 0 additions & 37 deletions src/playbook/Executables/REFRESHENV.cmd

This file was deleted.

0 comments on commit 9a6a018

Please sign in to comment.