🔧 - Changes the prefix and suffix values for various launcher actions in the constants.py file.
This commit is contained in:
25 files changed
+1395
-184
No files matched your search
@@ -5,12 +5,15 @@ Prevents system from going idle for a specified duration.
|
||||
|
||||
import subprocess
|
||||
from typing import List
|
||||
from threading import Timer
|
||||
|
||||
import gi
|
||||
import utils.icons as icons
|
||||
from fabric.utils import get_relative_path
|
||||
from fabric.utils.helpers import exec_shell_command_async
|
||||
from modules.launcher.plugin_base import PluginBase
|
||||
from modules.launcher.result import Result
|
||||
import config.data as data
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
@@ -57,11 +60,59 @@ class CaffeinePlugin(PluginBase):
|
||||
stderr=subprocess.DEVNULL,
|
||||
start_new_session=True, # Run in a new session to prevent hanging
|
||||
)
|
||||
|
||||
# Send notification based on duration
|
||||
if duration.lower() == "off":
|
||||
# Deactivation notification
|
||||
exec_shell_command_async(
|
||||
f"notify-send '☕ Caffeine' 'Deactivated' -a '{data.APP_NAME_CAP}' -e"
|
||||
)
|
||||
else:
|
||||
# Activation notification with duration
|
||||
duration_text = self.durations.get(duration, duration)
|
||||
exec_shell_command_async(
|
||||
f"notify-send '☕ Caffeine' 'Activated for {duration_text}' -a '{data.APP_NAME_CAP}' -e"
|
||||
)
|
||||
|
||||
# Schedule expiration notification for timed durations
|
||||
if duration.lower() not in ["on", "off"]:
|
||||
self._schedule_expiration_notification(duration, duration_text)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error starting inhibit script: {e}")
|
||||
|
||||
return action
|
||||
|
||||
def _parse_duration_to_seconds(self, duration_str: str) -> int:
|
||||
"""Parse duration string into seconds. Same logic as inhibit.py"""
|
||||
try:
|
||||
if duration_str.lower() in ['on', 'off']:
|
||||
return 0
|
||||
elif duration_str.endswith('h'):
|
||||
return int(float(duration_str[:-1]) * 3600)
|
||||
elif duration_str.endswith('m'):
|
||||
return int(float(duration_str[:-1]) * 60)
|
||||
elif duration_str.endswith('s'):
|
||||
return int(float(duration_str[:-1]))
|
||||
else:
|
||||
return int(duration_str)
|
||||
except ValueError:
|
||||
return 0
|
||||
|
||||
def _schedule_expiration_notification(self, duration: str, duration_text: str):
|
||||
"""Schedule a notification for when the caffeine effect expires."""
|
||||
seconds = self._parse_duration_to_seconds(duration)
|
||||
if seconds > 0:
|
||||
def send_expiration_notification():
|
||||
exec_shell_command_async(
|
||||
f"notify-send '☕ Caffeine' 'Expired after {duration_text}' -a '{data.APP_NAME_CAP}' -e"
|
||||
)
|
||||
|
||||
# Schedule the notification
|
||||
timer = Timer(seconds, send_expiration_notification)
|
||||
timer.daemon = True # Don't prevent program exit
|
||||
timer.start()
|
||||
|
||||
def _is_valid_duration(self, query: str) -> bool:
|
||||
"""Check if the query is a valid duration format."""
|
||||
if query in self.durations:
|
||||
|
||||
Reference in new issue
Block a user