瀏覽代碼

changed local dir to be default

smug 1 年之前
父節點
當前提交
e295a3ceb6
共有 4 個文件被更改,包括 11 次插入7 次删除
  1. 1 1
      nicegui/globals.py
  2. 3 3
      nicegui/run.py
  3. 2 0
      nicegui/run_with.py
  4. 5 3
      nicegui/storage.py

+ 1 - 1
nicegui/globals.py

@@ -41,7 +41,7 @@ reload: bool
 title: str
 viewport: str
 favicon: Optional[Union[str, Path]]
-storage_dir: Optional[Union[str, Path]]
+storage_path: Optional[Union[str, Path]]
 dark: Optional[bool]
 language: Language
 binding_refresh_interval: float

+ 3 - 3
nicegui/run.py

@@ -65,7 +65,7 @@ def run(*,
         prod_js: bool = True,
         endpoint_documentation: Literal['none', 'internal', 'page', 'all'] = 'none',
         storage_secret: Optional[str] = None,
-        storage_dir: Optional[Union[str, Path]] = None,
+        storage_path: Optional[Union[str, Path]] = None,
         **kwargs: Any,
         ) -> None:
     '''ui.run
@@ -95,7 +95,7 @@ def run(*,
     :param prod_js: whether to use the production version of Vue and Quasar dependencies (default: `True`)
     :param endpoint_documentation: control what endpoints appear in the autogenerated OpenAPI docs (default: 'none', options: 'none', 'internal', 'page', 'all')
     :param storage_secret: secret key for browser based storage (default: `None`, a value is required to enable ui.storage.individual and ui.storage.browser)
-    :param storage_dir: directory for local based storage (default: `None`, default is the temp directory, absolute path must be specified if not None)
+    :param storage_path: directory for local based storage (default: `None`, local directory is default, 'temp' for temp directory and for a custom path use the absolute path)
     :param kwargs: additional keyword arguments are passed to `uvicorn.run`    
     '''
     globals.ui_run_has_been_called = True
@@ -109,7 +109,7 @@ def run(*,
     globals.tailwind = tailwind
     globals.prod_js = prod_js
     globals.endpoint_documentation = endpoint_documentation
-    globals.storage_dir = storage_dir
+    globals.storage_path = storage_path
 
     for route in globals.app.routes:
         if not isinstance(route, Route):

+ 2 - 0
nicegui/run_with.py

@@ -21,6 +21,7 @@ def run_with(
     tailwind: bool = True,
     prod_js: bool = True,
     storage_secret: Optional[str] = None,
+    storage_path: Optional[Union[str, Path]] = None,
 ) -> None:
     globals.ui_run_has_been_called = True
     globals.title = title
@@ -31,6 +32,7 @@ def run_with(
     globals.binding_refresh_interval = binding_refresh_interval
     globals.tailwind = tailwind
     globals.prod_js = prod_js
+    globals.storage_path = storage_path
 
     set_storage_secret(storage_secret)
     app.on_event('startup')(lambda: handle_startup(with_welcome_message=False))

+ 5 - 3
nicegui/storage.py

@@ -75,10 +75,12 @@ class RequestTrackingMiddleware(BaseHTTPMiddleware):
 class Storage:
 
     def __init__(self) -> None:
-        if globals.storage_dir is not None:
-            self.storage_dir = Path(globals.storage_dir)
-        else:
+        if globals.storage_path == 'temp':
             self.storage_dir = Path(gettempdir() / 'nicegui')
+        elif globals.storage_path is not None and globals.storage_path != 'temp':
+            self.storage_dir = Path(globals.storage_path)
+        else:
+            self.storage_dir = Path('.nicegui')
 
         self._general = PersistentDict(self.storage_dir / 'storage_general.json')
         self._users: Dict[str, PersistentDict] = {}