Skip to content

Commit

Permalink
video upload support.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwersyk committed Dec 29, 2024
1 parent 6015b99 commit e81d8f0
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/screenrecorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import gi

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, GLib, Gio
import os


class ScreenRecorder:
def __init__(self, parent_window):
self.window = parent_window
self.recording = False
self.output_path = os.path.join(GLib.get_user_cache_dir(), "screen")
self.init_proxy()

def init_proxy(self):
try:
self.proxy = Gio.DBusProxy.new_for_bus_sync(
Gio.BusType.SESSION,
Gio.DBusProxyFlags.NONE,
None,
'org.gnome.Shell.Screencast',
'/org/gnome/Shell/Screencast',
'org.gnome.Shell.Screencast',
None
)
except GLib.Error as e:
self.show_error(str(e))

def start(self):
if not self.recording:
try:
old_file = self.output_path + ".mp4"
if os.path.exists(old_file):
try:
os.remove(old_file)
except OSError as e:
self.show_error(str(e))
return False

success, path = self.proxy.call_sync(
'Screencast',
GLib.Variant(
'(sa{sv})',
(self.output_path, {})
),
Gio.DBusCallFlags.NONE,
-1,
None
)
if success:
self.recording = True
return True

except GLib.Error as e:
self.show_error(str(e))
return False

def stop(self, *args):
if self.recording:
try:
self.proxy.call_sync(
'StopScreencast',
None,
Gio.DBusCallFlags.NONE,
-1,
None
)
self.recording = False
except GLib.Error as e:
self.show_error(str(e))

def show_error(self, message):
dialog = Adw.MessageDialog.new(self.window)
dialog.set_heading("Error")
dialog.set_body(str(message))
dialog.set_modal(True)
dialog.add_response("ok", "OK")
dialog.present()

0 comments on commit e81d8f0

Please sign in to comment.