Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions buildres/linux/jabrefHost.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
JABREF_PATH = "flatpak run org.jabref.jabref"
else:
logging.error("Could not determine JABREF_PATH")
send_message({"message": "error", "output": "Could not find JabRef. Please check that it is installed correctly."})
sys.exit(-1)

logging_dir = Path.home() / ".mozilla/native-messaging-hosts/"
Expand Down Expand Up @@ -75,12 +76,8 @@ def add_jabref_entry(data):
"""Send string via cli as literal to preserve special characters"""
cmd = str(JABREF_PATH).split() + ["--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))
response = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
logging.info("Called JabRef and got: {}".format(response))
return response


Expand All @@ -104,5 +101,9 @@ def add_jabref_entry(data):
send_message({"message": "jarFound"})
else:
entry = message["text"]
output = add_jabref_entry(entry)
send_message({"message": "ok", "output": str(output)})
try:
output = add_jabref_entry(entry)
send_message({"message": "ok", "output": str(output)})
except subprocess.CalledProcessError as exc:
logging.error("Failed to call JabRef: {} {}".format(exc.returncode, exc.output))
send_message({"message": "error", "output": str(exc.output)})
21 changes: 11 additions & 10 deletions buildres/mac/jabrefHost.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

if not JABREF_PATH.exists():
logging.error("Could not determine JABREF_PATH")
send_message({"message": "error", "output": "Could not find JabRef. Please check that it is installed correctly."})
sys.exit(-1)

logging_dir = Path.home() / ".mozilla/native-messaging-hosts/"
Expand Down Expand Up @@ -61,14 +62,10 @@ def send_message(message):

def add_jabref_entry(data):
"""Send string via cli as literal to preserve special characters"""
cmd = [str(JABREF_PATH), "--importBibtex", r"{}".format(data)]
cmd = str(JABREF_PATH).split() + ["--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))
response = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
logging.info("Called JabRef and got: {}".format(response))
return response


Expand All @@ -81,7 +78,7 @@ def add_jabref_entry(data):
logging.info(str(message))

if "status" in message and message["status"] == "validate":
cmd = [JABREF_PATH, "--version"]
cmd = str(JABREF_PATH).split() + ["--version"]
try:
response = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
Expand All @@ -92,5 +89,9 @@ def add_jabref_entry(data):
send_message({"message": "jarFound"})
else:
entry = message["text"]
output = add_jabref_entry(entry)
send_message({"message": "ok", "output": str(output)})
try:
output = add_jabref_entry(entry)
send_message({"message": "ok", "output": str(output)})
except subprocess.CalledProcessError as exc:
logging.error("Failed to call JabRef: {} {}".format(exc.returncode, exc.output))
send_message({"message": "error", "output": str(exc.output)})
17 changes: 16 additions & 1 deletion buildres/windows/JabRefHost.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
@echo off
pushd %~dp0
@powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File ".\JabRefHost.ps1"

:: Test if pwsh exists
where /q pwsh.exe
if %errorlevel%==0 (
@pwsh.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File ".\JabRefHost.ps1"
) else (
:: If not, test if powershell exists
where /q powershell.exe
if %errorlevel%==0 (
@powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File ".\JabRefHost.ps1"
) else (
echo "Could not find pwsh.exe or powershell.exe" 1>&2
echo "Please install PowerShell and try again." 1>&2
exit /b 1
)
)
20 changes: 11 additions & 9 deletions buildres/windows/JabRefHost.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ try {
}

if (-not (Test-Path $jabRefExe)) {
$wshell = New-Object -ComObject Wscript.Shell
$popup = "Unable to locate '$jabRefExe'."
$wshell.Popup($popup,0,"JabRef", 0x0 + 0x30)
return
return Respond @{message="jarNotFound"; output="Unable to locate '$jabRefExe'."}
}

#$wshell = New-Object -ComObject Wscript.Shell
#$wshell.Popup($message.Text,0,"JabRef", 0x0 + 0x30)

$messageText = $message.Text.replace("`n"," ").replace("`r"," ")
$tempfile = New-TemporaryFile
# WriteAllLines should write the file as UTF-8 without BOM
# unlike Out-File which writes UTF-16 with BOM in ps5.1
[IO.File]::WriteAllLines($tempfile, $messageText)
$output = & $jabRefExe -importToOpen $tempfile *>&1
Remove-Item $tempfile
# For debugging: uncomment the following lines to get the output of JabRef be displayed as a popup
#$output = "$messageText"
#$wshell = New-Object -ComObject Wscript.Shell
#$wshell.Popup($output,0,"JabRef", 0x0 + 0x30)
return Respond @{message="ok";output="$output"}
} finally {
return Respond @{message="ok"; output="$output"}
}
catch {
$err = $PSItem
Respond @{message="error"; output="$($err.Exception.Message)"; stacktrace="$($err.ScriptStackTrace)"}
# Still print the error to the console so that it is picked up by the browser in addition
throw $err
}
finally {
$reader.Dispose()
}