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).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
068ec860d3
commit
8c8c13167b
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 }
|
||||
Loading…
Add table
Add a link
Reference in a new issue