From 118a7b5338bd4e632dd58ab6ecd73707e813ae69 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 17 Nov 2023 00:08:18 -0800 Subject: [PATCH] Load theme files on first usage of Format-TerminalIcons --- Terminal-Icons/Private/Import-XmlThemes.ps1 | 13 +++++++++++++ Terminal-Icons/Public/Format-TerminalIcons.ps1 | 8 ++++++++ Terminal-Icons/Terminal-Icons.psm1 | 17 +++++++---------- 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 Terminal-Icons/Private/Import-XmlThemes.ps1 diff --git a/Terminal-Icons/Private/Import-XmlThemes.ps1 b/Terminal-Icons/Private/Import-XmlThemes.ps1 new file mode 100644 index 0000000..cc5e6fb --- /dev/null +++ b/Terminal-Icons/Private/Import-XmlThemes.ps1 @@ -0,0 +1,13 @@ +function Import-XmlThemes { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')] + param() + + $script:iconThemes = Import-Clixml -Path $script:moduleRoot/Data/iconThemes.xml + $script:colorThemes = Import-Clixml -Path $script:moduleRoot/Data/colorThemes.xml + $script:colorSequences = Import-Clixml -Path $script:moduleRoot/Data/colorSequences.xml + $script:glyphs = Import-Clixml -Path $script:moduleRoot/Data/glyphs.xml + $script:current.Themes = @{ + Color = $script:colorThemes + Icon = $script:iconThemes + } +} diff --git a/Terminal-Icons/Public/Format-TerminalIcons.ps1 b/Terminal-Icons/Public/Format-TerminalIcons.ps1 index e6280ba..62e5117 100644 --- a/Terminal-Icons/Public/Format-TerminalIcons.ps1 +++ b/Terminal-Icons/Public/Format-TerminalIcons.ps1 @@ -34,6 +34,14 @@ function Format-TerminalIcons { [hashtable]$CurrentSettings = $script:current ) + begin { + # Load the theme files on first invocation + if (-not $script:themeFilesLoaded) { + Import-XmlThemes + $script:themeFilesLoaded = $true + } + } + process { $displayInfo = Resolve-Icon $FileInfo if ($displayInfo.Icon) { diff --git a/Terminal-Icons/Terminal-Icons.psm1 b/Terminal-Icons/Terminal-Icons.psm1 index 37b7ff8..7a32ffe 100644 --- a/Terminal-Icons/Terminal-Icons.psm1 +++ b/Terminal-Icons/Terminal-Icons.psm1 @@ -49,18 +49,15 @@ $userThemePath = Get-ThemeStoragePath # Load or create default preferences $prefs = Import-Preferences -# Load builtin theme data -$iconThemes = Import-Clixml -Path $moduleRoot/Data/iconThemes.xml -$colorThemes = Import-Clixml -Path $moduleRoot/Data/colorThemes.xml -$colorSequences = Import-Clixml -Path $moduleRoot/Data/colorSequences.xml -$glyphs = Import-Clixml -Path $moduleRoot/Data/glyphs.xml +# To speed up module load times, the theme files are not imported on module load +# Instead, the they are loaded on the first invocation of `Format-TerminalIcons` +$themeFilesLoaded = $false +$iconThemes = @{} +$colorThemes = @{} +$colorSequences = @{} +$glyphs = @{} -# Set current settings $current = Get-CurrentSettings -$current.Themes = @{ - Color = $colorThemes - Icon = $iconThemes -} # As of 0.12.0, we no longer save the builtin theme files in the user theme folder ('devblackops_color.xml', 'devblackops_light_color.xml', 'devblackops_icon.xml').ForEach({