Switched from xclip to pyperclip for import from x.
This commit is contained in:
parent
4966b87ba1
commit
73206ce393
@ -5,9 +5,10 @@
|
|||||||
# By Chrys, Storm Dragon, and contributers.
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
from fenrirscreenreader.core import debug
|
from fenrirscreenreader.core import debug
|
||||||
import subprocess, os
|
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
import _thread
|
import _thread
|
||||||
|
import pyperclip
|
||||||
|
import os
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
@ -22,33 +23,40 @@ class command():
|
|||||||
_thread.start_new_thread(self._threadRun , ())
|
_thread.start_new_thread(self._threadRun , ())
|
||||||
def _threadRun(self):
|
def _threadRun(self):
|
||||||
try:
|
try:
|
||||||
# Find xclip path
|
# Remember original display environment variable if it exists
|
||||||
xclip_paths = ['/usr/bin/xclip', '/bin/xclip', '/usr/local/bin/xclip']
|
originalDisplay = os.environ.get('DISPLAY', '')
|
||||||
xclip_path = None
|
clipboardContent = None
|
||||||
for path in xclip_paths:
|
|
||||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
# Try different display options
|
||||||
xclip_path = path
|
for i in range(10):
|
||||||
break
|
display = f":{i}"
|
||||||
if not xclip_path:
|
try:
|
||||||
self.env['runtime']['outputManager'].presentText('xclip not found in common locations', interrupt=True)
|
# Set display environment variable
|
||||||
return
|
os.environ['DISPLAY'] = display
|
||||||
xClipboard = ''
|
# Attempt to get clipboard content
|
||||||
for display in range(10):
|
clipboardContent = pyperclip.paste()
|
||||||
p = Popen('su ' + self.env['general']['currUser'] + ' -p -c "' + xclip_path + ' -d :' + str(display) + ' -o"', stdout=PIPE, stderr=PIPE, shell=True)
|
# If we get here without exception, we found a working display
|
||||||
stdout, stderr = p.communicate()
|
if clipboardContent:
|
||||||
self.env['runtime']['outputManager'].interruptOutput()
|
break
|
||||||
stderr = stderr.decode('utf-8')
|
except Exception:
|
||||||
xClipboard = stdout.decode('utf-8')
|
# Failed for this display, try next one
|
||||||
if (stderr == ''):
|
continue
|
||||||
break
|
|
||||||
if stderr != '':
|
# Restore original display setting
|
||||||
self.env['runtime']['outputManager'].presentText(stderr , soundIcon='', interrupt=False)
|
if originalDisplay:
|
||||||
|
os.environ['DISPLAY'] = originalDisplay
|
||||||
else:
|
else:
|
||||||
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', xClipboard)
|
os.environ.pop('DISPLAY', None)
|
||||||
|
|
||||||
|
# Process the clipboard content if we found any
|
||||||
|
if clipboardContent and isinstance(clipboardContent, str):
|
||||||
|
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', clipboardContent)
|
||||||
self.env['runtime']['outputManager'].presentText('Import to Clipboard', soundIcon='CopyToClipboard', interrupt=True)
|
self.env['runtime']['outputManager'].presentText('Import to Clipboard', soundIcon='CopyToClipboard', interrupt=True)
|
||||||
self.env['runtime']['outputManager'].presentText(xClipboard, soundIcon='', interrupt=False)
|
self.env['runtime']['outputManager'].presentText(clipboardContent, soundIcon='', interrupt=False)
|
||||||
|
else:
|
||||||
|
self.env['runtime']['outputManager'].presentText('No text found in clipboard or no accessible display', interrupt=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['outputManager'].presentText(e , soundIcon='', interrupt=False)
|
self.env['runtime']['outputManager'].presentText(str(e), soundIcon='', interrupt=False)
|
||||||
|
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
# Fenrir TTY screen reader
|
# Fenrir TTY screen reader
|
||||||
# By Chrys, Storm Dragon, and contributers.
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
version = "2025.02.26"
|
version = "2025.03.02"
|
||||||
codeName = "testing"
|
codeName = "testing"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user