feat: lock_workstation + screenshot + net_info packs + modernise power pack
Three handy daily-driver packs + cleanup of the oldest power/act.lua.
power pack — added lock_workstation (resources/commands/power/)
- New command id: lock_workstation
- Phrase: "заблокируй компьютер" / "заблокируй пк" / "заблокируй экран"
- Action: rundll32.exe user32.dll,LockWorkStation
- Sandbox: full (needs system.exec)
- act.lua modernised:
* No more inline PowerShell SAPI escape chain — now uses jarvis.speak
(TTS backend abstraction respects user's chosen Piper/SAPI/Silero).
* Returns via jarvis.cmd.ok/error helpers.
* Logged warning for failing cmds without crashing the pack.
* Cleaner per-action `warn` flag controls the "say cancel to abort" hint.
screenshot pack (NEW, resources/commands/screenshot/, 2 commands)
- "сделай скрин" / "сделай скриншот" → screenshot.to_clipboard
Uses [System.Windows.Forms.Clipboard]::SetImage() with a captured Bitmap.
No file artifact, no LLM call — pure capture, fastest path.
- "сохрани скрин" → screenshot.to_file
Saves to ~/Pictures/Screenshots/jarvis-YYYYMMDD-HHMMSS.png.
Creates dir if missing. Notifies with full path.
- Distinct from vision/ pack which captures + describes via LLM.
net_info pack (NEW, resources/commands/net_info/, 3 commands)
- "какая сеть" / "какой wifi" → net.wifi_ssid
Parses `netsh wlan show interfaces` for SSID line (RU + EN field names).
- "мой IP" / "локальный IP" → net.local_ip
PowerShell Get-NetIPAddress, filters out 127.* and 169.* (link-local).
- "внешний IP" / "публичный IP" → net.public_ip
Hits api.ipify.org via jarvis.http.get (no key, plain text).
Tests: 99/99 pass (commands::tests auto-validates new packs).
Build: cargo build --release -p jarvis-app green.
Pack count: 59 → 62 (intro/echo from prior commit + screenshot + net_info; power
already counted — added a command, not a pack).
This commit is contained in:
parent
77063fed86
commit
41eb47724c
8 changed files with 243 additions and 25 deletions
36
resources/commands/screenshot/to_file.lua
Normal file
36
resources/commands/screenshot/to_file.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
-- Capture full screen → save PNG under ~/Pictures/Screenshots/jarvis-YYYYMMDD-HHMMSS.png
|
||||
local t = jarvis.context.time
|
||||
local stamp = string.format("%04d%02d%02d-%02d%02d%02d",
|
||||
t.year, t.month, t.day, t.hour, t.minute, t.second or 0)
|
||||
|
||||
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
||||
local dir = userprofile .. "\\Pictures\\Screenshots"
|
||||
local path = string.format("%s\\jarvis-%s.png", dir, stamp)
|
||||
|
||||
-- Ensure dir exists
|
||||
jarvis.fs.mkdir(dir)
|
||||
|
||||
local escaped = path:gsub("'", "''")
|
||||
local ps = string.format([[
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
$bounds = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
|
||||
$bmp = New-Object System.Drawing.Bitmap $bounds.Width, $bounds.Height
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)
|
||||
$bmp.Save('%s', [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$g.Dispose(); $bmp.Dispose()
|
||||
]], escaped)
|
||||
|
||||
local res = jarvis.system.exec(string.format(
|
||||
'powershell -NoProfile -ExecutionPolicy Bypass -Command "%s"',
|
||||
ps:gsub('"', '\\"'):gsub("\r?\n", "; ")
|
||||
))
|
||||
|
||||
if not res.success then
|
||||
jarvis.log("warn", "screenshot to file failed: " .. tostring(res.stderr):sub(1, 200))
|
||||
return jarvis.cmd.error("Не получилось сохранить скриншот.")
|
||||
end
|
||||
|
||||
jarvis.system.notify("Скриншот", path)
|
||||
return jarvis.cmd.ok("Скриншот сохранён в папку Скриншоты.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue