From 644e2c66a86cff8c3fad413940a5e11b879a38aa Mon Sep 17 00:00:00 2001 From: xfangfang <2553041586@qq.com> Date: Sat, 11 Sep 2021 13:08:24 +0800 Subject: [PATCH] Use xdg-open to openurl on linux --- macast/gui.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/macast/gui.py b/macast/gui.py index 8ab8fc242..6b5e64d3c 100644 --- a/macast/gui.py +++ b/macast/gui.py @@ -278,19 +278,24 @@ 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: @@ -298,10 +303,7 @@ def open_directory(self, 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):