macro_recorder: implement process elevation on linux

main
Ilya Zhuravlev 2020-12-21 21:52:56 -05:00
parent 542fb36c71
commit 000ad5d55c
4 changed files with 68 additions and 9 deletions

View File

@ -0,0 +1,2 @@
def linux_keystroke_recorder():
print("Recording")

View File

@ -0,0 +1,51 @@
import sys
from PyQt5.QtCore import QProcess
from PyQt5.QtWidgets import QPushButton, QWidget
from fbs_runtime.application_context import is_frozen
from basic_editor import BasicEditor
from vial_device import VialKeyboard
class LinuxRecorder:
def __init__(self):
self.process = None
def start(self):
self.process = QProcess()
args = [sys.executable]
if is_frozen():
args += sys.argv[1:]
else:
args += sys.argv
args += ["--linux-recorder"]
self.process.start("pkexec", args)
self.process.waitForFinished()
print(self.process.readAll())
class MacroRecorder(BasicEditor):
def __init__(self):
super().__init__()
self.recorder = LinuxRecorder()
self.recording = False
btn = QPushButton("Record")
btn.clicked.connect(self.on_record_clicked)
self.addWidget(btn)
def valid(self):
return isinstance(self.device, VialKeyboard)
def rebuild(self, device):
super().rebuild(device)
if not self.valid():
return
def on_record_clicked(self):
self.recorder.start()

View File

@ -7,6 +7,7 @@ from fbs_runtime.application_context.PyQt5 import ApplicationContext
import sys import sys
from linux_keystroke_recorder import linux_keystroke_recorder
from main_window import MainWindow from main_window import MainWindow
from constants import WINDOW_WIDTH, WINDOW_HEIGHT from constants import WINDOW_WIDTH, WINDOW_HEIGHT
@ -46,10 +47,13 @@ class UncaughtHook(QtCore.QObject):
if __name__ == '__main__': if __name__ == '__main__':
appctxt = ApplicationContext() # 1. Instantiate ApplicationContext if len(sys.argv) == 2 and sys.argv[1] == "--linux-recorder":
qt_exception_hook = UncaughtHook() linux_keystroke_recorder()
window = MainWindow() else:
window.resize(WINDOW_WIDTH, WINDOW_HEIGHT) appctxt = ApplicationContext() # 1. Instantiate ApplicationContext
window.show() qt_exception_hook = UncaughtHook()
exit_code = appctxt.app.exec_() # 2. Invoke appctxt.app.exec_() window = MainWindow()
sys.exit(exit_code) window.resize(WINDOW_WIDTH, WINDOW_HEIGHT)
window.show()
exit_code = appctxt.app.exec_() # 2. Invoke appctxt.app.exec_()
sys.exit(exit_code)

View File

@ -9,6 +9,7 @@ import json
from firmware_flasher import FirmwareFlasher from firmware_flasher import FirmwareFlasher
from keymap_editor import KeymapEditor from keymap_editor import KeymapEditor
from layout_editor import LayoutEditor from layout_editor import LayoutEditor
from macro_recorder import MacroRecorder
from util import tr, find_vial_devices from util import tr, find_vial_devices
@ -36,8 +37,9 @@ class MainWindow(QMainWindow):
self.layout_editor = LayoutEditor() self.layout_editor = LayoutEditor()
self.keymap_editor = KeymapEditor(self.layout_editor) self.keymap_editor = KeymapEditor(self.layout_editor)
self.firmware_flasher = FirmwareFlasher(self) self.firmware_flasher = FirmwareFlasher(self)
self.macro_recorder = MacroRecorder()
self.editors = [(self.keymap_editor, "Keymap"), (self.layout_editor, "Layout"), self.editors = [(self.keymap_editor, "Keymap"), (self.layout_editor, "Layout"), (self.macro_recorder, "Macros"),
(self.firmware_flasher, "Firmware updater")] (self.firmware_flasher, "Firmware updater")]
self.tabs = QTabWidget() self.tabs = QTabWidget()
@ -116,7 +118,7 @@ class MainWindow(QMainWindow):
if self.current_device is not None: if self.current_device is not None:
self.current_device.open(self.sideload_json if self.current_device.sideload else None) self.current_device.open(self.sideload_json if self.current_device.sideload else None)
for e in [self.layout_editor, self.keymap_editor, self.firmware_flasher]: for e in [self.layout_editor, self.keymap_editor, self.firmware_flasher, self.macro_recorder]:
e.rebuild(self.current_device) e.rebuild(self.current_device)
self.refresh_tabs() self.refresh_tabs()