def _run_and_get_stdout(command: List[str], pipe_command: List[str] = None) -> Tuple[int, str]: if pipe_command is None: if is_flatpak(): command = _FLATPAK_COMMAND_PREFIX + command process1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) output_bytes = process1.communicate()[0] output = output_bytes.decode(encoding='UTF-8') return process1.returncode, output if is_flatpak(): command = _FLATPAK_COMMAND_PREFIX + command pipe_command = _FLATPAK_COMMAND_PREFIX + pipe_command process1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) process2 = subprocess.Popen(pipe_command, stdin=process1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if process1.stdout is not None: process1.stdout.close() output_bytes = process2.communicate()[0] output = output_bytes.decode(encoding='UTF-8') return process2.returncode, output
def _get_main_option_entries() -> List[GLib.OptionEntry]: options = [ build_glib_option(_Options.VERSION.value, short_name='v', description="Show the app version"), build_glib_option(_Options.DEBUG.value, description="Show debug messages"), build_glib_option(_Options.HIDE_WINDOW.value, description="Start with the main window hidden"), build_glib_option( _Options.ADD_UDEV_RULE.value, description= "Add udev rule to allow execution without root permission"), build_glib_option( _Options.REMOVE_UDEV_RULE.value, description= "Remove udev rule that allow execution without root permission" ), ] if not is_flatpak(): options.append( build_glib_option( _Options.AUTOSTART_ON.value, description="Enable automatic start of the app on login")) options.append( build_glib_option( _Options.AUTOSTART_OFF.value, description="Disable automatic start of the app on login")) return options
def _init_widgets(self) -> None: self._dialog: Gtk.Dialog = self._builder.get_object('dialog') self._dialog.connect("delete-event", hide_on_delete) if is_flatpak(): self._builder.get_object('settings_launch_on_login_grid').set_sensitive(False) self._builder.get_object('settings_launch_on_login_description_label') \ .set_text("Not supported by Flatpak (see https://github.com/flatpak/flatpak/issues/118)")
def on_setting_changed(self, widget: Any, *args: Any) -> None: if isinstance(widget, Gtk.Switch): value = args[0] key = re.sub('_switch$', '', widget.get_name()) self._settings_interactor.set_bool(key, value) if key == 'settings_launch_on_login' and not is_flatpak(): set_autostart_entry(value) elif isinstance(widget, Gtk.SpinButton): key = re.sub('_spinbutton$', '', widget.get_name()) value = widget.get_value_as_int() self._settings_interactor.set_int(key, value)
def _get_udev_command() -> str: command = APP_PACKAGE_NAME if is_flatpak(): command = f"flatpak run {APP_ID}" command += " --add-udev-rule" return command