forked from platypush/platypush
Wrapped clipboard management logic in a try-except block to prevent the clipboard plugin from failing hard
This commit is contained in:
parent
1a316bc3a6
commit
c6c7128099
1 changed files with 16 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
from time import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from platypush.context import get_bus
|
from platypush.context import get_bus
|
||||||
|
@ -47,12 +48,21 @@ class ClipboardPlugin(RunnablePlugin):
|
||||||
def main(self):
|
def main(self):
|
||||||
import pyperclip
|
import pyperclip
|
||||||
|
|
||||||
|
last_error_time = 0
|
||||||
|
|
||||||
while not self.should_stop():
|
while not self.should_stop():
|
||||||
|
try:
|
||||||
text = pyperclip.paste()
|
text = pyperclip.paste()
|
||||||
if text and text != self._last_text:
|
if text and text != self._last_text:
|
||||||
get_bus().post(ClipboardEvent(text=text))
|
get_bus().post(ClipboardEvent(text=text))
|
||||||
self._last_text = text
|
self._last_text = text
|
||||||
|
except Exception as e:
|
||||||
|
if time() - last_error_time > 60:
|
||||||
|
last_error_time = time()
|
||||||
|
self.logger.error(
|
||||||
|
'Could not access the clipboard: %s: %s', type(e), e
|
||||||
|
)
|
||||||
|
finally:
|
||||||
self._should_stop.wait(0.1)
|
self._should_stop.wait(0.1)
|
||||||
|
|
||||||
self.logger.info('Stopped clipboard monitor backend')
|
self.logger.info('Stopped clipboard monitor backend')
|
||||||
|
|
Loading…
Reference in a new issue