]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/services/clipboard_manager.py
c790efc18e35d924b9be80e9868b4aa5056251db
[waydroid.git] / tools / services / clipboard_manager.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import logging
4 import threading
5 from tools.interfaces import IClipboard
6
7 try:
8 import pyclip
9 canClip = True
10 except Exception as e:
11 logging.debug(str(e))
12 canClip = False
13
14 stopping = False
15
16 def start(args):
17 def sendClipboardData(value):
18 try:
19 pyclip.copy(value)
20 except Exception as e:
21 logging.debug(str(e))
22
23 def getClipboardData():
24 try:
25 return pyclip.paste()
26 except Exception as e:
27 logging.debug(str(e))
28 return ""
29
30 def service_thread():
31 while not stopping:
32 IClipboard.add_service(args, sendClipboardData, getClipboardData)
33
34 if canClip:
35 global stopping
36 stopping = False
37 args.clipboard_manager = threading.Thread(target=service_thread)
38 args.clipboard_manager.start()
39 else:
40 logging.warning("Failed to start Clipboard manager service, check logs")
41
42 def stop(args):
43 global stopping
44 stopping = True
45 try:
46 if args.clipboardLoop:
47 args.clipboardLoop.quit()
48 except AttributeError:
49 logging.debug("Clipboard service is not even started")