Repository: Avaiga/taipy
File: taipy/gui/gui_actions.py (Python)

Code before:
            callback_on_status(True, function_result=res)
        except Exception as e:
            callback_on_status(False, e, user_function.__name__)

    def thread_status(name: str, period_s: float, count: int):
        active_thread = next((t for t in threading.enumerate() if t.name == name), None)
        if active_thread:
            callback_on_status(count)
            threading.Timer(period_s, thread_status, (name, period_s, count + 1)).start()

    thread = threading.Thread(target=user_function_in_thread, args=user_function_args)
    thread.start()
    if isinstance(period, int) and period >= 500 and callable(user_status_function):
        thread_status(thread.name, period / 1000.0, 0)


def get_local_storage(state: State, *keys: str) -> t.Optional[t.Union[str, t.Dict[str, str]]]:
    """Get local storage value(s).
    Arguments:
        state (State^): The current user state as received in any callback.
        *keys (string): The keys to get from the local storage
    Returns:
        All local storage values
    """
    if state and isinstance(state._gui, Gui):
        return state._gui._get_local_storage(*keys)
    _warn("'get_local_storage()' must be called in the context of a callback.")
    return None


Review comment (performance):
Line skip here.

Can this be called anytime in the app life cycle?

I suspect we should add more details on invoking this API (with the complexity of the keys type).

Code after:
        try:
            res = user_function(*uf_args)
            callback_on_status(True, function_result=res)
        except Exception as e:
            callback_on_status(False, e, user_function.__name__)

    def thread_status(name: str, period_s: float, count: int):
        active_thread = next((t for t in threading.enumerate() if t.name == name), None)
        if active_thread:
            callback_on_status(count)
            threading.Timer(period_s, thread_status, (name, period_s, count + 1)).start()

    thread = threading.Thread(target=user_function_in_thread, args=user_function_args)
    thread.start()
    if isinstance(period, int) and period >= 500 and _is_function(user_status_function):
        thread_status(thread.name, period / 1000.0, 0)


def query_local_storage(state: State, *keys: str) -> t.Optional[t.Union[str, t.Dict[str, str]]]:
    """Retrieve values from the browser's local storage.

    This function queries the local storage of the client identified by *state* and returns the
    values associated with the specified keys. Local storage is a key-value store available in the
    user's browser, typically manipulated by client-side code.

    Arguments:
        state (State^): The current user state as received in any callback.
        *keys (string): One or more keys to retrieve values for from the client's local storage.

    Returns:
        The requested values from the browser's local storage.

            - If a single key is provided (*keys* has a single element), this function returns the
              corresponding value as a string.
            - If multiple keys are provided, this function returns a dictionary mapping each key to
              its value in the client's local storage.
            - If no value is found for a key, that key will not appear in the dictionary.
    """
    if state and isinstance(state._gui, Gui):
        return state._gui._query_local_storage(*keys)
    _warn("'query_local_storage()' must be called in the context of a callback.")
    return None