skyjake / lagrange

A Beautiful Gemini Client
https://gmi.skyjake.fi/lagrange/
BSD 2-Clause "Simplified" License
1.19k stars 62 forks source link

Automatically switch to dark theme on Windows #591

Open quienn opened 1 year ago

quienn commented 1 year ago

The iOS build automatically switches themes according to the current system color scheme, and if IIRC the macOS build does it too. I wonder, could this feature land on Windows too? I think it's pretty useful for folks like me that use AutoDarkMode to switch color schemes on a schedule.

skyjake commented 1 year ago

This should be doable.

However, there is a small wrinkle in that this feature requires Windows 10 while the app should run on Windows 7, too. Something to take into consideration...

quienn commented 1 year ago

There's the AppsUseLightTheme registry key (located at Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize). By being accesible through the registry i think it should work on previous versions too.

Wish I could help with the implementation but I don't really know any C. 😕 Thank you for this great piece of software though! Hope my suggestion was helpful.

quienn commented 2 months ago

I've read through the code and it seems like the app already does some form of dark mode detection, which is for the title bar only. Could it be possible to also enable the option in the UI and execute a os.theme.changed command like in MacOS & iOS?


Edit: In the mean time, if anyone is interested in this feature and is already a user of Windows Auto Dark Mode, I wrote a PowerShell script for it:

# Lagrange.psm1
enum Theme {
  black = 0
  dark = 1
  light = 2
  white = 3
}

function Set-LagrangeTheme {
  param(
    [Theme]$Theme,
    [string]$LagrangePath = "C:\Program Files\Lagrange\lagrange.exe",
    [string]$LagrangeConfig = "$env:APPDATA\fi.skyjake.Lagrange"
  )

  if (Get-Process -Name "lagrange" -ErrorAction Ignore) {
    Write-Warning "Changing theme for running Lagrange instance..."
    Start-Process -FilePath $LagrangePath -ArgumentList "--theme $Theme"
  }
  else {
    $ConfigFile = Join-Path -Path $LagrangeConfig -ChildPath "prefs.cfg"
    $Config = Get-Content -Path $ConfigFile -Raw
    $Config = $Config -replace 'theme\.set arg:\d', "theme.set arg:$($Theme.value__)"
    Set-Content -Path $ConfigFile -Value $Config
  }
}

Export-ModuleMember -Function Set-LagrangeTheme

Then, ADM's scripts.yaml should look like this:

# $env:APPDATA\AutoDarkMode\scripts.yaml
...
  Scripts:
    - Name: Lagrange
      Command: pwsh
      WorkingDirectory: C:\Path\To\Scripts\Directory
      ArgsLight:
        [
          -NoLogo,
          -NoProfile,
          -Command,
          "Import-Module .\\Lagrange.psm1; Set-LagrangeTheme light",
        ]
      ArgsDark:
        [
          -NoLogo,
          -NoProfile,
          -Command,
          "Import-Module .\\Lagrange.psm1; Set-LagrangeTheme dark",
        ]
      AllowedSources: [Any]
      TimeoutMillis: