Skip to content

Commit

Permalink
feat: Add default option for fallback theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Odilf authored and f-person committed Oct 9, 2024
1 parent 14cad96 commit 852732d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lua/auto-dark-mode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ local query_command
---@type "Linux" | "Darwin" | "Windows_NT" | "WSL"
local system

---@type "light" | "dark"
local default_theme;

-- Parses the query response for each system
---@param res string
---@return boolean
Expand All @@ -27,7 +30,13 @@ local function parse_query_response(res)
-- 0: no preference
-- 1: dark
-- 2: light
return string.match(res, "uint32 1") ~= nil
if string.match(res, "uint32 1") ~= nil then
return true
elseif string.match(res, "unit32 2") ~= nil then
return false
else
return default_theme == "dark"
end
elseif system == "Darwin" then
return res == "Dark"
elseif system == "Windows_NT" or system == "WSL" then
Expand Down Expand Up @@ -149,6 +158,7 @@ local function setup(options)
set_background("light")
end
update_interval = options.update_interval or 3000
default_theme = options.default or "dark"

init()
end
Expand Down
3 changes: 3 additions & 0 deletions lua/auto-dark-mode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
---@field set_light_mode nil | fun(): nil
-- Every `update_interval` milliseconds a theme check will be performed.
---@field update_interval number?
-- Optional. Default theme to use if the system theme can't be detected.
-- Useful for linux and environments without a desktop manager.
---@field default "light" | "dark" | nil

0 comments on commit 852732d

Please sign in to comment.