🐛 fix(panel): improve screen recording detection and start time retrieval
This commit is contained in:
1 parent
5c746e4ce6
commit
ce99b7a73f
1 file changed
+34
-31
@@ -2,13 +2,12 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
from fabric.utils import get_relative_path
|
from fabric.utils import get_relative_path
|
||||||
from fabric.widgets.box import Box
|
from fabric.widgets.box import Box
|
||||||
from fabric.widgets.button import Button
|
from fabric.widgets.button import Button
|
||||||
from fabric.widgets.label import Label
|
from fabric.widgets.label import Label
|
||||||
from fabric.widgets.svg import Svg
|
from fabric.widgets.svg import Svg
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
|
|
||||||
class RecordingIndicator(Button):
|
class RecordingIndicator(Button):
|
||||||
@@ -28,7 +27,9 @@ class RecordingIndicator(Button):
|
|||||||
self.recording_icon = Svg(
|
self.recording_icon = Svg(
|
||||||
name="indicators-icon",
|
name="indicators-icon",
|
||||||
size=24,
|
size=24,
|
||||||
svg_file=get_relative_path("../../../config/assets/icons/misc/media-record.svg"),
|
svg_file=get_relative_path(
|
||||||
|
"../../../config/assets/icons/misc/media-record.svg"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
self.time_label = Label(
|
self.time_label = Label(
|
||||||
name="recording-time-label",
|
name="recording-time-label",
|
||||||
@@ -56,10 +57,10 @@ class RecordingIndicator(Button):
|
|||||||
GLib.timeout_add(100, lambda: self.remove_style_class("pressed") or False)
|
GLib.timeout_add(100, lambda: self.remove_style_class("pressed") or False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_wf_recorder_running(self):
|
def is_recorder_running(self):
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["pgrep", "-x", "wf-recorder"],
|
["pgrep", "-x", "wf-recorder", "-x", "gpu-screen-recorder"],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=1,
|
timeout=1,
|
||||||
@@ -73,7 +74,7 @@ class RecordingIndicator(Button):
|
|||||||
self.last_process_check = current_time
|
self.last_process_check = current_time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
is_recording = self.is_wf_recorder_running()
|
is_recording = self.is_recorder_running()
|
||||||
|
|
||||||
if is_recording:
|
if is_recording:
|
||||||
if not self.get_visible():
|
if not self.get_visible():
|
||||||
@@ -128,33 +129,36 @@ class RecordingIndicator(Button):
|
|||||||
self.timer_timeout_id = None
|
self.timer_timeout_id = None
|
||||||
|
|
||||||
def get_recording_start_time(self):
|
def get_recording_start_time(self):
|
||||||
start_time_file = "/tmp/recording_start_time.txt"
|
wf_file = "/tmp/recording_start_time.txt"
|
||||||
|
gpu_file = "/tmp/gpu_recording_start_time.txt"
|
||||||
|
|
||||||
try:
|
def read_timestamp(path):
|
||||||
if not os.path.exists(start_time_file):
|
|
||||||
return None
|
|
||||||
|
|
||||||
file_mtime = os.path.getmtime(start_time_file)
|
|
||||||
|
|
||||||
with open(start_time_file, "r") as f:
|
|
||||||
content = f.read().strip()
|
|
||||||
if content:
|
|
||||||
recorded_time = float(content)
|
|
||||||
|
|
||||||
current_time = time.time()
|
|
||||||
if abs(recorded_time - current_time) > 3600:
|
|
||||||
return file_mtime
|
|
||||||
|
|
||||||
return recorded_time
|
|
||||||
else:
|
|
||||||
return file_mtime
|
|
||||||
|
|
||||||
except (ValueError, OSError):
|
|
||||||
try:
|
try:
|
||||||
return os.path.getmtime(start_time_file)
|
with open(path, "r") as f:
|
||||||
except OSError:
|
content = f.read().strip()
|
||||||
|
if content:
|
||||||
|
t = float(content)
|
||||||
|
if abs(t - time.time()) <= 3600:
|
||||||
|
return t
|
||||||
|
return os.path.getmtime(path)
|
||||||
|
except (OSError, ValueError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if os.path.exists(wf_file):
|
||||||
|
t = read_timestamp(wf_file)
|
||||||
|
if t:
|
||||||
|
print("[DEBUG] Using wf-recorder start time")
|
||||||
|
return t
|
||||||
|
|
||||||
|
if os.path.exists(gpu_file):
|
||||||
|
t = read_timestamp(gpu_file)
|
||||||
|
if t:
|
||||||
|
print("[DEBUG] Using gpu-screen-recorder start time")
|
||||||
|
return t
|
||||||
|
|
||||||
|
print("[DEBUG] No start time file found, using current time")
|
||||||
|
return time.time()
|
||||||
|
|
||||||
def on_stop_recording(self, *args):
|
def on_stop_recording(self, *args):
|
||||||
try:
|
try:
|
||||||
self.set_visible(False)
|
self.set_visible(False)
|
||||||
@@ -181,7 +185,7 @@ class RecordingIndicator(Button):
|
|||||||
|
|
||||||
def _verify_recording_stopped(self):
|
def _verify_recording_stopped(self):
|
||||||
try:
|
try:
|
||||||
if self.is_wf_recorder_running():
|
if self.is_recorder_running():
|
||||||
if self.recording_start_time is None:
|
if self.recording_start_time is None:
|
||||||
self.recording_start_time = self.get_recording_start_time()
|
self.recording_start_time = self.get_recording_start_time()
|
||||||
|
|
||||||
@@ -193,7 +197,6 @@ class RecordingIndicator(Button):
|
|||||||
self.timer_timeout_id = GLib.timeout_add(
|
self.timer_timeout_id = GLib.timeout_add(
|
||||||
self.timer_update_interval, self.update_timer_display
|
self.timer_update_interval, self.update_timer_display
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.set_visible(False)
|
self.set_visible(False)
|
||||||
self.cleanup_recording_state()
|
self.cleanup_recording_state()
|
||||||
|
|||||||
Reference in new issue
Block a user