diff --git a/src/ds_stdlib.py b/src/ds_stdlib.py index f962e9e..1c8011d 100644 --- a/src/ds_stdlib.py +++ b/src/ds_stdlib.py @@ -3,6 +3,7 @@ import time import requests from enum import IntEnum import webbrowser +from shared import * default_stdlib_code = """ @@ -107,7 +108,7 @@ class stdlib_fetch_result(IntEnum): stdlib_readme_url = "https://github.com/duckyPad/DPDS-Standard-Library/blob/master/README.md" def open_stdlib_doc_url(): - webbrowser.open(stdlib_readme_url) + open_url_safe(stdlib_readme_url) stdlib_url = 'https://raw.githubusercontent.com/duckyPad/DPDS-Standard-Library/refs/heads/master/releases/duckypad_stdlib_latest.txt' STDLIB_CHECK_INTERVAL_HOURS = 12 diff --git a/src/duckypad_config.py b/src/duckypad_config.py index 63493a6..786dc59 100644 --- a/src/duckypad_config.py +++ b/src/duckypad_config.py @@ -336,9 +336,9 @@ def ui_reset(): def fw_update_click(event, dp_info_dict): if dp_info_dict['dp_model'] == DP_MODEL_OG_DUCKYPAD: - webbrowser.open("https://dekunukem.github.io/duckyPad/firmware_updates_and_version_history.html") + open_url_safe("https://dekunukem.github.io/duckyPad/firmware_updates_and_version_history.html") elif dp_info_dict['dp_model'] == DP_MODEL_DUCKYPAD_PRO: - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/doc/fw_update.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/doc/fw_update.html') def print_fw_update_label(dp_info_dict): this_version = dp_info_dict["fw_version"] @@ -1033,7 +1033,7 @@ def backup_button_click(): elif 'linux' in sys.platform: subprocess.Popen(["xdg-open", backup_path]) else: - webbrowser.open(backup_path) + open_url_safe(backup_path) def key_button_click_event(event): key_button_click(event.widget) diff --git a/src/shared.py b/src/shared.py index 74bff6d..25e323d 100644 --- a/src/shared.py +++ b/src/shared.py @@ -25,32 +25,42 @@ hid_dump_path = os.path.join(app_save_path, "hid_dump") temp_dir_path = os.path.join(app_save_path, "temp_dir") ext_lib_path = os.path.join(app_save_path, "dpds_libs") +def open_url_safe(url): + if sys.platform.startswith('linux') and os.geteuid() == 0: + if os.environ.get('SUDO_USER'): + try: + subprocess.Popen(['sudo', '-u', sudo_user, 'xdg-open', url]) + return + except OSError: + pass + webbrowser.open(url) + def open_discord_link(): - webbrowser.open("https://discord.gg/4sJCBx5") + open_url_safe("https://discord.gg/4sJCBx5") def app_update_click(event): - webbrowser.open('https://github.com/duckyPad/duckyPad-Configurator/releases/latest') + open_url_safe('https://github.com/duckyPad/duckyPad-Configurator/releases/latest') def open_profile_autoswitcher_url(): - webbrowser.open('https://github.com/duckyPad/duckyPad-profile-autoswitcher/blob/master/README.md') + open_url_safe('https://github.com/duckyPad/duckyPad-profile-autoswitcher/blob/master/README.md') def open_tindie_store(): - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/doc/store_links.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/doc/store_links.html') def open_mac_linux_instruction(): - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/doc/linux_macos_notes.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/doc/linux_macos_notes.html') def script_instruction_click(event): - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/doc/duckyscript_info.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/doc/duckyscript_info.html') def open_dpp_page(event): - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/README.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/README.html') def open_duckypad_user_manual_url(): - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/doc/getting_started.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/doc/getting_started.html') def open_duckypad_troubleshooting_url(): - webbrowser.open('https://dekunukem.github.io/duckyPad-Pro/doc/troubleshooting.html') + open_url_safe('https://dekunukem.github.io/duckyPad-Pro/doc/troubleshooting.html') def rgb_to_hex(rgb_tuple): return '#%02x%02x%02x' % rgb_tuple