Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken link to jabref.json #77

Closed
wants to merge 2 commits into from

Conversation

arshadkazmi42
Copy link

@arshadkazmi42 arshadkazmi42 commented Oct 26, 2019

Fixes #76

@tobiasdiez
Copy link
Member

Thanks for the report and the fix. I would guess that it's better to use the Linux version https://github.com/JabRef/jabref/blob/master/buildres/linux/org.jabref.jabref.json on Mac. As I don't have a Mac, I'm not sure how it works and what changes are necessary. In case you are a mac user, it would be great if you could play around a bit and then report what worked for you.

@arshadkazmi42
Copy link
Author

arshadkazmi42 commented Oct 26, 2019

@tobiasdiez I tried both windows and linux files.
Both does not seems to work.
I am seeing this error
Screen Shot 2019-10-26 at 2 05 36 PM

I followed the readme to setup

@arshadkazmi42
Copy link
Author

How can I verify if this is working? I tried on wikipedia and can see message till Send to jabref...

@tobiasdiez
Copy link
Member

This error means that Firefox cannot find JabRef, so in other words the path specified in the org.jabref.jabref.json file is not correct. You can try to edit this file with the correct path, then everything should work. So after the message "Send to JabRef" is shown, JabRef opens and imports the bibliographic entry.

@arshadkazmi42
Copy link
Author

@tobiasdiez I downloaded this file https://github.com/JabRef/jabref/blob/master/buildres/linux/jabrefHost.py and used this location as path in my org.jabref.jabref.json
Still getting the same issue.
Any thoughts? I am on MacOS

@tobiasdiez
Copy link
Member

Mhh, strange. That should have worked. Maybe try to put the py file somewhere else and/or try to specify the path in org.jabref.jabref.json in different ways (e.g. absolute or relative path). You can also try to move the json file to /Library/Application Support/Mozilla/NativeMessagingHosts/org.jabref.jabref.json or to ~/Library/Application Support/Mozilla/NativeMessagingHosts/org.jabref.jabref.json

@arshadkazmi42
Copy link
Author

I tried moving py file in same location as json file. In external path, tried moving the file in both the locations ~/Library and /Library

Still no luck, I tried firefox addon debug option and seeing these logs

Screen Shot 2019-10-27 at 4 19 29 PM

Is there any other way to debug it more?

@tobiasdiez
Copy link
Member

According to https://stackoverflow.com/a/54187367/873661, there should be more details in Firefox Menu --> Web Developer --> Browser Console

@tobiasdiez
Copy link
Member

In #75, we just found out that the problem on linux was a missing executable flag. Could you please try to run chmod +x jabrefHost.py.

@arshadkazmi42
Copy link
Author

@tobiasdiez I tried setting permission of py file using chmod +x still seeing the same error

I did the following,

  • created file org.jabref.jabref in ~/Library/Application Support/Mozilla/NativeMessagingHosts
  • create jabrefHost.py in /Users/arshad/Arshad and used this path inside the above file
  • installed the addon in firefox

Am I missing anything in this?

@tobiasdiez
Copy link
Member

😞 That should have worked. I'm running out of ideas what the problem could be. What is printed in Firefox's Browser console?

@Siedlerchr
Copy link
Member

@LyzardKing Any idea?

@LyzardKing
Copy link
Collaborator

I don't have a mac, but I can say that the python script should not be moved around, because it mostly uses relative paths if I remember correctly..

@LyzardKing
Copy link
Collaborator

so the json should point to the python file
and the python file should be in the proper location.
I think that should be the "ideal" scenario..
Does that still fail?

@arshadkazmi42
Copy link
Author

@LyzardKing what do you mean by proper location? Same directory where json file exists?

@LyzardKing
Copy link
Collaborator

LyzardKing commented Oct 28, 2019

The mac version doesn't include the python script yet! I forgot...
I'd have to look at how it can call the jabref executable..
@arshadkazmi42 You have the .app in the applications dir right?

which version did you download? Just to be sure.. the portable/dmg?

@arshadkazmi42
Copy link
Author

Yes. Correct

@LyzardKing
Copy link
Collaborator

Ok.. so you can open it like a folder, to see where the executable is
Then you'd need to set that path in the python script

@LyzardKing
Copy link
Collaborator

could you open the python script and try setting JABREF_PATH to /Applications/JabRef.app/Contents/MacOS/JabRef

@arshadkazmi42
Copy link
Author

arshadkazmi42 commented Oct 28, 2019

Updated the python script to this

jabrefHost.py

#!/usr/bin/python3 -u

# Note that running python with the `-u` flag is required on Windows,
# in order to ensure that stdin and stdout are opened in binary, rather
# than text, mode.

import json
import sys
import struct
import subprocess
import shlex
import logging
import shutil
from pathlib import Path

