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
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue