Skip to content

Commit

Permalink
Merge branch 'main' of github.com:zauberzeug/nicegui
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Dec 15, 2024
2 parents 835268d + a5bbea6 commit 9c7a40e
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions nicegui/ui_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys
from pathlib import Path
from typing import Any, List, Literal, Optional, Tuple, Union
from typing import Any, List, Literal, Optional, Tuple, TypedDict, Union

from starlette.routing import Route
from uvicorn.main import STARTUP_FAILURE
Expand All @@ -21,6 +21,28 @@
APP_IMPORT_STRING = 'nicegui:app'


class ContactDict(TypedDict):
name: Optional[str]
url: Optional[str]
email: Optional[str]


class LicenseInfoDict(TypedDict):
name: str
identifier: Optional[str]
url: Optional[str]


class DocsConfig(TypedDict):
title: Optional[str]
summary: Optional[str]
description: Optional[str]
version: Optional[str]
terms_of_service: Optional[str]
contact: Optional[ContactDict]
license_info: Optional[LicenseInfoDict]


def run(*,
host: Optional[str] = None,
port: Optional[int] = None,
Expand All @@ -31,7 +53,7 @@ def run(*,
language: Language = 'en-US',
binding_refresh_interval: float = 0.1,
reconnect_timeout: float = 3.0,
fastapi_docs: bool = False,
fastapi_docs: Union[bool, DocsConfig] = False,
show: bool = True,
on_air: Optional[Union[str, Literal[True]]] = None,
native: bool = False,
Expand Down Expand Up @@ -64,7 +86,7 @@ def run(*,
:param language: language for Quasar elements (default: `'en-US'`)
:param binding_refresh_interval: time between binding updates (default: `0.1` seconds, bigger is more CPU friendly)
:param reconnect_timeout: maximum time the server waits for the browser to reconnect (default: 3.0 seconds)
:param fastapi_docs: whether to enable FastAPI's automatic documentation with Swagger UI, ReDoc, and OpenAPI JSON (default: `False`)
:param fastapi_docs: enable FastAPI's automatic documentation with Swagger UI, ReDoc, and OpenAPI JSON (bool or dictionary as described `here<https://fastapi.tiangolo.com/tutorial/metadata/>`_, default: `False`)
:param show: automatically open the UI in a browser tab (default: `True`)
:param on_air: tech preview: `allows temporary remote access <https://nicegui.io/documentation/section_configuration_deployment#nicegui_on_air>`_ if set to `True` (default: disabled)
:param native: open the UI in a native window of size 800x600 (default: `False`, deactivates `show`, automatically finds an open port)
Expand Down Expand Up @@ -113,6 +135,16 @@ def run(*,
core.app.redoc_url = '/redoc'
if not core.app.openapi_url:
core.app.openapi_url = '/openapi.json'
if isinstance(fastapi_docs, dict):
core.app.title = fastapi_docs.get('title') or title
core.app.summary = fastapi_docs.get('summary')
core.app.description = fastapi_docs.get('description') or ''
core.app.version = fastapi_docs.get('version') or '0.1.0'
core.app.terms_of_service = fastapi_docs.get('terms_of_service')
contact = fastapi_docs.get('contact')
license_info = fastapi_docs.get('license_info')
core.app.contact = dict(contact) if contact else None
core.app.license_info = dict(license_info) if license_info else None
core.app.setup()

if on_air:
Expand Down

0 comments on commit 9c7a40e

Please sign in to comment.