dotfiles/multimedia/.config/mpv/scripts/battery.lua

38 lines
908 B
Lua
Raw Normal View History

-- If the laptop is on battery, the profile 'lq' will be loaded; otherwise 'hq' is used
2023-06-15 08:12:30 +00:00
local mp = require("mp")
2023-05-23 13:31:17 +00:00
local SHOULD_ADJUST = false
2020-05-13 15:41:14 +00:00
local lqprofile = "lowquality"
local hqprofile = "highquality"
local function powerstate()
2023-06-15 08:12:30 +00:00
local f = io.open("/sys/class/power_supply/AC/online")
if f == nil then
return
end
local t = f:read("*n")
f:close()
return t
end
2020-05-13 15:41:14 +00:00
local function adjust()
2023-06-15 08:12:30 +00:00
if not SHOULD_ADJUST then
return
end
2023-05-23 13:31:17 +00:00
2023-06-15 08:12:30 +00:00
local state = powerstate()
-- this actually overrides automatically applied profiles
-- like 'protocol.http'
if state == 0 then
mp.set_property("profile", lqprofile)
mp.msg.info("[quality] running battery, setting low-quality options.")
mp.osd_message("[quality] LQ")
else
mp.set_property("profile", hqprofile)
mp.msg.info("[quality] running ac, setting high-quality options.")
mp.osd_message("[quality] HQ")
end
end
2020-05-13 15:41:14 +00:00
mp.add_hook("on_load", 1, adjust)