-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make applying theme faster & reliable
- Loading branch information
Showing
3 changed files
with
101 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/playbook/Executables/AtlasModules/Scripts/Modules/Themes/Themes.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
$windir = [Environment]::GetFolderPath('Windows') | ||
|
||
function Stop-ThemeProcesses { | ||
Get-Process 'SystemSettings', 'control' -EA 0 | Stop-Process -Force | ||
} | ||
|
||
function Set-Theme { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$Path | ||
) | ||
|
||
if (!((Get-Item $Path -EA 0).Extension -eq '.theme')) { | ||
throw "'$Path' is not a valid path to a theme file." | ||
} | ||
|
||
function Set-ThemeUsingExplorer { | ||
Write-Warning "Failed to apply theme using COM, falling back to launching file..." | ||
|
||
Stop-ThemeProcesses | ||
Start-Process -FilePath explorer -ArgumentList $Path | ||
Start-Sleep 10 | ||
} | ||
|
||
Add-Type @' | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
public static class ThemeManagerAPI | ||
{ | ||
public static void ApplyTheme(string themeFilePath) | ||
{ | ||
IThemeManager themeManager = new ThemeManagerClass(); | ||
themeManager.ApplyTheme(themeFilePath); | ||
} | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
[Guid("D23CC733-5522-406D-8DFB-B3CF5EF52A71")] | ||
[ComImport] | ||
public interface ITheme | ||
{ | ||
} | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
[Guid("0646EBBE-C1B7-4045-8FD0-FFD65D3FC792")] | ||
[ComImport] | ||
public interface IThemeManager | ||
{ | ||
[DispId(1610678272)] | ||
ITheme CurrentTheme { get; } | ||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] | ||
void ApplyTheme([MarshalAs(UnmanagedType.BStr)] string themeFilePath); | ||
} | ||
[TypeLibType(TypeLibTypeFlags.FCanCreate)] | ||
[Guid("C04B329E-5823-4415-9C93-BA44688947B0")] | ||
[ClassInterface(ClassInterfaceType.None)] | ||
[ComImport] | ||
public class ThemeManagerClass : IThemeManager | ||
{ | ||
[DispId(1610678272)] | ||
public virtual extern ITheme CurrentTheme { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] get; } | ||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] | ||
public virtual extern void ApplyTheme([MarshalAs(UnmanagedType.BStr)] string themeFilePath); | ||
} | ||
} | ||
'@ | ||
|
||
try { | ||
[ThemeManagerAPI]::ApplyTheme($Path) | ||
} catch { | ||
Set-ThemeUsingExplorer | ||
} | ||
|
||
Stop-ThemeProcesses | ||
} | ||
|
||
function Set-ThemeMRU { | ||
if ([System.Environment]::OSVersion.Version.Build -ge 22000) { | ||
Stop-ThemeProcesses | ||
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" -Name "ThemeMRU" -Value "$((@( | ||
"atlas-v0.4.x-dark.theme", | ||
"atlas-v0.4.x-light.theme", | ||
"atlas-v0.3.x-dark.theme", | ||
"atlas-v0.3.x-light.theme", | ||
"dark.theme", | ||
"aero.theme" | ||
) | ForEach-Object { "$windir\resources\Themes\$_" }) -join ';');" -Type String -Force | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function Set-Theme, Set-ThemeMRU |
16 changes: 0 additions & 16 deletions
16
src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters