From 67983da22ec129cbde6a36631175e1ca022841d2 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 25 Sep 2023 12:54:21 -0400 Subject: [PATCH] (WSL) Port new clipboard clear behavior to WSL Former-commit-id: e1d96418abae79f6af75d72eeb6279e661196bd5 Former-commit-id: 0b345de72d9dc13de2f0db7c26264e0deb685965 --- lib/sshyp.py | 9 ++++++--- port-jobs/CLIPBOARD.py | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index d9a79a6..6546bcd 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -542,18 +542,21 @@ def copy_data(): # store hashed _copy_subject for later comparison _hash = sha512() _hash.update(_copy_subject.encode('utf-8')) - _hash = _hash.hexdigest() + f"{2*' '}-" # PORT START CLIPBOARD # WSL clipboard detection if 'WSL_DISTRO_NAME' in environ: run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'")) - Popen("sleep 30; powershell.exe -c Set-Clipboard ''", shell=True, stdout=DEVNULL, stderr=DEVNULL) + Popen("sleep 30; temp=$(echo \"$(powershell.exe -Command \'Get-FileHash -InputStream $([IO.MemoryStream]" + "::new([byte[]][char[]]\"$(Get-Clipboard)\")) -Algorithm SHA512 | Select-Object -ExpandProperty " + f"Hash\')\" | dos2unix); test \'{_hash.hexdigest().upper()}\' = \"$temp\" && powershell.exe -c " + "Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL) # Wayland clipboard detection elif 'WAYLAND_DISPLAY' in environ: run('wl-copy', stdin=Popen(('printf', _copy_subject.replace('\\', '\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \'{_hash}\' = \"$(printf \"$(wl-paste)\" | sha512sum)\" && wl-copy -c", shell=True) + Popen(f"sleep 30; test \'{_hash.hexdigest() + 2*' ' + '-'}\' = \"$(printf \"$(wl-paste)\" | sha512sum)\" " + "&& wl-copy -c", shell=True) # Haiku clipboard detection elif uname()[0] == 'Haiku': run(('clipboard', '-c', _copy_subject)) diff --git a/port-jobs/CLIPBOARD.py b/port-jobs/CLIPBOARD.py index 90867d7..04e9854 100755 --- a/port-jobs/CLIPBOARD.py +++ b/port-jobs/CLIPBOARD.py @@ -9,7 +9,10 @@ arguments, replacement = argv[1:], None if len(arguments) > 0: if arguments[0] == 'WSL': replacement = """run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'")) - Popen("sleep 30; powershell.exe -c Set-Clipboard ''", shell=True, stdout=DEVNULL, stderr=DEVNULL)""" + Popen("sleep 30; temp=$(echo \\"$(powershell.exe -Command \\'Get-FileHash -InputStream $([IO.MemoryStream]" + "::new([byte[]][char[]]\\"$(Get-Clipboard)\\")) -Algorithm SHA512 | Select-Object -ExpandProperty " + f"Hash\\')\\" | dos2unix); test \\'{_hash.hexdigest().upper()}\\' = \\"$temp\\" && powershell.exe -c " + "Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL)""" elif arguments[0] == 'MAC': replacement = """run('pbcopy', stdin=Popen(('printf', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\') .replace('%', '%%')), stdout=PIPE).stdout) @@ -24,7 +27,8 @@ if len(arguments) > 0: replacement = """if 'WAYLAND_DISPLAY' in environ: run('wl-copy', stdin=Popen(('printf', _copy_subject .replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \\'{_hash}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" && wl-copy -c", shell=True) + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" " + "&& wl-copy -c", shell=True) else: run(('xclip', '-sel', 'c'), stdin=Popen(('printf', _copy_subject .replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout)