diff --git a/src/playbook/Configuration/tweaks/qol/appearance/atlas-theme.yml b/src/playbook/Configuration/tweaks/qol/appearance/atlas-theme.yml index 3a2cdc6293..0a4eb393f6 100644 --- a/src/playbook/Configuration/tweaks/qol/appearance/atlas-theme.yml +++ b/src/playbook/Configuration/tweaks/qol/appearance/atlas-theme.yml @@ -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 diff --git a/src/playbook/Executables/AtlasModules/Scripts/Modules/Themes/Themes.psm1 b/src/playbook/Executables/AtlasModules/Scripts/Modules/Themes/Themes.psm1 index 9826c278a9..9e11243255 100644 --- a/src/playbook/Executables/AtlasModules/Scripts/Modules/Themes/Themes.psm1 +++ b/src/playbook/Executables/AtlasModules/Scripts/Modules/Themes/Themes.psm1 @@ -93,4 +93,50 @@ function Set-ThemeMRU { } } -Export-ModuleMember -Function Set-Theme, Set-ThemeMRU \ No newline at end of file +# 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 \ No newline at end of file diff --git a/src/playbook/Executables/AtlasModules/Scripts/lockscreen.ps1 b/src/playbook/Executables/AtlasModules/Scripts/lockscreen.ps1 deleted file mode 100644 index e55b16ea71..0000000000 --- a/src/playbook/Executables/AtlasModules/Scripts/lockscreen.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -# Credit: https://superuser.com/a/1343640 -$imagePath = "$([Environment]::GetFolderPath('Windows'))\AtlasModules\Wallpapers\lockscreen.png" - -if (!(Test-Path $imagePath)) { - throw "Lockscreen not found." -} - -$newImagePath = [System.IO.Path]::GetTempPath() + (New-Guid).Guid + [System.IO.Path]::GetExtension($imagePath) -Copy-Item $imagePath $newImagePath -[Windows.System.UserProfile.LockScreen, Windows.System.UserProfile, ContentType = WindowsRuntime] | Out-Null -Add-Type -AssemblyName System.Runtime.WindowsRuntime -$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 -} -[Windows.Storage.StorageFile, Windows.Storage, ContentType = WindowsRuntime] | Out-Null -$image = Await ([Windows.Storage.StorageFile]::GetFileFromPathAsync($newImagePath)) ([Windows.Storage.StorageFile]) -AwaitAction ([Windows.System.UserProfile.LockScreen]::SetImageFileAsync($image)) -Remove-Item $newImagePath \ No newline at end of file diff --git a/src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1 b/src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1 index 51d3dbbc26..0d1b123f76 100644 --- a/src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1 +++ b/src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1 @@ -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 diff --git a/src/playbook/Executables/REFRESHENV.cmd b/src/playbook/Executables/REFRESHENV.cmd deleted file mode 100644 index ec4c158555..0000000000 --- a/src/playbook/Executables/REFRESHENV.cmd +++ /dev/null @@ -1,37 +0,0 @@ -@echo off -:: a batch script to refresh environment variables from the registry -:: source: https://raw.githubusercontent.com/chocolatey-archive/chocolatey/master/src/redirects/RefreshEnv.cmd -:: modified by Xyueta - -:main -echo/@echo off >"%TEMP%\_env.cmd" -call :GetRegEnv "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" >> "%TEMP%\_env.cmd" -call :GetRegEnv "HKCU\Environment">>"%TEMP%\_env.cmd" >> "%TEMP%\_env.cmd" -call :SetFromReg "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path Path_HKLM >> "%TEMP%\_env.cmd" -call :SetFromReg "HKCU\Environment" Path Path_HKCU >> "%TEMP%\_env.cmd" -echo/set "Path=%%Path_HKLM%%;%%Path_HKCU%%" >> "%TEMP%\_env.cmd" -del /f /q "%TEMP%\_envset.tmp" > nul 2>&1 -del /f /q "%TEMP%\_envget.tmp" > nul 2>&1 -set "OriginalUserName=%USERNAME%" -set "OriginalArchitecture=%PROCESSOR_ARCHITECTURE%" -call "%TEMP%\_env.cmd" -del /f /q "%TEMP%\_env.cmd" > nul 2>&1 -set "USERNAME=%OriginalUserName%" -set "PROCESSOR_ARCHITECTURE=%OriginalArchitecture%" -exit /b - -:SetFromReg -reg query "%~1" /v "%~2" > "%TEMP%\_envset.tmp" 2>NUL -for /f "usebackq skip=2 tokens=2,*" %%a in ("%TEMP%\_envset.tmp") do ( - echo/set "%~3=%%b" -) -goto :eof - -:GetRegEnv -reg query "%~1" > "%TEMP%\_envget.tmp" -for /f "usebackq skip=2" %%a in ("%TEMP%\_envget.tmp") do ( - if /I not "%%~a" == "Path" ( - call :SetFromReg "%~1" "%%~a" "%%~a" - ) -) -goto :eof \ No newline at end of file