-- Power-management dispatcher: shutdown/restart/sleep/hibernate/logoff/cancel/lock. -- All commands share this script; behaviour selected by jarvis.context.command_id. -- Modernised to use jarvis.speak (TTS backend abstraction) + jarvis.cmd helpers. local cmd_id = jarvis.context.command_id local lang = jarvis.context.language local actions = { shutdown_pc = { cmd = 'shutdown.exe /s /t 30 /c "J.A.R.V.I.S.: shutdown in 30s. Say cancel to abort."', label = lang == "ru" and "Выключение через 30 секунд" or "Shutdown in 30 sec", warn = true, }, restart_pc = { cmd = 'shutdown.exe /r /t 30 /c "J.A.R.V.I.S.: restart in 30s. Say cancel to abort."', label = lang == "ru" and "Перезагрузка через 30 секунд" or "Restart in 30 sec", warn = true, }, logoff_user = { cmd = 'shutdown.exe /l', label = lang == "ru" and "Выход из системы" or "Sign out" }, sleep_pc = { cmd = 'rundll32.exe powrprof.dll,SetSuspendState 0,1,0', label = lang == "ru" and "Сон" or "Sleep" }, hibernate_pc = { cmd = 'shutdown.exe /h', label = lang == "ru" and "Гибернация" or "Hibernate" }, cancel_shutdown = { cmd = 'shutdown.exe /a', label = lang == "ru" and "Выключение отменено" or "Shutdown cancelled" }, lock_workstation = { cmd = 'rundll32.exe user32.dll,LockWorkStation', label = lang == "ru" and "Компьютер заблокирован" or "PC locked" }, } local a = actions[cmd_id] if not a then return jarvis.cmd.error("Unknown power command.") end local res = jarvis.system.exec(a.cmd) local ok = res.success -- shutdown /a returns non-zero if there was no pending shutdown — treat as success -- (idempotent "cancel if any"). if not ok and cmd_id == "cancel_shutdown" then ok = true end if not ok then jarvis.log("error", "power " .. cmd_id .. " failed: " .. tostring(res.stderr):sub(1, 200)) return jarvis.cmd.error((lang == "ru" and "Не получилось: " or "Failed: ") .. cmd_id) end jarvis.system.notify("Power", a.label) jarvis.log("info", "power: " .. cmd_id .. " -> " .. a.label) -- For destructive ops with a 30-second window, give the user the abort hint. local say = a.label if a.warn then say = say .. ". " .. (lang == "ru" and "Скажите отмени если передумали." or "Say cancel to abort.") end return jarvis.cmd.ok(say)