Skip to content

Commit

Permalink
Narrowed types and moved type hints inline for chrome.py
Browse files Browse the repository at this point in the history
  • Loading branch information
thatfloflo committed Feb 10, 2023
1 parent be7e70e commit b3cf69a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
19 changes: 11 additions & 8 deletions eel/chrome.py
@@ -1,22 +1,24 @@
from __future__ import annotations
import sys, subprocess as sps, os
from typing import Dict, List, Any, Optional

# Every browser specific module must define run(), find_path() and name like this

name = 'Google Chrome/Chromium'
name: str = 'Google Chrome/Chromium'

def run(path, options, start_urls):
def run(path: str, options: Dict[str, Any], start_urls: List[str]):
if options['app_mode']:
for url in start_urls:
sps.Popen([path, '--app=%s' % url] +
options['cmdline_args'],
stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE)
else:
args = options['cmdline_args'] + start_urls
args: List[str] = options['cmdline_args'] + start_urls
sps.Popen([path, '--new-window'] + args,
stdout=sps.PIPE, stderr=sys.stderr, stdin=sps.PIPE)


def find_path():
def find_path() -> Optional[str]:
if sys.platform in ['win32', 'win64']:
return _find_chrome_win()
elif sys.platform == 'darwin':
Expand All @@ -27,7 +29,7 @@ def find_path():
return None


def _find_chrome_mac():
def _find_chrome_mac() -> Optional[str]:
default_dir = r'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
if os.path.exists(default_dir):
return default_dir
Expand All @@ -39,7 +41,7 @@ def _find_chrome_mac():
return None


def _find_chromium_mac():
def _find_chromium_mac() -> Optional[str]:
default_dir = r'/Applications/Chromium.app/Contents/MacOS/Chromium'
if os.path.exists(default_dir):
return default_dir
Expand All @@ -51,7 +53,7 @@ def _find_chromium_mac():
return None


def _find_chrome_linux():
def _find_chrome_linux() -> Optional[str]:
import whichcraft as wch
chrome_names = ['chromium-browser',
'chromium',
Expand All @@ -65,9 +67,10 @@ def _find_chrome_linux():
return None


def _find_chrome_win():
def _find_chrome_win() -> Optional[str]:
import winreg as reg
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
chrome_path: Optional[str] = None

for install_type in reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE:
try:
Expand Down
29 changes: 0 additions & 29 deletions eel/chrome.pyi

This file was deleted.

0 comments on commit b3cf69a

Please sign in to comment.