Skip to content

Commit

Permalink
Add support for "restart app" button for Linux
Browse files Browse the repository at this point in the history
- Added support for restarting apps on Linux with two arguments (process name and restart command)
- Moved restart app logic to a dedicated restart_app.py file
- Updated commands.py to use the new restart_app function
- Updated commands.json to include OS-specific arguments for restarting apps
- Updated translations to include OS-specific argument names for restarting apps
  • Loading branch information
Lenochxd committed Dec 17, 2024
1 parent a3f14e8 commit b7decdf
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 12 deletions.
6 changes: 1 addition & 5 deletions app/buttons/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ def handle_command(message=None):
system.kill(message)

elif message.startswith("/restart"):
exe = message.replace("/restart", "")
if not "." in exe:
exe += ".exe"
subprocess.Popen(f"taskkill /f /im {exe}", shell=True)
subprocess.Popen(f"start {exe}", shell=True)
system.restart_app(message)

elif message.startswith("/clearclipboard"):
subprocess.Popen('cmd /c "echo off | clip"', shell=True)
Expand Down
1 change: 1 addition & 0 deletions app/buttons/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .screensaver import handle_command as screensaver
from .lock_session import lock_session
from .taskkill import kill
from .restart_app import restart_app
40 changes: 40 additions & 0 deletions app/buttons/system/restart_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from app.utils.platform import is_windows, is_linux
import subprocess
import time
from app.utils.logger import log


def restart_app(message):
if is_windows:
app = message.replace("/restart", "")
if not "." in app:
app += ".exe"
subprocess.Popen(f"taskkill /f /im {app}", shell=True)
if subprocess.Popen(f"start {app}", shell=True).returncode == 0:
log.success(f"App '{app}' restarted successfully")
else:
log.error(f"App '{app}' not found")
raise RuntimeError(f"App '{app}' not found")

elif is_linux:
app, restart_command = message.replace("/restart", "").strip().split("---")
app = app.strip()
restart_command = restart_command.strip()

# Kill all processes with the app name
subprocess.Popen(f"pkill -f {app}", shell=True)
time.sleep(0.5)

# Restart the app
log.debug(f"Restarting app '{app}' with command '{restart_command}'")
result = subprocess.Popen(f"nohup {restart_command} > /dev/null 2>&1 &", shell=True, start_new_session=True)
result.wait()
log.debug(result)
if result.returncode == 0:
log.success(f"App '{app}' restarted successfully")
else:
log.error(f"Failed to restart app '{app}'")
raise RuntimeError(f"Failed to restart app '{app}'")

else:
raise NotImplementedError("Restart is not implemented for this platform.")
18 changes: 17 additions & 1 deletion webdeck/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,23 @@
"command": "/restart",
"args": [
{
"TYPE": "input filetype['.exe']"
"TYPE": "input filetype['.exe']",
"os": "windows"
},
{
"TYPE": "input text",
"placeholder": "pkill -f process_name",
"os": "linux"
},
{
"TYPE": "text",
"value": "---",
"os": "linux"
},
{
"TYPE": "input text",
"placeholder": "nohup your_command > /dev/null 2>&1 &",
"os": "linux"
}
],
"style": {}
Expand Down
4 changes: 3 additions & 1 deletion webdeck/translations/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ SYSTEM_kill_a_task__arg_1_name__linux=Process name (as shown in 'ps -A')
SYSTEM_restart_a_task__btn_name=Restart a task
SYSTEM_restart_a_task__btn_default_display_name=Restart task
SYSTEM_restart_a_task__btn_description=
SYSTEM_restart_a_task__arg_1_name=Task (app.exe)
SYSTEM_restart_a_task__arg_1_name__windows=Task (app.exe)
SYSTEM_restart_a_task__arg_1_name__linux=Process name to close (as shown in 'ps -A')
SYSTEM_restart_a_task__arg_2_name__linux=Restart command

SYSTEM_execute_python_code__btn_name=Execute python code
SYSTEM_execute_python_code__btn_default_display_name=
Expand Down
4 changes: 3 additions & 1 deletion webdeck/translations/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ SYSTEM_kill_a_task__arg_1_name__linux=Process name (as shown in 'ps -A')
SYSTEM_restart_a_task__btn_name=Restart a task
SYSTEM_restart_a_task__btn_default_display_name=Restart task
SYSTEM_restart_a_task__btn_description=
SYSTEM_restart_a_task__arg_1_name=Task (app.exe)
SYSTEM_restart_a_task__arg_1_name__windows=Task (app.exe)
SYSTEM_restart_a_task__arg_1_name__linux=Process name to close (as shown in 'ps -A')
SYSTEM_restart_a_task__arg_2_name__linux=Restart command

SYSTEM_execute_python_code__btn_name=Execute python code
SYSTEM_execute_python_code__btn_default_display_name=
Expand Down
6 changes: 4 additions & 2 deletions webdeck/translations/fr_FR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,15 @@ SYSTEM_superaltf4__btn_description=Ferme de force la fenêtre au premier plan
SYSTEM_kill_a_task__btn_name=Tuer une tâche
SYSTEM_kill_a_task__btn_default_display_name=Tuer la tâche
SYSTEM_kill_a_task__btn_description=
SYSTEM_kill_a_task__arg_1_name__windows=Tache (app.exe)
SYSTEM_kill_a_task__arg_1_name__windows=Tâche (app.exe)
SYSTEM_kill_a_task__arg_1_name__linux=Nom du processus (tel qu'affiché dans 'ps -A')

SYSTEM_restart_a_task__btn_name=Redémarrer une application
SYSTEM_restart_a_task__btn_default_display_name=Redémarrer l'application
SYSTEM_restart_a_task__btn_description=
SYSTEM_restart_a_task__arg_1_name=Tache (app.exe)
SYSTEM_restart_a_task__arg_1_name__windows=Tâche (app.exe)
SYSTEM_restart_a_task__arg_1_name__linux=Nom du processus à fermer (tel qu'affiché dans 'ps -A')
SYSTEM_restart_a_task__arg_2_name__linux=Commande de redémarrage

SYSTEM_execute_python_code__btn_name=Exécuter du code python
SYSTEM_execute_python_code__btn_default_display_name=Exécuter le code python
Expand Down
4 changes: 3 additions & 1 deletion webdeck/translations/ko_KR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ SYSTEM_kill_a_task__arg_1_name__linux=프로세스 이름 ('ps -A' 에 표시된
SYSTEM_restart_a_task__btn_name=프로그램 재시작
SYSTEM_restart_a_task__btn_default_display_name=
SYSTEM_restart_a_task__btn_description=
SYSTEM_restart_a_task__arg_1_name=프로그램 (app.exe)
SYSTEM_restart_a_task__arg_1_name__windows=프로그램 (app.exe)
SYSTEM_restart_a_task__arg_1_name__linux=종료할 프로세스 이름 ('ps -A' 에 표시된 대로)
SYSTEM_restart_a_task__arg_2_name__linux=재시작 명령어

SYSTEM_execute_python_code__btn_name=파이썬 코드 실행
SYSTEM_execute_python_code__btn_default_display_name=
Expand Down
4 changes: 3 additions & 1 deletion webdeck/translations/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ SYSTEM_kill_a_task__arg_1_name__linux=Process name (as shown in 'ps -A')
SYSTEM_restart_a_task__btn_name=Restart a task
SYSTEM_restart_a_task__btn_default_display_name=Restart task
SYSTEM_restart_a_task__btn_description=
SYSTEM_restart_a_task__arg_1_name=Task (app.exe)
SYSTEM_restart_a_task__arg_1_name__windows=Task (app.exe)
SYSTEM_restart_a_task__arg_1_name__linux=Process name to close (as shown in 'ps -A')
SYSTEM_restart_a_task__arg_2_name__linux=Restart command

SYSTEM_execute_python_code__btn_name=Execute python code
SYSTEM_execute_python_code__btn_default_display_name=
Expand Down

0 comments on commit b7decdf

Please sign in to comment.