# We assume that this python script is located in "jabref/lib" while the executable is "jabref/bin/JabRef"
script_dir = Path(__file__).resolve().parent.parent
JABREF_PATH = script_dir / "/Applications/JabRef.app/Contents/MacOS/JabRef"
if not JABREF_PATH.exists():
    JABREF_PATH = shutil.which("jabref")

logging_dir = Path.home() / ".mozilla/native-messaging-hosts/"
if not logging_dir.exists():
    logging_dir.mkdir(parents=True)
logging.basicConfig(filename=logging_dir / 'jabref_browser_extension.log')

# Read a message from stdin and decode it.
def get_message():
    raw_length = sys.stdin.buffer.read(4)
    if not raw_length:
        logging.error("Raw_length \n")
        sys.exit(0)
    message_length = struct.unpack('=I', raw_length)[0]
    logging.info("Got length: {} bytes to be read\n".format(message_length))
    message = sys.stdin.buffer.read(message_length).decode("utf-8")
    logging.info("Got message of {} chars\n".format(len(message)))
    data = json.loads(message)
    logging.info("Successfully retrieved JSON\n")
    return data


# Encode a message for transmission, given its content.
def encode_message(message_content):
    encoded_content = json.dumps(message_content).encode("utf-8")
    encoded_length = struct.pack('=I', len(encoded_content))
    return {'length': encoded_length, 'content': struct.pack(str(len(encoded_content))+"s",encoded_content)}


# Send an encoded message to stdout.
def send_message(message):
    encoded_message = encode_message(message)
    sys.stdout.buffer.write(encoded_message['length'])
    sys.stdout.buffer.write(encoded_message['content'])
    sys.stdout.buffer.flush()

def add_jabref_entry(data):
    cmd = str(JABREF_PATH) + " -importBibtex " + "\"" + data + "\""
    try:
        response = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as exc:
        logging.error("Failed to call JabRef: %s %s", exc.returncode, exc.output)
    else:
        logging.info(f'Called JabRef and got: {response}')
    return response


logging.info("Starting JabRef backend")

try:
    message = get_message()
except Exception as e:
    message = str(e)
logging.info(str(message))

if 'status' in message and message["status"] == "validate":
    cmd = str(JABREF_PATH) + " -version"
    try:
        response = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as exc:
        logging.error("Failed to call JabRef: %s %s", exc.returncode, exc.output)
        send_message({"message": "jarNotFound", "path": JABREF_PATH})
    else:
        logging.info(f'{response}')
        send_message({"message": "jarFound"})
else:
    entry = message["text"]
    output = add_jabref_entry(entry)
    send_message({"message": "ok", "output": str(output)})

org.jabref.jabref.json


{
  "name": "org.jabref.jabref",
  "description": "JabRef",
  "path": "jabrefHost.py",
  "type": "stdio",
  "allowed_extensions": [
    "@jabfox"
  ]
}

Above is the two file with updated code. both the files are kept at ~/Library/Application Support/Mozilla/NativeMessagingHosts

Am I doing anything wrong here? I s there a way to debug the python file?

@LyzardKing
Copy link
Collaborator

The path in the json file has to be absolute

@LyzardKing
Copy link
Collaborator

and the line in the python script has to be changed to this:
JABREF_PATH = "/Applications/JabRef.app/Contents/MacOS/JabRef"

@arshadkazmi42
Copy link
Author

Updated the path and reinstalled the addon. Still seeing the same error

@LyzardKing
Copy link
Collaborator

just to be sure, if you call that path in a terminal jabref starts, right?

@arshadkazmi42
Copy link
Author

Yes it starts

@arshadkazmi42
Copy link
Author

For checking this I am going to this page https://en.wikipedia.org/wiki/Hacker
and clicking on Jafref icon. Is that fine?

@LyzardKing
Copy link
Collaborator

Ok, so the path is correct.. and the json has the full path, not just jabrefHost.py?

@tobiasdiez
Copy link
Member

The disconnected port message is only shown if the python script is not found by Firefox. If the python script does not find JabRef then a different error message would be shown. However, I have no idea how to find out the reason why Firefox does not find the python script (or is not able to run it).

@arshadkazmi42
Copy link
Author

@LyzardKing So I tried running the python script using python3. I am seeing this error

Traceback (most recent call last):
  File "/Users/arshad/Arshad/jabrefHost.py", line 19, in <module>
    if not JABREF_PATH.exists():
AttributeError: 'str' object has no attribute 'exists'

@LyzardKing
Copy link
Collaborator

Because it's a Path object instead.
Change the usual line to
JABREF_PATH = Path( "/Applications/JabRef.app/Contents/MacOS/JabRef")

@arshadkazmi42
Copy link
Author

