Skip to content

Commit

Permalink
Add support for "kill a task" button for Linux
Browse files Browse the repository at this point in the history
- Added support for killing tasks on Linux using `killall -ignore-case`
- Moved task killing logic to a dedicated taskkill.py file
- Updated commands.py to use the new kill function
- Updated commands.json to include OS-specific arguments for task killing
- Updated translations to include OS-specific argument names for task killing
  • Loading branch information
Lenochxd committed Dec 16, 2024
1 parent e772491 commit a3f14e8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 23 deletions.
18 changes: 1 addition & 17 deletions app/buttons/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,7 @@ def handle_command(message=None):
window.close(hwnd)

elif message.startswith(("/kill", "/taskill", "/taskkill", "/forceclose")):
window_name = (
message.replace("/kill", "")
.replace("/taskill", "")
.replace("/taskkill", "")
.replace("/forceclose", "")
)
hwnd = window.get_by_name(window_name)
if hwnd:
log.debug(f"Window '{window_name}' found with handle : {hwnd}")
else:
log.debug(f"Window '{window_name}' not found")
try:
window.close(hwnd)
except:
if not "." in window_name:
window_name += ".exe"
subprocess.Popen(f"taskkill /f /im {window_name}", shell=True)
system.kill(message)

elif message.startswith("/restart"):
exe = message.replace("/restart", "")
Expand Down
1 change: 1 addition & 0 deletions app/buttons/system/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .command_handler import handle_command
from .screensaver import handle_command as screensaver
from .lock_session import lock_session
from .taskkill import kill
49 changes: 49 additions & 0 deletions app/buttons/system/taskkill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from app.utils.platform import is_windows, is_linux

import os
import subprocess
import pyautogui
from app.utils.logger import log
from .. import window

def kill(message):
process = (
message.replace("/kill", "")
.replace("/taskill", "")
.replace("/taskkill", "")
.replace("/forceclose", "")
).strip()

if is_windows:
if process.endswith(".exe"):
subprocess.Popen(f"taskkill /f /im {process}", shell=True)
else:
window_name = process
hwnd = window.get_by_name(window_name)
if hwnd:
log.debug(f"Window '{window_name}' found with handle : {hwnd}")
try:
window.close(hwnd)
except:
subprocess.Popen(f"taskkill /f /im {window_name}.exe", shell=True)
else:
log.debug(f"Window '{window_name}' not found")
subprocess.Popen(f"taskkill /f /im {window_name}.exe", shell=True)

elif is_linux:
log.debug(f"Killing process '{process}'")
if subprocess.run(f"killall --ignore-case {process}", shell=True).returncode == 0:
log.success(f"Process '{process}' killed successfully")
else:
log.error(f"Process '{process}' not found")
raise RuntimeError(f"Process '{process}' not found")

else:
raise NotImplementedError("Screensaver is not implemented for this platform.")


def screensaver_off():
pyautogui.press("CTRL")
if is_linux:
os.system("gnome-screensaver-command -d")

8 changes: 7 additions & 1 deletion webdeck/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,13 @@
"command": "/forceclose",
"args": [
{
"TYPE": "input filetype['.exe']"
"TYPE": "input filetype['.exe']",
"os": "windows"
},
{
"TYPE": "input text",
"placeholder": "killall process_name",
"os": "linux"
}
],
"style": {}
Expand Down
3 changes: 2 additions & 1 deletion webdeck/translations/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ SYSTEM_superaltf4__btn_description=Force close the foreground window
SYSTEM_kill_a_task__btn_name=Kill a task
SYSTEM_kill_a_task__btn_default_display_name=Kill task
SYSTEM_kill_a_task__btn_description=
SYSTEM_kill_a_task__arg_1_name=Task (app.exe)
SYSTEM_kill_a_task__arg_1_name__windows=Task (app.exe)
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
Expand Down
3 changes: 2 additions & 1 deletion webdeck/translations/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ SYSTEM_superaltf4__btn_description=Force close the foreground window
SYSTEM_kill_a_task__btn_name=Kill a task
SYSTEM_kill_a_task__btn_default_display_name=Kill task
SYSTEM_kill_a_task__btn_description=
SYSTEM_kill_a_task__arg_1_name=Task (app.exe)
SYSTEM_kill_a_task__arg_1_name__windows=Task (app.exe)
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
Expand Down
3 changes: 2 additions & 1 deletion webdeck/translations/fr_FR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ 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=Tache (app.exe)
SYSTEM_kill_a_task__arg_1_name__windows=Tache (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
Expand Down
3 changes: 2 additions & 1 deletion webdeck/translations/ko_KR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ SYSTEM_superaltf4__btn_description=현재 창을 강제로 종료합니다.
SYSTEM_kill_a_task__btn_name=프로그램 종료
SYSTEM_kill_a_task__btn_default_display_name=
SYSTEM_kill_a_task__btn_description=
SYSTEM_kill_a_task__arg_1_name=프로그램 (app.exe)
SYSTEM_kill_a_task__arg_1_name__windows=프로그램 (app.exe)
SYSTEM_kill_a_task__arg_1_name__linux=프로세스 이름 ('ps -A' 에 표시된 대로)

SYSTEM_restart_a_task__btn_name=프로그램 재시작
SYSTEM_restart_a_task__btn_default_display_name=
Expand Down
3 changes: 2 additions & 1 deletion webdeck/translations/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ SYSTEM_superaltf4__btn_description=Force close the foreground window
SYSTEM_kill_a_task__btn_name=Kill a task
SYSTEM_kill_a_task__btn_default_display_name=Kill task
SYSTEM_kill_a_task__btn_description=
SYSTEM_kill_a_task__arg_1_name=Task (app.exe)
SYSTEM_kill_a_task__arg_1_name__windows=Task (app.exe)
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
Expand Down

0 comments on commit a3f14e8

Please sign in to comment.