diff --git a/lua/auto-dark-mode/init.lua b/lua/auto-dark-mode/init.lua index 5794153..6934c1b 100644 --- a/lua/auto-dark-mode/init.lua +++ b/lua/auto-dark-mode/init.lua @@ -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 @@ -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 @@ -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 diff --git a/lua/auto-dark-mode/types.lua b/lua/auto-dark-mode/types.lua index ea61b44..fb7a5a0 100644 --- a/lua/auto-dark-mode/types.lua +++ b/lua/auto-dark-mode/types.lua @@ -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