Skip to content

Commit bcd27a0

Browse files
fix: replace webbrowser.open with xdg-open with original LD_LIBRARY_PATH
1 parent eadf39d commit bcd27a0

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

aw_qt/trayicon.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
22
import logging
33
import signal
4-
import webbrowser
54
import os
65
import subprocess
6+
import webbrowser
77

88
from PyQt5 import QtCore
99
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMessageBox, QMenu, QWidget, QPushButton
@@ -16,14 +16,40 @@
1616
logger = logging.getLogger(__name__)
1717

1818

19+
def get_env():
20+
"""
21+
Necessary for xdg-open to work properly when PyInstaller overrides LD_LIBRARY_PATH
22+
23+
https://github.com/ActivityWatch/activitywatch/issues/208#issuecomment-417346407
24+
"""
25+
env = dict(os.environ) # make a copy of the environment
26+
lp_key = 'LD_LIBRARY_PATH' # for GNU/Linux and *BSD.
27+
lp_orig = env.get(lp_key + '_ORIG')
28+
if lp_orig is not None:
29+
env[lp_key] = lp_orig # restore the original, unmodified value
30+
else:
31+
# This happens when LD_LIBRARY_PATH was not set.
32+
# Remove the env var as a last resort:
33+
env.pop(lp_key, None)
34+
return env
35+
36+
37+
def open_url(url):
38+
if sys.platform == "linux":
39+
env = get_env()
40+
subprocess.Popen(["xdg-open", url], env=env)
41+
else:
42+
webbrowser.open(url)
43+
44+
1945
def open_webui(root_url):
2046
print("Opening dashboard")
21-
webbrowser.open(root_url)
47+
open_url(root_url)
2248

2349

2450
def open_apibrowser(root_url):
2551
print("Opening api browser")
26-
webbrowser.open(root_url + "/api")
52+
open_url(root_url + "/api")
2753

2854

2955
def open_dir(d):

0 commit comments

Comments
 (0)