Skip to content
This repository was archived by the owner on Jul 26, 2024. It is now read-only.

Commit 9fce75f

Browse files
committed
refactoring and typing
1 parent fa70fa3 commit 9fce75f

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

paling/edge.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
name = 'Edge'
44

5-
def run(path, options, start_urls):
5+
def run(path: str, options: dict, start_urls: list) -> None:
6+
"""
7+
Run the specified web browser with the given options and start URLs.
8+
9+
Args:
10+
path (str): The path to the web browser executable.
11+
options (dict): A dictionary of options for the web browser.
12+
start_urls (list): A list of URLs to open in the web browser.
13+
14+
Returns:
15+
None
16+
"""
617
if path != 'edge_legacy':
718
if options['app_mode']:
819
for url in start_urls:
@@ -16,13 +27,19 @@ def run(path, options, start_urls):
1627
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
1728
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
1829

19-
def find_path():
30+
def find_path() -> str | None:
2031
if sys.platform in ['win32', 'win64']:
2132
return _find_edge_win()
2233
else:
2334
return None
2435

25-
def _find_edge_win():
36+
def _find_edge_win() -> str:
37+
"""
38+
Finds the path of the Microsoft Edge browser executable on Windows.
39+
40+
Returns:
41+
str: The path of the Microsoft Edge browser executable.
42+
"""
2643
import winreg as reg
2744
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe'
2845

@@ -33,7 +50,7 @@ def _find_edge_win():
3350
reg_key.Close()
3451
if not os.path.isfile(edge_path):
3552
continue
36-
except WindowsError:
53+
except FileNotFoundError:
3754
edge_path = 'edge_legacy'
3855
else:
3956
break

paling/electron.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
name: str = 'Electron'
1111

1212
def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None:
13+
"""
14+
Run the specified Electron application.
15+
16+
Args:
17+
path (str): The path to the Electron application executable.
18+
options (OptionsDictT): A dictionary containing options for the Electron application.
19+
start_urls (List[str]): A list of URLs to open in the Electron application.
20+
21+
Raises:
22+
TypeError: If the 'cmdline_args' option is not of type List[str].
23+
"""
1324
if not isinstance(options['cmdline_args'], list):
1425
raise TypeError("'cmdline_args' option must be of type List[str]")
1526
cmd = [path] + options['cmdline_args']
@@ -18,12 +29,18 @@ def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None:
1829

1930

2031
def find_path() -> Optional[str]:
32+
"""
33+
Finds the path to the Electron executable.
34+
35+
Returns:
36+
Optional[str]: The path to the Electron executable if found, otherwise None.
37+
"""
2138
if sys.platform in ['win32', 'win64']:
2239
# It doesn't work well passing the .bat file to Popen, so we get the actual .exe
2340
bat_path = wch.which('electron')
2441
return os.path.join(bat_path, r'..\node_modules\electron\dist\electron.exe')
2542
elif sys.platform in ['darwin', 'linux']:
26-
# This should work find...
43+
# This should work fine...
2744
return wch.which('electron') # type: ignore # whichcraft doesn't currently have type hints
2845
else:
2946
return None

0 commit comments

Comments
 (0)