Try to fix an issue where xclip is not being found even though it is installed.
This commit is contained in:
		| @@ -25,32 +25,53 @@ class command(): | |||||||
|             if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): |             if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): | ||||||
|                 self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) |                 self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) | ||||||
|                 return |                 return | ||||||
|                                                                                                                                                                  |                                                                                                                                                      | ||||||
|             clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') |             clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') | ||||||
|             user = self.env['general']['currUser'] |             user = self.env['general']['currUser'] | ||||||
|                                                                                                                                                                  |          | ||||||
|  |             # First try to find xclip in common locations | ||||||
|  |             xclip_paths = [ | ||||||
|  |                 '/usr/bin/xclip', | ||||||
|  |                 '/bin/xclip', | ||||||
|  |                 '/usr/local/bin/xclip' | ||||||
|  |             ] | ||||||
|  |          | ||||||
|  |             xclip_path = None | ||||||
|  |             for path in xclip_paths: | ||||||
|  |                 if os.path.isfile(path) and os.access(path, os.X_OK): | ||||||
|  |                     xclip_path = path | ||||||
|  |                     break | ||||||
|  |                  | ||||||
|  |             if not xclip_path: | ||||||
|  |                 self.env['runtime']['outputManager'].presentText( | ||||||
|  |                     'xclip not found in common locations',  | ||||||
|  |                     interrupt=True | ||||||
|  |                 ) | ||||||
|  |                 return | ||||||
|  |                                                                                                                                                      | ||||||
|             for display in range(10): |             for display in range(10): | ||||||
|                 p = Popen( |                 p = Popen( | ||||||
|                     ['su', user, '-c', f"xclip -d :{display} -selection clipboard"], |                     ['su', user, '-p', '-c', f"{xclip_path} -d :{display} -selection clipboard"], | ||||||
|                     stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=os.setpgrp |                     stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=os.setpgrp | ||||||
|                 ) |                 ) | ||||||
|                 stdout, stderr = p.communicate(input=clipboard.encode('utf-8')) |                 stdout, stderr = p.communicate(input=clipboard.encode('utf-8')) | ||||||
|                                                                                                                                                                  |                                                                                                                                                      | ||||||
|                 self.env['runtime']['outputManager'].interruptOutput() |                 self.env['runtime']['outputManager'].interruptOutput() | ||||||
|                                                                                                                                                                  |                                                                                                                                                      | ||||||
|                 stderr = stderr.decode('utf-8') |                 stderr = stderr.decode('utf-8') | ||||||
|                 stdout = stdout.decode('utf-8') |                 stdout = stdout.decode('utf-8') | ||||||
|                                                                                                                                                                  |                                                                                                                                                      | ||||||
|                 if stderr == '': |                 if stderr == '': | ||||||
|                     break |                     break | ||||||
|                                                                                                                                                                  |                                                                                                                                                      | ||||||
|             if stderr != '': |             if stderr != '': | ||||||
|                 self.env['runtime']['outputManager'].presentText(stderr, soundIcon='', interrupt=False) |                 self.env['runtime']['outputManager'].presentText(stderr, soundIcon='', interrupt=False) | ||||||
|             else: |             else: | ||||||
|                 self.env['runtime']['outputManager'].presentText('exported to the X session.', interrupt=True) |                 self.env['runtime']['outputManager'].presentText('exported to the X session.', interrupt=True) | ||||||
|                                                                                                                                                                  |                                                                                                                                                      | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             self.env['runtime']['outputManager'].presentText(str(e), soundIcon='', interrupt=False) |             self.env['runtime']['outputManager'].presentText(str(e), soundIcon='', interrupt=False) | ||||||
|  |  | ||||||
|                                                                                                                                                                  |                                                                                                                                                                  | ||||||
|     def setCallback(self, callback): |     def setCallback(self, callback): | ||||||
|         pass |         pass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user