Skip to content

Reuse the post view dialog and WebView instead of rebuilding it each time - #171

Open
garo-pro wants to merge 1 commit into
trypsynth:mainfrom
garo-pro:fix-164-reuse-webview
Open

garo-pro wants to merge 1 commit into
trypsynth:mainfrom
garo-pro:fix-164-reuse-webview

Conversation

@garo-pro

Copy link
Copy Markdown

Reuse the post view dialog and WebView instead of rebuilding it each time

Fixes #164

Problem

show_post_view_dialog (src/ui/dialogs/post_view.rs) created a new Dialog and WebView on every call and destroyed them when the dialog closed. Each time a user viewed a post, WebView2 had to be initialized from scratch. That made opening a post slow, and it brought back the first-launch layout problem on every open: lines were shorter than the user's NVDA/Windows text settings called for.

Change

The dialog, its WebView, and the Boost/Favorite buttons are now built once and cached in a thread_local. Each view only does the following:

  • sets the dialog title,
  • sets the Boost/Unboost and Favorite/Unfavorite labels from the post's current state,
  • calls set_page with the new content.

The script injection (Escape to close, link handling) stays in the on_loaded handler. It is registered once and runs after every set_page, so behavior is unchanged. The dialog is no longer destroyed after show_modal. It lives for the life of the app, and wx tears it down with its parent frame on exit.

Trade-offs

  • A WebView2 instance now stays alive after the first post view, which uses more memory than before. This is the cost of not reinitializing it each time.
  • The cached dialog is parented to the frame passed on first use. That is always the main frame today.

Testing

  • cargo clippy and cargo test pass, and CI is green on my fork.
  • Tested manually: the post view now opens without the WebView2 reload delay after the first time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webview2 reinicializes every time now

1 participant