45 lines
1.4 KiB
Lua
45 lines
1.4 KiB
Lua
|
|
local lang = jarvis.context.language
|
|||
|
|
local cmd_id = jarvis.context.command_id
|
|||
|
|
|
|||
|
|
local ps = [[
|
|||
|
|
$ErrorActionPreference = 'Stop'
|
|||
|
|
try {
|
|||
|
|
$cur = (Get-WmiObject -Namespace root\WMI -Class WmiMonitorBrightness -ErrorAction Stop).CurrentBrightness
|
|||
|
|
} catch {
|
|||
|
|
Write-Output 'no_wmi'
|
|||
|
|
exit 0
|
|||
|
|
}
|
|||
|
|
$target = switch ('__OP__') {
|
|||
|
|
'up' { [Math]::Min(100, $cur + 20) }
|
|||
|
|
'down' { [Math]::Max(0, $cur - 20) }
|
|||
|
|
'max' { 100 }
|
|||
|
|
'min' { 10 }
|
|||
|
|
default { $cur }
|
|||
|
|
}
|
|||
|
|
$m = Get-WmiObject -Namespace root\WMI -Class WmiMonitorBrightnessMethods
|
|||
|
|
$m.WmiSetBrightness(1, $target) | Out-Null
|
|||
|
|
Write-Output $target
|
|||
|
|
]]
|
|||
|
|
|
|||
|
|
local op = ({
|
|||
|
|
brightness_up = "up", brightness_down = "down",
|
|||
|
|
brightness_max = "max", brightness_min = "min",
|
|||
|
|
})[cmd_id] or "up"
|
|||
|
|
|
|||
|
|
local script = ps:gsub("__OP__", op)
|
|||
|
|
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -Command "%s"', script:gsub('"', '\\"'))
|
|||
|
|
local res = jarvis.system.exec(cmd)
|
|||
|
|
local out = (res.stdout or ""):gsub("[\r\n]+$", ""):gsub("^%s+", "")
|
|||
|
|
|
|||
|
|
if out == "no_wmi" or not res.success then
|
|||
|
|
jarvis.system.notify("Brightness",
|
|||
|
|
lang == "ru" and "Не поддерживается на этом дисплее"
|
|||
|
|
or "Not supported on this display")
|
|||
|
|
jarvis.audio.play_error()
|
|||
|
|
return { chain = false }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
jarvis.system.notify(lang == "ru" and "Яркость" or "Brightness", out .. "%")
|
|||
|
|
jarvis.audio.play_ok()
|
|||
|
|
return { chain = false }
|