mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-12 11:26:08 +00:00
Merge master into the reliability branch
The paste block was rewritten by both sides: master taught press() to put the remembered application back in front (focus), this branch moved the history write ahead of the paste and stopped restoring the old clipboard over a transcript the key press refused. Kept this branch's order and error handling, and handed press() the focus it now takes.
This commit is contained in:
+10
-5
@@ -50,16 +50,20 @@ class Pipeline(QObject):
|
||||
def busy(self):
|
||||
return self._thread is not None and self._thread.is_alive()
|
||||
|
||||
def run(self, wav_path, duration, rms_values=(), ask=False, paste=None):
|
||||
def run(self, wav_path, duration, rms_values=(), ask=False, paste=None,
|
||||
focus=None):
|
||||
"""`paste` overrides the setting for this one run, which is what a
|
||||
dictation asked for from a terminal wants: the text comes back down the
|
||||
socket, and pasting it into whatever had focus is nobody's intention."""
|
||||
socket, and pasting it into whatever had focus is nobody's intention.
|
||||
|
||||
`focus` is the application that was in front when the recording began,
|
||||
as a process id, and is where the paste is meant to land."""
|
||||
if self.busy:
|
||||
return
|
||||
self._stop.clear()
|
||||
self._thread = threading.Thread(
|
||||
target=self._work,
|
||||
args=(wav_path, duration, list(rms_values), ask, paste),
|
||||
args=(wav_path, duration, list(rms_values), ask, paste, focus),
|
||||
daemon=True,
|
||||
)
|
||||
self._thread.start()
|
||||
@@ -73,7 +77,8 @@ class Pipeline(QObject):
|
||||
"""
|
||||
self._stop.set()
|
||||
|
||||
def _work(self, wav_path, duration, rms_values, ask, paste_override=None):
|
||||
def _work(self, wav_path, duration, rms_values, ask, paste_override=None,
|
||||
focus=None):
|
||||
conf = self.conf
|
||||
started = time.monotonic()
|
||||
raw = ""
|
||||
@@ -171,7 +176,7 @@ class Pipeline(QObject):
|
||||
if wants_paste:
|
||||
self.stage.emit(t("Pasting…"))
|
||||
try:
|
||||
paste.press(conf["paste_shortcut"])
|
||||
paste.press(conf["paste_shortcut"], focus=focus)
|
||||
except paste.PasteError as exc:
|
||||
# The transcript is on the clipboard and in the history;
|
||||
# a key press that would not land is a warning, not a
|
||||
|
||||
Reference in New Issue
Block a user