Skip to content

Commit 03e05eb

Browse files
committed
style: format using stylua
1 parent c439798 commit 03e05eb

File tree

2 files changed

+35
-39
lines changed

2 files changed

+35
-39
lines changed

lua/auto-dark-mode/init.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ M.init = function()
9595
"string:color-scheme",
9696
}
9797

98-
if vim.fn.executable("dbus-monitor") ~= 0 then
99-
M.state.monitor_command = {
100-
"dbus-monitor",
101-
"--session",
102-
"type=signal,interface=org.freedesktop.portal.Settings,member=SettingChanged,path=/org/freedesktop/portal/desktop,arg0='org.freedesktop.appearance',arg1='color-scheme'",
103-
}
104-
105-
end
98+
if vim.fn.executable("dbus-monitor") ~= 0 then
99+
M.state.monitor_command = {
100+
"dbus-monitor",
101+
"--session",
102+
"type=signal,interface=org.freedesktop.portal.Settings,member=SettingChanged,path=/org/freedesktop/portal/desktop,arg0='org.freedesktop.appearance',arg1='color-scheme'",
103+
}
104+
end
106105
elseif M.state.system == "Windows_NT" or M.state.system == "WSL" then
107106
local reg = "reg.exe"
108107

lua/auto-dark-mode/interval.lua

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ local uv = vim.uv or vim.loop
1616
---@return Appearance?
1717
local function parse_query_response(stdout, stderr)
1818
if M.state.system == "Linux" then
19-
if stderr ~= "" then
20-
return nil;
21-
end
19+
if stderr ~= "" then
20+
return nil
21+
end
2222

2323
-- https://github.com/flatpak/xdg-desktop-portal/blob/c0f0eb103effdcf3701a1bf53f12fe953fbf0b75/data/org.freedesktop.impl.portal.Settings.xml#L32-L46
2424
-- 0: no preference
@@ -71,27 +71,25 @@ end
7171
-- The callback is called with the plaintext stdout response of the query.
7272
---@param callback? fun(stdout: string, stderr: string): nil
7373
---@return nil
74-
M.monitor_dark_mode = function (callback)
75-
-- if no callback is provided, use a no-op
76-
callback = callback or function() end
77-
78-
vim.fn.jobstart(M.state.monitor_command,
79-
{
80-
on_stdout = function (_, data, _)
81-
data = table.concat(data, "")
82-
83-
if string.match(data, "uint32") then
84-
-- check if this was a signal update with a new value,
85-
-- as otherwise the fallback option will be incorrectly triggered
86-
callback(data, "")
87-
end
88-
end,
89-
on_stderr = function (_, data, _)
90-
data = table.concat(data, "")
91-
callback("", data)
92-
end
93-
}
94-
);
74+
M.monitor_dark_mode = function(callback)
75+
-- if no callback is provided, use a no-op
76+
callback = callback or function() end
77+
78+
vim.fn.jobstart(M.state.monitor_command, {
79+
on_stdout = function(_, data, _)
80+
data = table.concat(data, "")
81+
82+
if string.match(data, "uint32") then
83+
-- check if this was a signal update with a new value,
84+
-- as otherwise the fallback option will be incorrectly triggered
85+
callback(data, "")
86+
end
87+
end,
88+
on_stderr = function(_, data, _)
89+
data = table.concat(data, "")
90+
callback("", data)
91+
end,
92+
})
9593
end
9694

9795
-- Uses a subprocess to query the system for the current dark mode setting.
@@ -178,13 +176,12 @@ M.start = function(options, state)
178176
-- act as if the timer has finished once to instantly sync on startup
179177
timer_callback()
180178

181-
-- if the system supports monitoring, prefer that over polling updates
182-
if next(M.state.monitor_command) ~= nil then
183-
M.monitor_dark_mode(M.parse_callback)
184-
else
185-
M.start_timer()
186-
end
187-
179+
-- if the system supports monitoring, prefer that over polling updates
180+
if next(M.state.monitor_command) ~= nil then
181+
M.monitor_dark_mode(M.parse_callback)
182+
else
183+
M.start_timer()
184+
end
188185
end
189186

190187
return M

0 commit comments

Comments
 (0)