J.A.R.V.I.S-rust/resources/commands/window/_window_helper.ps1

43 lines
1.4 KiB
PowerShell
Raw Normal View History

feat(commands): tier-1 PC tools — window mgmt, clipboard, notes, process killer, web search Five new portable Lua command packs. Bumps the total from 11 to 16 packs. All sandbox=full, all dispatched via jarvis.system.exec or jarvis.fs / jarvis.system APIs, no new Rust code, post_build.py --sync copies them under target/. cargo test -p jarvis-core --lib commands::tests passes 3/3 against all 16. window/ — 8 commands, single dispatch.lua keyed by jarvis.context.command_id: show_desktop / maximize_window / minimize_window / snap_left / snap_right / close_window / restore_all / task_view. _window_helper.ps1 P/Invokes user32!keybd_event for arbitrary combos like "win+d", "alt+f4", "win+shift+m". Uses one shared script per pack — much less duplication than the volume/ approach. clipboard_read/ — read_clipboard. Pulls jarvis.system.clipboard.get(), caps preview at 400 chars, then shells PowerShell System.Speech to actually speak it aloud (auto-picks the first ru-RU voice if present). Also fires a notify with a 120-char snippet. notes/ — add_note + open_notes. add_note strips the trigger phrase from the recognized voice, appends "[YYYY-MM-DD HH:MM] body\n" to %USERPROFILE%\Documents\jarvis-notes.txt via jarvis.fs.append (creates the file on first call). open_notes opens the file in the default editor via jarvis.system.open. Trigger list covers RU/EN/UA variants of "запиши" / "запомни" / "write down" / etc. process_kill/ — kill_process. Trigger-strips "закрой программу" / "убей процесс" / etc., then runs the remainder through an alias map (хром→ chrome, телега→telegram, спотифай→spotify, edge/edge/едж→msedge etc., 20+ entries) before invoking taskkill /F /IM. Notifies success/not-found. websearch/ — search_google / search_youtube / search_wiki / search_yandex. Single dispatch.lua reads jarvis.context.command_id to pick the base URL, URL-encodes the query (Lua %02X gsub, not relying on jarvis.http), opens the resulting link via jarvis.system.open (system default browser). Portability check: every helper resolves paths via $env:USERPROFILE / jarvis.context.command_path / jarvis.system.env — no hardcoded C:\ refs.
2026-05-15 11:27:02 +03:00
param(
[Parameter(Mandatory=$true)]
[string]$Combo
)
Add-Type -Name WinKey -Namespace Win32 -MemberDefinition @'
[DllImport("user32.dll")]
public static extern void keybd_event(byte vk, byte sc, uint flags, System.UIntPtr extra);
'@
$VK = @{
'win'=0x5B; 'lwin'=0x5B; 'rwin'=0x5C;
'alt'=0x12; 'ctrl'=0x11; 'shift'=0x10;
'a'=0x41; 'b'=0x42; 'c'=0x43; 'd'=0x44; 'e'=0x45; 'f'=0x46;
'g'=0x47; 'h'=0x48; 'i'=0x49; 'j'=0x4A; 'k'=0x4B; 'l'=0x4C;
'm'=0x4D; 'n'=0x4E; 'o'=0x4F; 'p'=0x50; 'q'=0x51; 'r'=0x52;
's'=0x53; 't'=0x54; 'u'=0x55; 'v'=0x56; 'w'=0x57; 'x'=0x58;
'y'=0x59; 'z'=0x5A;
'up'=0x26; 'down'=0x28; 'left'=0x25; 'right'=0x27;
'tab'=0x09; 'esc'=0x1B; 'enter'=0x0D; 'space'=0x20; 'home'=0x24; 'end'=0x23;
'f1'=0x70; 'f2'=0x71; 'f3'=0x72; 'f4'=0x73; 'f5'=0x74; 'f6'=0x75;
'f7'=0x76; 'f8'=0x77; 'f9'=0x78; 'f10'=0x79; 'f11'=0x7A; 'f12'=0x7B;
}
$parts = ($Combo.ToLower() -split '\+') | ForEach-Object { $_.Trim() }
$codes = @()
foreach ($k in $parts) {
if (-not $VK.ContainsKey($k)) {
Write-Error "Unknown key: $k (in combo: $Combo)"
exit 2
}
$codes += [byte][int]$VK[$k]
}
foreach ($c in $codes) {
[Win32.WinKey]::keybd_event($c, 0, 0, [UIntPtr]::Zero)
}
Start-Sleep -Milliseconds 35
[array]::Reverse($codes)
foreach ($c in $codes) {
[Win32.WinKey]::keybd_event($c, 0, 2, [UIntPtr]::Zero)
}