diff --git a/news.d/bugfix/1560.ui.md b/news.d/bugfix/1560.ui.md new file mode 100644 index 000000000..a0cf28f0c --- /dev/null +++ b/news.d/bugfix/1560.ui.md @@ -0,0 +1 @@ +Update the tray icon to "disconnected" when a serial-over-USB machine is unplugged. diff --git a/plover/machine/base.py b/plover/machine/base.py index 11fb20c31..8709975c2 100644 --- a/plover/machine/base.py +++ b/plover/machine/base.py @@ -149,10 +149,18 @@ class ThreadedStenotypeBase(StenotypeBase, threading.Thread): """ def __init__(self): threading.Thread.__init__(self) + self._on_unhandled_exception(self._error) self.name += '-machine' StenotypeBase.__init__(self) self.finished = threading.Event() + def _on_unhandled_exception(self, action): + super_invoke_excepthook = self._invoke_excepthook + def invoke_excepthook(self): + action() + super_invoke_excepthook(self) + self._invoke_excepthook = invoke_excepthook + def run(self): """This method should be overridden by a subclass.""" pass diff --git a/test/test_machine.py b/test/test_machine.py new file mode 100644 index 000000000..3d45fbb37 --- /dev/null +++ b/test/test_machine.py @@ -0,0 +1,14 @@ +from unittest.mock import Mock +from plover.machine.base import ThreadedStenotypeBase + +class MyMachine(ThreadedStenotypeBase): + def run(self): + raise "some unexpected error" + +def test_update_machine_staten_on_unhandled_exception(): + machine = MyMachine() + callback = Mock() + machine.add_state_callback(callback) + machine.start_capture() + machine.join() + callback.assert_called_with('disconnected')