mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
Run a dictation and a command to the agent at the same time
The two shared one state machine, which meant an agent thinking for a minute was a minute in which nothing could be dictated. That is the wrong trade: the work has nothing in common past the microphone, and the microphone is busy for the seconds you are speaking, not the minute afterwards. So they are two flows now, each with its own state, its own pipeline and its own indicator. Either can be working while the other records. Only the recorder is taken in turns, because there is one of it: whichever asks second is refused while the first holds it, and the menu entry greys out to say so rather than failing quietly. "Am I recording" is read off the two states rather than off the recorder's owner, which outlives the recording by the moment it takes the audio to arrive, and would otherwise report a microphone as busy after it was free. Two indicators in one corner would sit on top of each other, so an indicator can be told what it stacks on: it offsets by that one's height while it is showing and drops back into the corner when it goes, which the animation timer notices without anything having to tell it. Pasting is now under a lock. It is three steps rather than one, read the clipboard, write ours, press the key, and two runs finishing together would paste one answer and restore the other's clipboard over it. Calling off the agent is its own menu entry and its own command, instead of a cancel that meant different things depending on what was running. The tray icon still ends whichever recording is going.
This commit is contained in:
@@ -26,6 +26,12 @@ from i18n import t
|
||||
|
||||
CHUNK_SECONDS = audio.CHUNK_FRAMES / audio.RATE
|
||||
|
||||
# A dictation and a command to the agent run side by side and can finish at the
|
||||
# same moment. Pasting is not one step but three that must not interleave: read
|
||||
# what is on the clipboard, put ours there, press the key. Two runs doing that
|
||||
# at once would paste one answer and restore the other's clipboard over it.
|
||||
_paste_lock = threading.Lock()
|
||||
|
||||
|
||||
class Pipeline(QObject):
|
||||
stage = pyqtSignal(str) # human-readable progress line
|
||||
@@ -129,15 +135,16 @@ class Pipeline(QObject):
|
||||
)
|
||||
warning = "\n".join(x for x in (warning, denied) if x)
|
||||
|
||||
previous = paste.read_clipboard() if conf["restore_clipboard"] else None
|
||||
paste.copy(text)
|
||||
with _paste_lock:
|
||||
previous = paste.read_clipboard() if conf["restore_clipboard"] else None
|
||||
paste.copy(text)
|
||||
|
||||
if (conf["assistant_paste"] if ask else conf["auto_paste"]):
|
||||
self.stage.emit(t("Pasting…"))
|
||||
paste.press(conf["paste_shortcut"])
|
||||
if previous is not None:
|
||||
time.sleep(0.35)
|
||||
paste.copy_bytes(previous)
|
||||
if (conf["assistant_paste"] if ask else conf["auto_paste"]):
|
||||
self.stage.emit(t("Pasting…"))
|
||||
paste.press(conf["paste_shortcut"])
|
||||
if previous is not None:
|
||||
time.sleep(0.35)
|
||||
paste.copy_bytes(previous)
|
||||
|
||||
cfg.append_history({
|
||||
"ts": time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
|
||||
Reference in New Issue
Block a user