-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for "restart app" button for Linux
- 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
Showing
9 changed files
with
75 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters