From 5a4e952d4dca8fb3d49b49abdd06f6e42fcb27d9 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 24 Sep 2023 21:50:14 -0400 Subject: [PATCH] (Wayland) Only clear clipboard contents if they have not been changed since altered by sshyp Former-commit-id: 2b6be8d327419bccc51430f732fb03ff9bba0439 Former-commit-id: 09406c55e394e97c90d984067bff9b4677b0496a --- lib/sshyp.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index ede04b1..db37719 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -521,6 +521,7 @@ def gen(): # copies a specified field of an entry to the clipboard def copy_data(): + from hashlib import sha512 from subprocess import Popen # ensure the copy target is an entry target_type_check(entry_name, True, True) @@ -537,6 +538,12 @@ def copy_data(): # ensure field is not blank if _copy_subject == '': raise IndexError + + # store hashed _copy_subject for later comparison + _hash = sha512() + _hash.update(_copy_subject.encode('utf-8')) + _hash = _hash.hexdigest() + ' -' + # PORT START CLIPBOARD # WSL clipboard detection if 'WSL_DISTRO_NAME' in environ: @@ -546,7 +553,7 @@ def copy_data(): elif 'WAYLAND_DISPLAY' in environ: run('wl-copy', stdin=Popen(('printf', _copy_subject.replace('\\', '\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen('sleep 30; wl-copy -c', shell=True) + Popen(f"sleep 30; test \'{_hash}\' = \"$(printf \"$(wl-paste)\" | sha512sum)\" && wl-copy -c", shell=True) # Haiku clipboard detection elif uname()[0] == 'Haiku': run(('clipboard', '-c', _copy_subject))