arshadkazmi42 commented Oct 29, 2019

Updated the path, now python script is working,
Its not giving any error and does not displays anything in the terminal

Still seeing same error on addon

@arshadkazmi42
Copy link
Author

arshadkazmi42 commented Oct 29, 2019

The disconnected port message is only shown if the python script is not found by Firefox. If the python script does not find JabRef then a different error message would be shown. However, I have no idea how to find out the reason why Firefox does not find the python script (or is not able to run it).

json file is at this location ~/Library/Application Support/Mozilla/NativeMessagingHosts/org.jabref.jabref.json

Firefox will read it from there right? or it needs to be somewhere else or something needs to be configured for this?

@tobiasdiez
Copy link
Member

That seems correct. Are there any errors in the Firefox Menu --> Web Developer --> Browser console?

@arshadkazmi42
Copy link
Author

That seems correct. Are there any errors in the Firefox Menu --> Web Developer --> Browser console?

Yes.

Unix error 13 during operation open on file /Library/Application Support/Mozilla/NativeMessagingHosts/org.jabref.jabref.json (Permission denied)

This is the error I am getting. Looks like it can't open the json file itself

@LyzardKing
Copy link
Collaborator

Do you have two copies of the json file, one in ~/.. and another one in /Library/..?

@arshadkazmi42
Copy link
Author

@LyzardKing Yes. I do. in /Library/... with this name jabref.json

@LyzardKing
Copy link
Collaborator

try removing that and keeop only the one in ~/..

@arshadkazmi42
Copy link
Author

Seeing this error now No such native application org.jabref.jabref

@tobiasdiez
Copy link
Member

Just to make sure, please try the following:

  • delete all files in both ~/Library... and in /Library (make a backup of the json file)
  • put json file into /Library/... with name org.jabref.jabref.json
  • try to run addon
  • in case there is an error, delete json in /Library and put one into ~/Library/... again with the name org.jabref.jabref.json

Thanks for your consistent help in this endeavour!

@arshadkazmi42
Copy link
Author

I tried above steps.
On moving the json file to /Library/...
I have started getting some other error Failed to execute command "/Users/...../jabrefHost.py"

Now its reading the json file, but can't execute jabrefHost.py I tried giving chmod +x jabrefHost.py still same error

@LyzardKing
Copy link
Collaborator

By same error do you mean the Failed to execute command?

@arshadkazmi42
Copy link
Author

By same error do you mean the Failed to execute command?

Yes.

@LyzardKing
Copy link
Collaborator

Is the path in the json file correct?

@arshadkazmi42
Copy link
Author

arshadkazmi42 commented Oct 29, 2019

Yes. I tried moving the py file to same location with json.
On that I got these in Browser console

OpenGL compositor Initialized Succesfully.
Version: 2.1 INTEL-10.36.19
Vendor: Intel Inc.
Renderer: Intel(R) Iris(TM) Plus Graphics 640
FBO Texture Target: TEXTURE_2D
OpenGL compositor Initialized Succesfully.
Version: 2.1 INTEL-10.36.19
Vendor: Intel Inc.
Renderer: Intel(R) Iris(TM) Plus Graphics 640
FBO Texture Target: TEXTURE_2D
navigator.requestMediaKeySystemAccess promise rejected 0x80530009 'Key system is unsupported'
MediaKeySystemAccess::GetKeySystemStatus(com.widevine.alpha) result=available msg=''

and this error in addon inspect logs

Error: "Attempt to postMessage on disconnected port

@LyzardKing
Copy link
Collaborator

That seems to be an error regarding the DRM implementation (widevine)..
Nothing jabref related..

@arshadkazmi42
Copy link
Author

Anything else we can try to validate this?

@tobiasdiez
Copy link
Member

Sorry, I've no idea why this is not working...I think the above error is also not helpful as it's not JabRef related (and probably not even related to the native messaging stuff). 😢

@tobiasdiez
Copy link
Member

@arshadkazmi42 Could you solved the issue in the meantime? Maybe it's working now with the new JabRef 5.0 release?

@arshadkazmi42
Copy link
Author

@tobiasdiez I will look into it ASAP. I will try it with the latest version of JabRef 5.0

@tobiasdiez
Copy link
Member

@arshadkazmi42 Did you had any luck fixing this? In the meantime, we had some improvements by @LyzardKing concerning the linux scripts, so this might work now?!

@arshadkazmi42
Copy link
Author

@tobiasdiez havent got a chance to look into this in sometime. will try to have a look at it

Base automatically changed from master to main January 24, 2021 19:03
@tobiasdiez
Copy link
Member

Since there has been no progress in some time, I'll close this PR for now. Please feel free to resolve the conflicts after you tested the latest versions!

@tobiasdiez tobiasdiez closed this Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken link in README
4 participants