diff --git a/.gitignore b/.gitignore index 3badd4c..f3db087 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ dist/ .vscode build/ *.spec -*test* \ No newline at end of file +*test* +*Pipfile* +pack*.bat \ No newline at end of file diff --git a/customProtocolHandler.py b/customProtocolHandler.py index 439b97a..e1b6f65 100644 --- a/customProtocolHandler.py +++ b/customProtocolHandler.py @@ -6,6 +6,9 @@ import configparser from plyer import notification +def convert_to_os_path(string): + converted_path = string.replace('/', os.path.sep).replace('\\', os.path.sep) + return converted_path def bring_window_to_front(window_title): import pygetwindow as gw @@ -14,12 +17,19 @@ def bring_window_to_front(window_title): window[0].activate() +def message(e): + try: + notification.notify(title="Error", message=str(e), timeout=5) + except NotImplementedError: + with open('error.log', 'w') as f: + f.write(str(e)) + def process_custom_protocol(url): parsed_url = urlparse(url) hostname = parsed_url.hostname query_string = parsed_url.query parsed_params = parse_qs(query_string) - file_path = parsed_params.get("file", [""])[0].replace('\\', '/') + file_path: str = convert_to_os_path(parsed_params.get("file", [""])[0]) if hostname == 'open': app = parsed_params.get("app", [""])[0] @@ -40,11 +50,13 @@ def process_custom_protocol(url): subprocess.run(['start', '""', '/wait', file_path], shell=True) if __name__ == "__main__": - url = sys.argv[1] - config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'config.conf')) - config = configparser.ConfigParser() - config.read(config_path) try: + url = sys.argv[1] + config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'config.conf')) + config = configparser.ConfigParser() + config.read(config_path) process_custom_protocol(url) except Exception as e: - notification.notify(title="Error", message=str(e), timeout=5) \ No newline at end of file + print(e) + message(e) + \ No newline at end of file