Skip to content

Commit

Permalink
Update code for exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bowen-0x00 committed Mar 6, 2024
1 parent 7be6ed7 commit 0345c27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ dist/
.vscode
build/
*.spec
*test*
*test*
*Pipfile*
pack*.bat
24 changes: 18 additions & 6 deletions customProtocolHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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)
print(e)
message(e)

0 comments on commit 0345c27

Please sign in to comment.