Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase initialisation speed by optionally excluding files to scan #697

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ This will start a webserver on the default settings (http://localhost:8000) and

If Chrome or Chromium is installed then by default it will open in that in App Mode (with the `--app` cmdline flag), regardless of what the OS's default browser is set to (it is possible to override this behaviour).

If you have large amounts of .html or .js files, eel.init() might take up a long time to scan those files for exposed functions. By passing a list of paths to the init function's exclude_path parameter you can exclude these files from being scanned.

### App options

Additional options can be passed to `eel.start()` as keyword arguments.
Expand Down
6 changes: 5 additions & 1 deletion eel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def decorator(function: Callable[..., Any]) -> Any:


def init(path: str, allowed_extensions: List[str] = ['.js', '.html', '.txt', '.htm',
'.xhtml', '.vue'], js_result_timeout: int = 10000) -> None:
'.xhtml', '.vue'], exclude_path: List[str] = [], js_result_timeout: int = 10000) -> None:
global root_path, _js_functions, _js_result_timeout
root_path = _get_real_path(path)

Expand All @@ -121,6 +121,10 @@ def init(path: str, allowed_extensions: List[str] = ['.js', '.html', '.txt', '.h
if not any(name.endswith(ext) for ext in allowed_extensions):
continue

# exclude specific file paths to increase loading speed on initialisation
if any(exclude in os.path.join(root, name) for exclude in exclude_path):
continue

try:
with open(os.path.join(root, name), encoding='utf-8') as file:
contents = file.read()
Expand Down