feat(commands): add media controls + system info packs
media/ — play_pause, next, prev, stop via user32!keybd_event (VK_MEDIA_*
0xB0..0xB3). Helper _media_helper.ps1 mirrors the volume/ pack pattern,
so the same C# P/Invoke style works for the four standard media keys
without needing any external tooling. Catches Spotify, foobar, browsers,
Yandex Music PWA — anything that responds to system media keys.
sysinfo/ — battery / time / cpu / ram / disk and an "all" combo.
_sysinfo.ps1 uses CIM queries (Win32_Battery, Win32_OperatingSystem,
Win32_LogicalDisk, Win32_Processor + Win32_PerfFormattedData_PerfOS_
Processor) — no external deps. Time is rendered in ru-RU culture
("01:17, 15 мая, пятница"). Battery falls back to a friendly "no
battery, looks like a desktop" when Win32_Battery is empty. SystemDrive
env var resolves the right disk on non-C:/ installs.
Each sysinfo command notifies the line as a Windows toast and logs it.
Triggered locally: sysinfo_all currently reports:
Сейчас: 01:17, 15 мая, пятница
Батарея не обнаружена (видимо, десктоп)
CPU: AMD Ryzen 7 5700X3D 8-Core Processor, загрузка 4%
RAM: 23.4 из 47.9 ГБ (49% занято)
Диск C:: свободно 118.2 из 1906.8 ГБ
Total command packs is now 9 (verified via jarvis-gui startup log).
Portability: all PowerShell helpers use $env:SystemDrive and CIM
classes that ship with every Windows install; Lua wrappers resolve
the helper path via jarvis.context.command_path (no hardcoded user
profile paths or absolute C:\ refs).
This commit is contained in:
parent
24457ad6c9
commit
b257f03f65
14 changed files with 474 additions and 0 deletions
20
resources/commands/media/_media_helper.ps1
Normal file
20
resources/commands/media/_media_helper.ps1
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[ValidateSet("play_pause","next","prev","stop")]
|
||||
[string]$Action
|
||||
)
|
||||
|
||||
Add-Type -Name MediaKey -Namespace Win32 -MemberDefinition @'
|
||||
[DllImport("user32.dll")]
|
||||
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, System.UIntPtr dwExtraInfo);
|
||||
'@
|
||||
|
||||
$vk = switch ($Action) {
|
||||
"play_pause" { 0xB3 }
|
||||
"next" { 0xB0 }
|
||||
"prev" { 0xB1 }
|
||||
"stop" { 0xB2 }
|
||||
}
|
||||
|
||||
[Win32.MediaKey]::keybd_event($vk, 0, 0, [UIntPtr]::Zero)
|
||||
[Win32.MediaKey]::keybd_event($vk, 0, 2, [UIntPtr]::Zero)
|
||||
103
resources/commands/media/command.toml
Normal file
103
resources/commands/media/command.toml
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
[[commands]]
|
||||
id = "media_play_pause"
|
||||
type = "lua"
|
||||
script = "play_pause.lua"
|
||||
sandbox = "full"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"пауза",
|
||||
"поставь на паузу",
|
||||
"продолжи",
|
||||
"включи музыку",
|
||||
"запусти музыку",
|
||||
"плей",
|
||||
]
|
||||
en = [
|
||||
"pause",
|
||||
"play",
|
||||
"resume",
|
||||
"play music",
|
||||
]
|
||||
ua = [
|
||||
"пауза",
|
||||
"продовж",
|
||||
"включи музику",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "media_next"
|
||||
type = "lua"
|
||||
script = "next_track.lua"
|
||||
sandbox = "full"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"следующий трек",
|
||||
"следующая песня",
|
||||
"переключи трек",
|
||||
"следующая",
|
||||
"дальше",
|
||||
]
|
||||
en = [
|
||||
"next track",
|
||||
"next song",
|
||||
"skip",
|
||||
"next",
|
||||
]
|
||||
ua = [
|
||||
"наступний трек",
|
||||
"наступна пісня",
|
||||
"далі",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "media_prev"
|
||||
type = "lua"
|
||||
script = "prev_track.lua"
|
||||
sandbox = "full"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"предыдущий трек",
|
||||
"предыдущая песня",
|
||||
"верни песню",
|
||||
"назад",
|
||||
]
|
||||
en = [
|
||||
"previous track",
|
||||
"previous song",
|
||||
"back",
|
||||
]
|
||||
ua = [
|
||||
"попередній трек",
|
||||
"назад",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "media_stop"
|
||||
type = "lua"
|
||||
script = "stop_media.lua"
|
||||
sandbox = "full"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"стоп музыка",
|
||||
"останови музыку",
|
||||
"выключи музыку",
|
||||
]
|
||||
en = [
|
||||
"stop music",
|
||||
"stop playback",
|
||||
]
|
||||
ua = [
|
||||
"стоп музика",
|
||||
"вимкни музику",
|
||||
]
|
||||
13
resources/commands/media/next_track.lua
Normal file
13
resources/commands/media/next_track.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_media_helper.ps1"
|
||||
local cmd = string.format(
|
||||
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action next',
|
||||
helper
|
||||
)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
if res.success then
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "media next failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/media/play_pause.lua
Normal file
13
resources/commands/media/play_pause.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_media_helper.ps1"
|
||||
local cmd = string.format(
|
||||
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action play_pause',
|
||||
helper
|
||||
)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
if res.success then
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "play/pause failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/media/prev_track.lua
Normal file
13
resources/commands/media/prev_track.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_media_helper.ps1"
|
||||
local cmd = string.format(
|
||||
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action prev',
|
||||
helper
|
||||
)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
if res.success then
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "media prev failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/media/stop_media.lua
Normal file
13
resources/commands/media/stop_media.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_media_helper.ps1"
|
||||
local cmd = string.format(
|
||||
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action stop',
|
||||
helper
|
||||
)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
if res.success then
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "media stop failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
69
resources/commands/sysinfo/_sysinfo.ps1
Normal file
69
resources/commands/sysinfo/_sysinfo.ps1
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[ValidateSet("battery","time","cpu","ram","disk","all")]
|
||||
[string]$Topic
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
function Get-BatteryInfo {
|
||||
$b = Get-CimInstance -ClassName Win32_Battery
|
||||
if (-not $b) { return "Батарея не обнаружена (видимо, десктоп)" }
|
||||
$pct = [int]$b.EstimatedChargeRemaining
|
||||
$status = switch ($b.BatteryStatus) {
|
||||
1 { "разряжается" }
|
||||
2 { "от сети" }
|
||||
3 { "заряжена" }
|
||||
4 { "низкий заряд" }
|
||||
5 { "критический заряд" }
|
||||
default { "статус $($b.BatteryStatus)" }
|
||||
}
|
||||
return "Батарея: $pct%, $status"
|
||||
}
|
||||
|
||||
function Get-TimeInfo {
|
||||
$ru = [System.Globalization.CultureInfo]::GetCultureInfo("ru-RU")
|
||||
$now = Get-Date
|
||||
return "Сейчас: " + $now.ToString("HH:mm, dd MMMM, dddd", $ru)
|
||||
}
|
||||
|
||||
function Get-CpuInfo {
|
||||
$cpu = Get-CimInstance -ClassName Win32_Processor | Select-Object -First 1
|
||||
$load = (Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor -Filter "Name='_Total'" -ErrorAction SilentlyContinue).PercentProcessorTime
|
||||
if ($null -eq $load) { $load = $cpu.LoadPercentage }
|
||||
return "CPU: $($cpu.Name.Trim()), загрузка $load%"
|
||||
}
|
||||
|
||||
function Get-RamInfo {
|
||||
$os = Get-CimInstance -ClassName Win32_OperatingSystem
|
||||
$totalGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 1)
|
||||
$freeGB = [math]::Round($os.FreePhysicalMemory / 1MB, 1)
|
||||
$usedGB = [math]::Round($totalGB - $freeGB, 1)
|
||||
$pct = [int](($usedGB / $totalGB) * 100)
|
||||
return "RAM: $usedGB из $totalGB ГБ ($pct% занято)"
|
||||
}
|
||||
|
||||
function Get-DiskInfo {
|
||||
$sys = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='$($env:SystemDrive)'"
|
||||
if (-not $sys) {
|
||||
$sys = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | Select-Object -First 1
|
||||
}
|
||||
$freeGB = [math]::Round($sys.FreeSpace / 1GB, 1)
|
||||
$totalGB = [math]::Round($sys.Size / 1GB, 1)
|
||||
return "Диск $($sys.DeviceID): свободно $freeGB из $totalGB ГБ"
|
||||
}
|
||||
|
||||
switch ($Topic) {
|
||||
"battery" { Get-BatteryInfo }
|
||||
"time" { Get-TimeInfo }
|
||||
"cpu" { Get-CpuInfo }
|
||||
"ram" { Get-RamInfo }
|
||||
"disk" { Get-DiskInfo }
|
||||
"all" {
|
||||
Get-TimeInfo
|
||||
Get-BatteryInfo
|
||||
Get-CpuInfo
|
||||
Get-RamInfo
|
||||
Get-DiskInfo
|
||||
}
|
||||
}
|
||||
13
resources/commands/sysinfo/all.lua
Normal file
13
resources/commands/sysinfo/all.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_sysinfo.ps1"
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic all', helper)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local text = (res.stdout or ""):gsub("[\r\n]+$", "")
|
||||
if res.success and text ~= "" then
|
||||
jarvis.system.notify("Статус системы", text)
|
||||
jarvis.log("info", text)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "sysinfo all failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/sysinfo/battery.lua
Normal file
13
resources/commands/sysinfo/battery.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_sysinfo.ps1"
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic battery', helper)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local text = (res.stdout or ""):gsub("[\r\n]+$", "")
|
||||
if res.success and text ~= "" then
|
||||
jarvis.system.notify("Батарея", text)
|
||||
jarvis.log("info", text)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "battery info failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
152
resources/commands/sysinfo/command.toml
Normal file
152
resources/commands/sysinfo/command.toml
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
[[commands]]
|
||||
id = "sysinfo_battery"
|
||||
type = "lua"
|
||||
script = "battery.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"сколько заряда",
|
||||
"сколько батарея",
|
||||
"заряд батареи",
|
||||
"сколько процентов",
|
||||
]
|
||||
en = [
|
||||
"battery level",
|
||||
"how much battery",
|
||||
"battery status",
|
||||
]
|
||||
ua = [
|
||||
"скільки заряду",
|
||||
"заряд батареї",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "sysinfo_time"
|
||||
type = "lua"
|
||||
script = "time.lua"
|
||||
sandbox = "full"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"сколько времени",
|
||||
"который час",
|
||||
"сколько сейчас времени",
|
||||
"какой день",
|
||||
"какое сегодня число",
|
||||
]
|
||||
en = [
|
||||
"what time is it",
|
||||
"current time",
|
||||
"what day is it",
|
||||
"what is the date",
|
||||
]
|
||||
ua = [
|
||||
"котра година",
|
||||
"скільки часу",
|
||||
"який сьогодні день",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "sysinfo_cpu"
|
||||
type = "lua"
|
||||
script = "cpu.lua"
|
||||
sandbox = "full"
|
||||
timeout = 8000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"загрузка процессора",
|
||||
"сколько процессор",
|
||||
"нагрузка цпу",
|
||||
"что с процессором",
|
||||
]
|
||||
en = [
|
||||
"cpu load",
|
||||
"cpu usage",
|
||||
"how is cpu",
|
||||
]
|
||||
ua = [
|
||||
"завантаження процесора",
|
||||
"як процесор",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "sysinfo_ram"
|
||||
type = "lua"
|
||||
script = "ram.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"сколько памяти",
|
||||
"сколько оперативки",
|
||||
"загрузка оперативки",
|
||||
"сколько свободной памяти",
|
||||
]
|
||||
en = [
|
||||
"how much ram",
|
||||
"ram usage",
|
||||
"memory usage",
|
||||
]
|
||||
ua = [
|
||||
"скільки пам'яті",
|
||||
"скільки оперативки",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "sysinfo_disk"
|
||||
type = "lua"
|
||||
script = "disk.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"сколько свободно на диске",
|
||||
"сколько места на диске",
|
||||
"сколько места на жёстком",
|
||||
"сколько свободно",
|
||||
]
|
||||
en = [
|
||||
"free disk space",
|
||||
"how much disk space",
|
||||
"disk usage",
|
||||
]
|
||||
ua = [
|
||||
"скільки вільно на диску",
|
||||
"скільки місця на диску",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "sysinfo_all"
|
||||
type = "lua"
|
||||
script = "all.lua"
|
||||
sandbox = "full"
|
||||
timeout = 10000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"статус системы",
|
||||
"что с компьютером",
|
||||
"состояние пк",
|
||||
"что по системе",
|
||||
"статус",
|
||||
]
|
||||
en = [
|
||||
"system status",
|
||||
"how is the system",
|
||||
"pc status",
|
||||
]
|
||||
ua = [
|
||||
"статус системи",
|
||||
"стан пк",
|
||||
]
|
||||
13
resources/commands/sysinfo/cpu.lua
Normal file
13
resources/commands/sysinfo/cpu.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_sysinfo.ps1"
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic cpu', helper)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local text = (res.stdout or ""):gsub("[\r\n]+$", "")
|
||||
if res.success and text ~= "" then
|
||||
jarvis.system.notify("CPU", text)
|
||||
jarvis.log("info", text)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "cpu info failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/sysinfo/disk.lua
Normal file
13
resources/commands/sysinfo/disk.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_sysinfo.ps1"
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic disk', helper)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local text = (res.stdout or ""):gsub("[\r\n]+$", "")
|
||||
if res.success and text ~= "" then
|
||||
jarvis.system.notify("Диск", text)
|
||||
jarvis.log("info", text)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "disk info failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/sysinfo/ram.lua
Normal file
13
resources/commands/sysinfo/ram.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_sysinfo.ps1"
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic ram', helper)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local text = (res.stdout or ""):gsub("[\r\n]+$", "")
|
||||
if res.success and text ~= "" then
|
||||
jarvis.system.notify("Память", text)
|
||||
jarvis.log("info", text)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "ram info failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
13
resources/commands/sysinfo/time.lua
Normal file
13
resources/commands/sysinfo/time.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
local helper = jarvis.context.command_path .. "\\_sysinfo.ps1"
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic time', helper)
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local text = (res.stdout or ""):gsub("[\r\n]+$", "")
|
||||
if res.success and text ~= "" then
|
||||
jarvis.system.notify("Время", text)
|
||||
jarvis.log("info", text)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "time info failed: " .. tostring(res.stderr))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
return { chain = false }
|
||||
Loading…
Add table
Add a link
Reference in a new issue