ahrm / sioyek

Sioyek is a PDF viewer with a focus on textbooks and research papers
https://sioyek.info/
GNU General Public License v3.0
6.76k stars 219 forks source link

Extension working if sioyek started from command line otherwise not on MacOS #771

Open nickel8448 opened 11 months ago

nickel8448 commented 11 months ago

Hello, I created a very basic extension to search and do next of text from the clipboard. The extension works fine if I start sioyek from the terminal but if I open Sioyek from the finder, the extension does not work. I thought it could be due to not using the .app version but the homebrew version also doesn't work.

new_command _sn python3 /Users/rahulwadhwani/UPSC/NMP/Scripts/search_and_next_sioyek.py /Applications/sioyek.app/Contents/MacOS/sioyek
new_command _sn2 python3 /Users/rahulwadhwani/UPSC/NMP/Scripts/search_and_next_sioyek.py /opt/homebrew/bin/sioyek

Any recommendations how to fix this?

Thanks

ahrm commented 11 months ago

Yeah, I have noticed that too. I don't have a mac machine so it is pretty hard for me to test but if someone can figure out what the problem is that would be great.

nickel8448 commented 11 months ago

I can run some kind of tests or collect any specific logs if that helps. Please let me know

xiangsam commented 9 months ago

I encountered this issue on a Mac M1 as well. Here is my solution, and I hope it can assist someone.

I want to run the translation extension in sioyek-python-extension. It works when I run the Python command directly in the terminal. However, it remains unresponsive when I invoke it within sioyek app via :. The config of the extension in prefs_user.config is as follows:

new_command _translate_selected_text python3 -m sioyek.translate "%{sioyek_path}" "%{selected_text}"

I try to directly run the sioyek executable file in /Applications/sioyek.app/Contents/MacOS/sioyek, then run the command in opened sioyek app, and get the logs in terminal:

samrito@samrito-MacBook-Air MacOS % ./sioyek 
default_config_path: /Applications/sioyek.app/Contents/MacOS/prefs.config
default_keys_path: /Applications/sioyek.app/Contents/MacOS/keys.config
user_config_path: [ 0 ] /Users/samrito/.config/sioyek/prefs_user.config
user_config_path: [ 1 ] /Users/samrito/Library/Application Support/sioyek/prefs_user.config
user_keys_path: [ 0 ] /Users/samrito/.config/sioyek/keys_user.config
user_keys_path: [ 1 ] /Users/samrito/Library/Application Support/sioyek/keys_user.config
Error: % is not a valid configuration name
database_file_path: /Users/samrito/Library/Application Support/sioyek/test.db
local_database_file_path: /Users/samrito/Library/Application Support/sioyek/local.db
global_database_file_path: /Users/samrito/Library/CloudStorage/OneDrive-Personal/sioyek/shared.db
tutorial_path: /Applications/sioyek.app/Contents/MacOS/tutorial.pdf
last_opened_file_address_path: /Users/samrito/Library/Application Support/sioyek/last_document_path.txt
shader_path: /Applications/sioyek.app/Contents/MacOS/shaders
Creating shared memory block...
Shared memory created: this is the primary application.
Starting IPC server...
IPC server started.
WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'uvs' not read by fragment shader
WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'uvs' not read by fragment shader
WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'uvs' not read by fragment shader
WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'uvs' not read by fragment shader
WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

WARNING: Output of vertex shader 'screen_pos' not read by fragment shader

Data set on unsupported clipboard mode. QMimeData object will be deleted.
QString::arg: Argument missing: python3 /Users/samrito/Library/Python/3.9/lib/python/site-packages/sioyek/translate.py "/Applications/sioyek.app/Contents/MacOS/sioyek" "%{selected_text}", /Users/samrito/Zotero/storage/HMERN4F7/Wu et al. - 2023 - SEGA Structural Entropy Guided Anchor View for Gr.pdf
Traceback (most recent call last):
  File "/Users/samrito/Library/Python/3.9/lib/python/site-packages/sioyek/translate.py", line 5, in <module>
    from sioyek import Sioyek, clean_path
  File "/Users/samrito/Library/Python/3.9/lib/python/site-packages/sioyek/sioyek.py", line 5, in <module>
    import regex
  File "/Users/samrito/Library/Python/3.9/lib/python/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/samrito/Library/Python/3.9/lib/python/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/samrito/Library/Python/3.9/lib/python/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/Users/samrito/Library/Python/3.9/lib/python/site-packages/regex/_regex.cpython-39-darwin.so, 0x0002): tried: '/Users/samrito/Library/Python/3.9/lib/python/site-packages/regex/_regex.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64)))

It appears that the issue is caused by the difference between ARM64 and x86_64 architectures. I modified the config and it works now:

new_command _translate_selected_text arch -arm64 python3 -m sioyek.translate "%{sioyek_path}" "%{selected_text}"

Other problems: The sioyek package in sioyek-python-extension requires PyQt5. I installed it on my Mac M1 by following the top answer in this Stack Overflow question.

sbryngelson commented 8 months ago

@xiangsam bizarre that this fixed your issue with a GUI/terminal instantiation but not others like here https://github.com/ahrm/sioyek-python-extensions/issues/19