Add files via upload
This commit is contained in:
1 parent
320d933f08
commit
cd70cb7796
27 files changed
+5807
-3538
No files matched your search
+151
-102
@@ -1,6 +1,3 @@
|
||||
# actions/open_app.py
|
||||
# MARK XXV — Cross-Platform App Launcher
|
||||
|
||||
import time
|
||||
import subprocess
|
||||
import platform
|
||||
@@ -12,92 +9,120 @@ try:
|
||||
except ImportError:
|
||||
_PSUTIL = False
|
||||
|
||||
_APP_ALIASES = {
|
||||
"whatsapp": {"Windows": "WhatsApp", "Darwin": "WhatsApp", "Linux": "whatsapp"},
|
||||
"chrome": {"Windows": "chrome", "Darwin": "Google Chrome", "Linux": "google-chrome"},
|
||||
"google chrome": {"Windows": "chrome", "Darwin": "Google Chrome", "Linux": "google-chrome"},
|
||||
"firefox": {"Windows": "firefox", "Darwin": "Firefox", "Linux": "firefox"},
|
||||
"spotify": {"Windows": "Spotify", "Darwin": "Spotify", "Linux": "spotify"},
|
||||
"vscode": {"Windows": "code", "Darwin": "Visual Studio Code", "Linux": "code"},
|
||||
"visual studio code": {"Windows": "code", "Darwin": "Visual Studio Code", "Linux": "code"},
|
||||
"discord": {"Windows": "Discord", "Darwin": "Discord", "Linux": "discord"},
|
||||
"telegram": {"Windows": "Telegram", "Darwin": "Telegram", "Linux": "telegram"},
|
||||
"instagram": {"Windows": "Instagram", "Darwin": "Instagram", "Linux": "instagram"},
|
||||
"tiktok": {"Windows": "TikTok", "Darwin": "TikTok", "Linux": "tiktok"},
|
||||
"notepad": {"Windows": "notepad.exe", "Darwin": "TextEdit", "Linux": "gedit"},
|
||||
"calculator": {"Windows": "calc.exe", "Darwin": "Calculator", "Linux": "gnome-calculator"},
|
||||
"terminal": {"Windows": "cmd.exe", "Darwin": "Terminal", "Linux": "gnome-terminal"},
|
||||
"cmd": {"Windows": "cmd.exe", "Darwin": "Terminal", "Linux": "bash"},
|
||||
"explorer": {"Windows": "explorer.exe", "Darwin": "Finder", "Linux": "nautilus"},
|
||||
"file explorer": {"Windows": "explorer.exe", "Darwin": "Finder", "Linux": "nautilus"},
|
||||
"paint": {"Windows": "mspaint.exe", "Darwin": "Preview", "Linux": "gimp"},
|
||||
"word": {"Windows": "winword", "Darwin": "Microsoft Word", "Linux": "libreoffice --writer"},
|
||||
"excel": {"Windows": "excel", "Darwin": "Microsoft Excel", "Linux": "libreoffice --calc"},
|
||||
"powerpoint": {"Windows": "powerpnt", "Darwin": "Microsoft PowerPoint","Linux": "libreoffice --impress"},
|
||||
"vlc": {"Windows": "vlc", "Darwin": "VLC", "Linux": "vlc"},
|
||||
"zoom": {"Windows": "Zoom", "Darwin": "zoom.us", "Linux": "zoom"},
|
||||
"slack": {"Windows": "Slack", "Darwin": "Slack", "Linux": "slack"},
|
||||
"steam": {"Windows": "steam", "Darwin": "Steam", "Linux": "steam"},
|
||||
"task manager": {"Windows": "taskmgr.exe", "Darwin": "Activity Monitor", "Linux": "gnome-system-monitor"},
|
||||
"settings": {"Windows": "ms-settings:", "Darwin": "System Preferences", "Linux": "gnome-control-center"},
|
||||
"powershell": {"Windows": "powershell.exe", "Darwin": "Terminal", "Linux": "bash"},
|
||||
"edge": {"Windows": "msedge", "Darwin": "Microsoft Edge", "Linux": "microsoft-edge"},
|
||||
"brave": {"Windows": "brave", "Darwin": "Brave Browser", "Linux": "brave-browser"},
|
||||
"obsidian": {"Windows": "Obsidian", "Darwin": "Obsidian", "Linux": "obsidian"},
|
||||
"notion": {"Windows": "Notion", "Darwin": "Notion", "Linux": "notion"},
|
||||
"blender": {"Windows": "blender", "Darwin": "Blender", "Linux": "blender"},
|
||||
"capcut": {"Windows": "CapCut", "Darwin": "CapCut", "Linux": "capcut"},
|
||||
"postman": {"Windows": "Postman", "Darwin": "Postman", "Linux": "postman"},
|
||||
"figma": {"Windows": "Figma", "Darwin": "Figma", "Linux": "figma"},
|
||||
_SYSTEM = platform.system()
|
||||
|
||||
_APP_ALIASES: dict[str, dict[str, str]] = {
|
||||
|
||||
"chrome": {"Windows": "chrome", "Darwin": "Google Chrome", "Linux": "google-chrome"},
|
||||
"google chrome": {"Windows": "chrome", "Darwin": "Google Chrome", "Linux": "google-chrome"},
|
||||
"firefox": {"Windows": "firefox", "Darwin": "Firefox", "Linux": "firefox"},
|
||||
"edge": {"Windows": "msedge", "Darwin": "Microsoft Edge", "Linux": "microsoft-edge"},
|
||||
"brave": {"Windows": "brave", "Darwin": "Brave Browser", "Linux": "brave-browser"},
|
||||
"safari": {"Windows": "msedge", "Darwin": "Safari", "Linux": "firefox"},
|
||||
"opera": {"Windows": "opera", "Darwin": "Opera", "Linux": "opera"},
|
||||
"whatsapp": {"Windows": "WhatsApp", "Darwin": "WhatsApp", "Linux": "whatsapp"},
|
||||
"telegram": {"Windows": "Telegram", "Darwin": "Telegram", "Linux": "telegram"},
|
||||
"discord": {"Windows": "Discord", "Darwin": "Discord", "Linux": "discord"},
|
||||
"slack": {"Windows": "Slack", "Darwin": "Slack", "Linux": "slack"},
|
||||
"zoom": {"Windows": "Zoom", "Darwin": "zoom.us", "Linux": "zoom"},
|
||||
"teams": {"Windows": "msteams", "Darwin": "Microsoft Teams", "Linux": "teams"},
|
||||
"skype": {"Windows": "skype", "Darwin": "Skype", "Linux": "skype"},
|
||||
"signal": {"Windows": "signal", "Darwin": "Signal", "Linux": "signal"},
|
||||
"spotify": {"Windows": "Spotify", "Darwin": "Spotify", "Linux": "spotify"},
|
||||
"vlc": {"Windows": "vlc", "Darwin": "VLC", "Linux": "vlc"},
|
||||
"netflix": {"Windows": "Netflix", "Darwin": "Netflix", "Linux": "firefox"},
|
||||
"vscode": {"Windows": "code", "Darwin": "Visual Studio Code", "Linux": "code"},
|
||||
"visual studio code": {"Windows": "code", "Darwin": "Visual Studio Code", "Linux": "code"},
|
||||
"code": {"Windows": "code", "Darwin": "Visual Studio Code", "Linux": "code"},
|
||||
"terminal": {"Windows": "wt", "Darwin": "Terminal", "Linux": "gnome-terminal"},
|
||||
"cmd": {"Windows": "cmd.exe", "Darwin": "Terminal", "Linux": "bash"},
|
||||
"powershell": {"Windows": "powershell.exe", "Darwin": "Terminal", "Linux": "bash"},
|
||||
"postman": {"Windows": "Postman", "Darwin": "Postman", "Linux": "postman"},
|
||||
"git": {"Windows": "git-bash", "Darwin": "Terminal", "Linux": "bash"},
|
||||
"figma": {"Windows": "Figma", "Darwin": "Figma", "Linux": "figma"},
|
||||
"blender": {"Windows": "blender", "Darwin": "Blender", "Linux": "blender"},
|
||||
"word": {"Windows": "winword", "Darwin": "Microsoft Word", "Linux": "libreoffice --writer"},
|
||||
"excel": {"Windows": "excel", "Darwin": "Microsoft Excel", "Linux": "libreoffice --calc"},
|
||||
"powerpoint": {"Windows": "powerpnt", "Darwin": "Microsoft PowerPoint", "Linux": "libreoffice --impress"},
|
||||
"libreoffice": {"Windows": "soffice", "Darwin": "LibreOffice", "Linux": "libreoffice"},
|
||||
"notepad": {"Windows": "notepad.exe", "Darwin": "TextEdit", "Linux": "gedit"},
|
||||
"textedit": {"Windows": "notepad.exe", "Darwin": "TextEdit", "Linux": "gedit"},
|
||||
"explorer": {"Windows": "explorer.exe", "Darwin": "Finder", "Linux": "nautilus"},
|
||||
"file explorer": {"Windows": "explorer.exe", "Darwin": "Finder", "Linux": "nautilus"},
|
||||
"finder": {"Windows": "explorer.exe", "Darwin": "Finder", "Linux": "nautilus"},
|
||||
"task manager": {"Windows": "taskmgr.exe", "Darwin": "Activity Monitor", "Linux": "gnome-system-monitor"},
|
||||
"settings": {"Windows": "ms-settings:", "Darwin": "System Preferences", "Linux": "gnome-control-center"},
|
||||
"calculator": {"Windows": "calc.exe", "Darwin": "Calculator", "Linux": "gnome-calculator"},
|
||||
"paint": {"Windows": "mspaint.exe", "Darwin": "Preview", "Linux": "gimp"},
|
||||
"instagram": {"Windows": "Instagram", "Darwin": "Instagram", "Linux": "firefox"},
|
||||
"tiktok": {"Windows": "TikTok", "Darwin": "TikTok", "Linux": "firefox"},
|
||||
"notion": {"Windows": "Notion", "Darwin": "Notion", "Linux": "notion"},
|
||||
"obsidian": {"Windows": "Obsidian", "Darwin": "Obsidian", "Linux": "obsidian"},
|
||||
"capcut": {"Windows": "CapCut", "Darwin": "CapCut", "Linux": "capcut"},
|
||||
"steam": {"Windows": "steam", "Darwin": "Steam", "Linux": "steam"},
|
||||
"epic": {"Windows": "EpicGamesLauncher", "Darwin": "Epic Games Launcher", "Linux": "legendary"},
|
||||
"epic games": {"Windows": "EpicGamesLauncher", "Darwin": "Epic Games Launcher", "Linux": "legendary"},
|
||||
}
|
||||
|
||||
|
||||
def _normalize(raw: str) -> str:
|
||||
system = platform.system()
|
||||
key = raw.lower().strip()
|
||||
key = raw.lower().strip()
|
||||
|
||||
if key in _APP_ALIASES:
|
||||
return _APP_ALIASES[key].get(system, raw)
|
||||
return _APP_ALIASES[key].get(_SYSTEM, raw)
|
||||
|
||||
for alias_key, os_map in _APP_ALIASES.items():
|
||||
if alias_key in key or key in alias_key:
|
||||
return os_map.get(system, raw)
|
||||
return raw
|
||||
|
||||
|
||||
def _is_running(app_name: str) -> bool:
|
||||
if not _PSUTIL:
|
||||
return True
|
||||
app_lower = app_name.lower().replace(" ", "").replace(".exe", "")
|
||||
try:
|
||||
for proc in psutil.process_iter(["name"]):
|
||||
try:
|
||||
proc_name = proc.info["name"].lower().replace(" ", "").replace(".exe", "")
|
||||
if app_lower in proc_name or proc_name in app_lower:
|
||||
return True
|
||||
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
return os_map.get(_SYSTEM, raw)
|
||||
|
||||
return raw
|
||||
|
||||
def _launch_windows(app_name: str) -> bool:
|
||||
|
||||
if shutil.which(app_name) or shutil.which(app_name.split(".")[0]):
|
||||
try:
|
||||
subprocess.Popen(
|
||||
app_name,
|
||||
shell=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
time.sleep(1.5)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"[open_app] subprocess failed: {e}")
|
||||
|
||||
if ":" in app_name:
|
||||
try:
|
||||
subprocess.Popen(f"start {app_name}", shell=True)
|
||||
time.sleep(1.0)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
import pyautogui
|
||||
pyautogui.PAUSE = 0.1
|
||||
pyautogui.press("win")
|
||||
time.sleep(0.6)
|
||||
time.sleep(0.7)
|
||||
pyautogui.write(app_name, interval=0.05)
|
||||
time.sleep(0.8)
|
||||
time.sleep(0.9)
|
||||
pyautogui.press("enter")
|
||||
time.sleep(3.0)
|
||||
time.sleep(2.5)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"[open_app] ⚠️ Windows launch failed: {e}")
|
||||
return False
|
||||
print(f"[open_app] Start Menu search failed: {e}")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _launch_macos(app_name: str) -> bool:
|
||||
|
||||
try:
|
||||
result = subprocess.run(["open", "-a", app_name], capture_output=True, timeout=8)
|
||||
result = subprocess.run(
|
||||
["open", "-a", app_name],
|
||||
capture_output=True, timeout=8
|
||||
)
|
||||
if result.returncode == 0:
|
||||
time.sleep(1.0)
|
||||
return True
|
||||
@@ -105,13 +130,29 @@ def _launch_macos(app_name: str) -> bool:
|
||||
pass
|
||||
|
||||
try:
|
||||
result = subprocess.run(["open", "-a", f"{app_name}.app"], capture_output=True, timeout=8)
|
||||
result = subprocess.run(
|
||||
["open", "-a", f"{app_name}.app"],
|
||||
capture_output=True, timeout=8
|
||||
)
|
||||
if result.returncode == 0:
|
||||
time.sleep(1.0)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
binary = shutil.which(app_name) or shutil.which(app_name.lower())
|
||||
if binary:
|
||||
try:
|
||||
subprocess.Popen(
|
||||
[binary],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
time.sleep(1.0)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
import pyautogui
|
||||
pyautogui.hotkey("command", "space")
|
||||
@@ -122,37 +163,54 @@ def _launch_macos(app_name: str) -> bool:
|
||||
time.sleep(1.5)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"[open_app] ⚠️ macOS Spotlight failed: {e}")
|
||||
return False
|
||||
print(f"[open_app] Spotlight failed: {e}")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _launch_linux(app_name: str) -> bool:
|
||||
|
||||
binary = (
|
||||
shutil.which(app_name) or
|
||||
shutil.which(app_name.lower()) or
|
||||
shutil.which(app_name.lower().replace(" ", "-"))
|
||||
shutil.which(app_name.lower().replace(" ", "-")) or
|
||||
shutil.which(app_name.lower().replace(" ", "_"))
|
||||
)
|
||||
if binary:
|
||||
try:
|
||||
subprocess.Popen([binary], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
subprocess.Popen(
|
||||
[binary],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
time.sleep(1.0)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
subprocess.run(["xdg-open", app_name], capture_output=True, timeout=5)
|
||||
subprocess.run(
|
||||
["xdg-open", app_name],
|
||||
capture_output=True, timeout=5
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
desktop_name = app_name.lower().replace(" ", "-")
|
||||
subprocess.run(["gtk-launch", desktop_name], capture_output=True, timeout=5)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
for desktop_name in [
|
||||
app_name.lower(),
|
||||
app_name.lower().replace(" ", "-"),
|
||||
app_name.lower().replace(" ", ""),
|
||||
]:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["gtk-launch", desktop_name],
|
||||
capture_output=True, timeout=5
|
||||
)
|
||||
if result.returncode == 0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
@@ -163,7 +221,6 @@ _OS_LAUNCHERS = {
|
||||
"Linux": _launch_linux,
|
||||
}
|
||||
|
||||
|
||||
def open_app(
|
||||
parameters=None,
|
||||
response=None,
|
||||
@@ -173,36 +230,28 @@ def open_app(
|
||||
app_name = (parameters or {}).get("app_name", "").strip()
|
||||
|
||||
if not app_name:
|
||||
return "Please specify which application to open, sir."
|
||||
|
||||
system = platform.system()
|
||||
launcher = _OS_LAUNCHERS.get(system)
|
||||
return "No application name provided."
|
||||
|
||||
launcher = _OS_LAUNCHERS.get(_SYSTEM)
|
||||
if launcher is None:
|
||||
return f"Unsupported OS: {system}"
|
||||
return f"Unsupported operating system: {_SYSTEM}"
|
||||
|
||||
normalized = _normalize(app_name)
|
||||
print(f"[open_app] 🚀 Launching: {app_name} → {normalized} ({system})")
|
||||
print(f"[open_app] Launching: '{app_name}' → '{normalized}' ({_SYSTEM})")
|
||||
|
||||
if player:
|
||||
player.write_log(f"[open_app] {app_name}")
|
||||
|
||||
try:
|
||||
success = launcher(normalized)
|
||||
|
||||
if success:
|
||||
return f"Opened {app_name} successfully, sir."
|
||||
|
||||
if normalized != app_name:
|
||||
success = launcher(app_name)
|
||||
if success:
|
||||
return f"Opened {app_name} successfully, sir."
|
||||
|
||||
if launcher(normalized):
|
||||
return f"Opened {app_name}."
|
||||
if normalized.lower() != app_name.lower():
|
||||
if launcher(app_name):
|
||||
return f"Opened {app_name}."
|
||||
return (
|
||||
f"I tried to open {app_name}, sir, but couldn't confirm it launched. "
|
||||
f"It may still be loading or might not be installed."
|
||||
f"Could not confirm that {app_name} launched. "
|
||||
f"It may still be loading, or it might not be installed."
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[open_app] ❌ {e}")
|
||||
return f"Failed to open {app_name}, sir: {e}"
|
||||
print(f"[open_app] Error: {e}")
|
||||
return f"Failed to open {app_name}: {e}"
|
||||
Reference in new issue
Block a user