Skip to content

Commit

Permalink
Run GUI code for handle_data on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiesel authored and MinmoTech committed Jun 13, 2023
1 parent 67a6651 commit 2a104fd
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/migaku_connection/card_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,21 @@ def _handle_data_from_card_creator(self, jsonData):
field_contents = text
note[field_name] = field_contents

# TODO: Refactor
if "editor" in current_note_info:
editor = current_note_info["editor"]
editor.loadNote()
if not editor.addMode:
editor._save_current_note()
if "reviewer" in current_note_info:
# NOTE: cannot use aqt.operations.update_note as it invalidates mw
note.flush()
aqt.mw.col.save()
reviewer_reshow(current_note_info["reviewer"], mute=True)

def update():
# runs GUI code, so it needs to run on main thread
if "editor" in current_note_info:
editor = current_note_info["editor"]
editor.loadNote()
if not editor.addMode:
editor._save_current_note()

if "reviewer" in current_note_info:
# NOTE: cannot use aqt.operations.update_note as it invalidates mw
note.flush()
aqt.mw.col.save()
reviewer_reshow(current_note_info["reviewer"], mute=True)

aqt.mw.taskman.run_on_main(update)
return "Added data to note."

def handle_audio_delivery(self, text):
Expand Down

0 comments on commit 2a104fd

Please sign in to comment.