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

Changing the page name also changes the name of the native window #4008

Open
vitalogy opened this issue Nov 19, 2024 · 4 comments
Open

Changing the page name also changes the name of the native window #4008

vitalogy opened this issue Nov 19, 2024 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@vitalogy
Copy link

Description

Thanks for NiceGUI, a great framework ... this makes fun :)

The Problem:
We have a program with a main window (native window) in which you can work, but also do the work in your favorite browser.
When the name of a page is changed in the browser, the name of the main window is also changed. That doesn't look good.
The name of the main window should not change and remain with the name it was initialized with.

I think it's because of this PR #3583

Would it be possible to integrate another parameter/switch to decide whether the title of the main window can be changed? This parameter could have the initial value True.

@rodja
Copy link
Member

rodja commented Nov 20, 2024

Thanks for reporting this. Can you provide a minimum reproducible code example? This would allow us and the community to help more efficiently. Thanks!
Why is it important to provide a minimal reproducible example?

@falkoschindler
Copy link
Contributor

falkoschindler commented Nov 20, 2024

Minimum example:

from nicegui import ui

ui.button('Change title', on_click=lambda: ui.page_title('New title'))

ui.run(title='Title', native=True)

But to me it feels totally fine to change the window title when calling ui.page_title - exactly as discussed in #3583.

To only change the title in the browser, you could use a custom page_title function:

def page_title(title: str) -> None:
    client = ui.context.client
    client.title = title
    if client.has_socket_connection:
        client.run_javascript(f'document.title = {json.dumps(title)}')

@rodja
Copy link
Member

rodja commented Nov 20, 2024

I think it is not obvious that we change the title of the app when using ui.page_title. As @vitalogy described, it even changes the title of the app if the change is called within a separate tab in the web browser. I think it should only change the title if it is called "in the native view".

@falkoschindler
Copy link
Contributor

Ok, looks like we need to introduce a new client.is_native property to only call main_window.set_title for native clients. This could be done with some JavaScript checking for a pywebview object during handshake.
Does anyone want to give it a try?

@falkoschindler falkoschindler added bug Something isn't working help wanted Extra attention is needed labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants