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

Examples: async request no blocking main thread #1578

Conversation

Claudio-code
Copy link
Contributor

Tried fix it #853

  • Make async web request to pokeapi and list all in window
  • When scroll to end make new request and add new pokemons in list

@bilelmoussaoui
Copy link
Member

Thanks a lot for your contribution, please send a PR to add the needed dependencies to https://github.com/gtk-rs/gtk4-rs/blob/master/Dockerfile.

But before doing so, the other option is to disable the default features of reqwest and use rustls-tls instead. That will make the example easily runnable on other platforms like windows

Copy link
Member

@bilelmoussaoui bilelmoussaoui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, few things though:

  • Add a readme for the example
  • The gif example is nice, but please record just the application window without anything else (to reduce the size) and using a light default theme to match all the other examples. The current gif is too large (1.18mb).
  • Please rename the gif to something like screenshot.gif
  • Add the example to the main examples/README.md

examples/Cargo.toml Outdated Show resolved Hide resolved
examples/Cargo.toml Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/main.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/main.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/main.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/main.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/pokemon_client.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/pokemon_client.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/pokemon_client.rs Outdated Show resolved Hide resolved
examples/request_no_blocking_main_thread/main.rs Outdated Show resolved Hide resolved
@Claudio-code Claudio-code force-pushed the example/request_no_blocking_main_thread branch from c8479b4 to 7c5f1ea Compare January 25, 2024 21:03
examples/Cargo.toml Outdated Show resolved Hide resolved
examples/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines 27 to 29
pub fn new() -> Self {
Self { page: 0 }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could derive Default and use that instead

@@ -0,0 +1,107 @@
use glib::clone;
use gtk::glib::once_cell::sync::Lazy;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are removing once_cell usage from our crates, so you should use std::sync::OnceLock here instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't do this and it ends up giving errors because of the listbox, but if you instantiate it within the lambda there is no way for the ScrolledWindow to receive its value. Can you show me an example of what this implementation would look like?

error:
Screenshot from 2024-01-28 15-23-46

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I achieved resolve

@bilelmoussaoui bilelmoussaoui linked an issue Jan 29, 2024 that may be closed by this pull request
@bilelmoussaoui
Copy link
Member

Looks good to me! Still not a fan of the gif, but I will update that later to have a consistent look across the examples.

Thank you for your contribution

@bilelmoussaoui bilelmoussaoui merged commit 88db796 into gtk-rs:master Jan 29, 2024
37 checks passed
@Claudio-code Claudio-code deleted the example/request_no_blocking_main_thread branch January 30, 2024 01:07
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.

Add an example that makes use of async operations
3 participants