Skip to content

Commit e866673

Browse files
[WIP] clipboard service
1 parent 4b700e6 commit e866673

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@ ln -sv /usr/share/udroid/main.sh /usr/bin/udroid-upgrade || {
7474
die "Failed to create symlink"
7575
}
7676

77+
# Clipboard-service
78+
7779
shout "Installation Complete."

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def vnc_mode(port=1,mode="start",xstartup=os.getenv('HOME')+"/.vnc/xstartup"):
2020

2121
if __name__ == '__main__':
2222
parser = optparse.OptionParser()
23+
parser.add_option("--clipboard-service", action="store_true", dest="clipboard_service", default=False, help="Start clipboard service")
2324
parser.add_option("--upgrade" ,action="store_true", default=False, help="Installs update if found updates")
2425
parser.add_option("--upgrade-check",action="store_true", default=False, help="check for updates")
2526
parser.add_option("--startvnc" ,action='store_true', default=False, help="Start VNC on port")
@@ -42,4 +43,6 @@ def vnc_mode(port=1,mode="start",xstartup=os.getenv('HOME')+"/.vnc/xstartup"):
4243
from utils.upgrade import *
4344
upgrade_check()
4445
sys.exit(0)
45-
46+
if options.clipboard_service:
47+
from utils.clipboard_watcher import *
48+
start_clipboard_service()

main.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ case $(echo "$0" | cut -d "/" -f 4) in
1414
"udroid-upgrade-check")
1515
python3 /usr/share/udroid/main.py --upgrade-check
1616
;;
17+
"clipboard-service")
18+
python3 /usr/share/udroid/main.py --clipboard-service
1719
esac

utils/clipboard_watcher

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
start_service() {
4+
# TODO
5+
:
6+
}
7+
8+
stop_service() {
9+
# TODO
10+
:
11+
}
12+
13+
case $1 in
14+
"start") start_service ;;
15+
"stop") stop_service ;;
16+
*) echo "Usage: $0 start|stop" ;;
17+
esac

utils/clipboard_watcher.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os, time
2+
3+
CLIPBOARD_BUFFER_FILE="/tmp/clipboard"
4+
5+
##############
6+
# watch if clipboard buffer file has changed with last modified time
7+
# if changed, then copy the content to clipboard
8+
def start_clipboard_service():
9+
last_modified_time = os.path.getmtime(CLIPBOARD_BUFFER_FILE)
10+
# check is xclip installed
11+
_xclip = os.popen("which xclip").read().strip()
12+
if _xclip is None:
13+
print("xclip not found")
14+
os.exit(1)
15+
16+
while os.get('Display') is not None:
17+
time.sleep(0.4)
18+
if os.path.exists(CLIPBOARD_BUFFER_FILE):
19+
if os.path.getmtime(CLIPBOARD_BUFFER_FILE) != last_modified_time:
20+
os.system(f"cat {CLIPBOARD_BUFFER_FILE} | xclip -selection clipboard")
21+
else:
22+
print("clipboard buffer file not found")
23+
os.exit(1)

0 commit comments

Comments
 (0)