Skip to content

Commit

Permalink
Use xdg-open to openurl on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Sep 11, 2021
1 parent 9aaff32 commit 644e2c6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions macast/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,30 +278,32 @@ def dialog(self, content, callback=None, cancel="Cancel", ok="Ok"):
if callback:
callback()

def get_env(self):
# https://github.com/pyinstaller/pyinstaller/issues/3668#issuecomment-742547785
env = Setting.get_system_env()
toDelete = []
for (k, v) in env.items():
if k != 'PATH' and 'tmp' in v:
toDelete.append(k)
for k in toDelete:
env.pop(k, None)
return env

def open_browser(self, url):
if self.platform == Platform.Darwin:
subprocess.Popen(['open', url])
elif self.platform == Platform.Win32:
webbrowser.open(url)
else:
try:
subprocess.Popen("sensible-browser {}".format(url),
shell=True,
env=Setting.get_system_env())
except Exception as e:
logger.error(e)
webbrowser.open(url)
subprocess.Popen(["xdg-open",url], env=self.get_env())

def open_directory(self, path):
if self.platform == Platform.Darwin:
subprocess.Popen(['open', path])
elif self.platform == Platform.Win32:
subprocess.Popen(['explorer.exe', path])
else:
try:
subprocess.Popen(['xdg-open', path])
except Exception as e:
logger.error(str(e))
subprocess.Popen(["xdg-open", path], env=self.get_env())

@staticmethod
def build_menu_item_group(titles, callback):
Expand Down

0 comments on commit 644e2c6

Please sign in to comment.