Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use whiskers #16

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

$palette = [ordered]@{
"latte" = @{
"latte" = @{
"base" = "#eff1f5"
"mantle" = "#e6e9ef"
"crust" = "#dce0e8"
}
"frappe" = @{
"frappe" = @{
"base" = "#303446"
"mantle" = "#292c3c"
"crust" = "#232634"
Expand All @@ -17,7 +17,7 @@ $palette = [ordered]@{
"mantle" = "#1e2030"
"crust" = "#181926"
}
"mocha" = @{
"mocha" = @{
"base" = "#1e1e2e"
"mantle" = "#181825"
"crust" = "#11111b"
Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_default:
@just --list

build:
whiskers windows-files.tera
96 changes: 96 additions & 0 deletions windows-files.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
whiskers:
version: "2.5.0"
filename: "install.ps1"
---
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

$palette = [ordered]@{
{% for _, flavor in flavors -%}
"{{flavor.identifier}}" = @{
"base" = "#{{flavor.colors.base.hex}}"
"mantle" = "#{{flavor.colors.mantle.hex}}"
"crust" = "#{{flavor.colors.crust.hex}}"
{%- if not loop.last %}
}{% endif %}
{% endfor -%}
}
}

$flavorChoices = @()
$i = 1
foreach ($flavor in $palette.Keys) {
$flavorChoices += "$flavor (&$i)"
$i++
}

$flavor = $Host.UI.PromptForChoice("Flavor", "Which flavor do you want to use?", $flavorChoices, 3)
$colors = $palette[$flavor]

$flatAppearance = $Host.UI.PromptForChoice("Appearance", "Do you want to use the flat appearance?", ('&Yes', '&No'), 1)
$flatAppearance = $flatAppearance -eq 0

function Update-Config {
param ([string]$path, [hashtable]$colors)

if (-Not (Test-Path $path)) {
Write-Host "File not found: $path" -ForegroundColor Yellow
return
}
Write-Host "> Updating $path..."

$config = Get-Content -Path $path | ConvertFrom-Json -AsHashtable -Depth 10

$config.AppThemeAddressBarBackgroundColor = $colors["base"]
$config.AppThemeFileAreaBackgroundColor = $colors["base"]
$config.AppThemeSidebarBackgroundColor = $colors["mantle"]
$config.AppThemeBackgroundColor = If ($flatAppearance) { $colors["mantle"] } else { $colors["crust"] }

$config | ConvertTo-Json -Depth 10 | Set-Content -Path $path
}

# from https://files.community/docs/contributing/updates
$possiblePackageNames = @(
# Dev
"FilesDev_ykqwq8d6ps0ag",
# Classic
"Files_wvne1zexy08sa",
# Sideload
"Files_1y0xx7n9077q4",
# Sideload Preview
"FilesPreview_1y0xx7n9077q4",
# Microsoft Store
"49306atecsolution.FilesUWP_et10x9a9vyk8t"
)

$locatedPaths = @()
foreach ($name in $possiblePackageNames) {
$fullPath = "$env:LOCALAPPDATA\Packages\$name\LocalState\settings\user_settings.json"
if (Test-Path $fullPath) {
$locatedPaths += $fullPath
}
}

if ($locatedPaths.Count -eq 0) {
Write-Host "Could not locate the Files configuration file." -ForegroundColor Red
return
}

# shut down running Files processes
$runningProcesses = @()
$runningProcesses += Get-Process -Name "Files" -ErrorAction Ignore
$runningProcesses += Get-Process -Name "Files.App.Server" -ErrorAction Ignore
if ($runningProcesses.Count -gt 0) {
Write-Host "Killing running Files processes..." -ForegroundColor Yellow
$runningProcesses | ForEach-Object { $_.Kill() }
# wait for the processes to die
Start-Sleep -Seconds 3
}


foreach ($path in $locatedPaths) {
Update-Config -path $path -colors $colors
}

Write-Host "Catppuccin for Files has been installed! 🎉" -ForegroundColor Green