-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Autoinstall extension in chrome #6442
Merged
Merged
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e7de544
Initial extention autoinstall for chrome/chromium in linux
LyzardKing 198819c
Add postinst/postrm chrome extension
LyzardKing 4bbaba3
Add json files to macos build
LyzardKing 384826a
Add macos resource files and link in the pkg release
LyzardKing 02878cc
Use chrome store url to install extension
LyzardKing 386e2d9
set chromium auto-install to world readable
LyzardKing fc0c8b6
Add permissions to macos autoinstall extension
LyzardKing ac8fd4f
Add inst/rm for chromium extension on rpm
LyzardKing 53fda44
Rename postinstall to postinstall.test
tobiasdiez da01d55
Merge remote-tracking branch 'upstream/master' into autoinstall_ext
Siedlerchr 6025b72
try again with postinstall
Siedlerchr 15b8161
Add exec permission to mac postinstall
LyzardKing 9f560b7
Fix shell indentations
LyzardKing 1a54692
Fix mac postinst to use -d option
LyzardKing e9c0d55
Add custom host file for macos
LyzardKing 9f1bc8b
Add path to macos native messaging host files
LyzardKing 06f487c
Remove binary mode in python script
LyzardKing c7df1df
create the dir before copying file
LyzardKing ba6ae48
Add mac native-messaging json to postinst
LyzardKing a7eaf2d
Try mkdir/cp to add files to macos pkg
LyzardKing 1b17049
Fix path spaces
LyzardKing ecec705
Add -p option to mkdir parents
LyzardKing 0cb4ed2
Merge branch 'master' into autoinstall_ext
Siedlerchr 378008a
postinstall macos force /bin/sh
LyzardKing 42bef18
revert to using install on macos
LyzardKing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
buildres/linux/native-messaging-host/chromium/bifehkofibaamoeaopjglfkddgkijdlh.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"external_update_url": "https://clients2.google.com/service/update2/crx" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/python3 | ||
|
||
import json | ||
import logging | ||
import platform | ||
import shlex | ||
import shutil | ||
import struct | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
# We assume that this python script is located in "jabref/lib" while the executable is "jabref/bin/JabRef" | ||
# Note that the `which` command does not work as intended on MacOs, so the path must be hardcoded. | ||
script_dir = Path(__file__).resolve().parent.parent | ||
JABREF_PATH = script_dir / "bin/JabRef" | ||
if not JABREF_PATH.exists(): | ||
JABREF_PATH = Path( "/Applications/JabRef.app/Contents/MacOS/JabRef") | ||
|
||
if not JABREF_PATH.exists(): | ||
logging.error("Could not determine JABREF_PATH") | ||
sys.exit(-1) | ||
|
||
logging_dir = Path.home() / ".mozilla/native-messaging-hosts/" | ||
if not logging_dir.exists(): | ||
logging_dir.mkdir(parents=True) | ||
logging.basicConfig(filename=str(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 null") | ||
sys.exit(0) | ||
message_length = struct.unpack("=I", raw_length)[0] | ||
logging.info("Got length: {} bytes to be read".format(message_length)) | ||
message = sys.stdin.buffer.read(message_length).decode("utf-8") | ||
logging.info("Got message of {} chars".format(len(message))) | ||
data = json.loads(message) | ||
logging.info("Successfully retrieved JSON") | ||
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): | ||
"""Send string via cli as literal to preserve special characters""" | ||
cmd = [str(JABREF_PATH), "--importBibtex", r"{}".format(data)] | ||
logging.info("Try to execute command {}".format(cmd)) | ||
try: | ||
response = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
except subprocess.CalledProcessError as exc: | ||
logging.error("Failed to call JabRef: {} {}".format(exc.returncode, exc.output)) | ||
else: | ||
logging.info("Called JabRef and got: {}".format(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 = [JABREF_PATH, "--version"] | ||
try: | ||
response = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
except subprocess.CalledProcessError as exc: | ||
logging.error("Failed to call JabRef: {} {}".format(exc.returncode, exc.output)) | ||
send_message({"message": "jarNotFound", "path": JABREF_PATH}) | ||
else: | ||
logging.info("Response: {}".format(response)) | ||
send_message({"message": "jarFound"}) | ||
else: | ||
entry = message["text"] | ||
output = add_jabref_entry(entry) | ||
send_message({"message": "ok", "output": str(output)}) |
3 changes: 3 additions & 0 deletions
3
buildres/mac/native-messaging-host/chromium/bifehkofibaamoeaopjglfkddgkijdlh.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"external_update_url": "https://clients2.google.com/service/update2/crx" | ||
} |
9 changes: 9 additions & 0 deletions
9
buildres/mac/native-messaging-host/chromium/org.jabref.jabref.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "org.jabref.jabref", | ||
"description": "JabRef", | ||
"path": "/Applications/JabRef.app/Contents/Resources/jabrefHost.py", | ||
"type": "stdio", | ||
"allowed_origins": [ | ||
"chrome-extension://bifehkofibaamoeaopjglfkddgkijdlh/" | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
buildres/mac/native-messaging-host/firefox/org.jabref.jabref.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "org.jabref.jabref", | ||
"description": "JabRef", | ||
"path": "/Applications/JabRef.app/Contents/Resources/jabrefHost.py", | ||
"type": "stdio", | ||
"allowed_extensions": [ | ||
"browserextension@jabref.org", | ||
"@jabfox" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env sh | ||
|
||
chown root:wheel "INSTALL_LOCATION" | ||
chmod a+rX "INSTALL_LOCATION" | ||
chmod +r "APP_LOCATION/"*.jar | ||
# Trigger an auto-install of the browser addon for chrome/chromium browsers | ||
# First create the necessary path, then copy the autoinstall file. | ||
install -d /Library/Application\ Support/Google/Chrome/External\ Extensions/ | ||
install -m0644 /Applications/JabRef.app/Contents/Resources/native-messaging-host/chromium/bifehkofibaamoeaopjglfkddgkijdlh.json /Library/Application\ Support/Google/Chrome/External\ Extensions/bifehkofibaamoeaopjglfkddgkijdlh.json | ||
# Install the native-messaging host script for firefox/chrome/chromium | ||
install -d /Library/Application Support/Mozilla/NativeMessagingHosts/ | ||
install -m0755 /Applications/JabRef.app/Contents/Resources/native-messaging-host/firefox/org.jabref.jabref.json /Library/Application Support/Mozilla/NativeMessagingHosts/org.jabref.jabref.json | ||
install -d /Library/Application Support/Chromium/NativeMessagingHosts/ | ||
install -m0755 /Applications/JabRef.app/Contents/Resources/native-messaging-host/chromium/org.jabref.jabref.json /Library/Application Support/Chromium/NativeMessagingHosts/org.jabref.jabref.json | ||
install -d /Library/Google/Chrome/NativeMessagingHosts/ | ||
install -m0755 /Applications/JabRef.app/Contents/Resources/native-messaging-host/chromium/org.jabref.jabref.json /Library/Google/Chrome/NativeMessagingHosts/org.jabref.jabref.json | ||
|
||
exit 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not possible to reuse the linux version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is basically the same file. The issue is that with the --resource-dir option in jpackage I cannot add a single file from another directory.
So I copied it and changed the path settings.