mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibHTML+Browser: Show the number of pending resource loads
For now this is simply a counter+hook exposed by ResourceLoader and shown in the Browser status bar. This is not very nuanced, and it would be nice to expose more info so we could eventually do something like a progress bar.
This commit is contained in:
parent
bf5a65d934
commit
06113b4ffe
3 changed files with 22 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <LibHTML/Layout/LayoutNode.h>
|
#include <LibHTML/Layout/LayoutNode.h>
|
||||||
#include <LibHTML/Parser/CSSParser.h>
|
#include <LibHTML/Parser/CSSParser.h>
|
||||||
#include <LibHTML/Parser/HTMLParser.h>
|
#include <LibHTML/Parser/HTMLParser.h>
|
||||||
|
#include <LibHTML/ResourceLoader.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char* home_url = "file:///home/anon/www/welcome.html";
|
static const char* home_url = "file:///home/anon/www/welcome.html";
|
||||||
|
@ -78,6 +79,14 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto statusbar = GStatusBar::construct(widget);
|
auto statusbar = GStatusBar::construct(widget);
|
||||||
|
|
||||||
|
ResourceLoader::the().on_load_counter_change = [&] {
|
||||||
|
if (ResourceLoader::the().pending_loads() == 0) {
|
||||||
|
statusbar->set_text("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
statusbar->set_text(String::format("Loading (%d pending resources...)", ResourceLoader::the().pending_loads()));
|
||||||
|
};
|
||||||
|
|
||||||
auto menubar = make<GMenuBar>();
|
auto menubar = make<GMenuBar>();
|
||||||
|
|
||||||
auto app_menu = make<GMenu>("Browser");
|
auto app_menu = make<GMenu>("Browser");
|
||||||
|
|
|
@ -35,7 +35,13 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> call
|
||||||
request.set_url(url);
|
request.set_url(url);
|
||||||
request.set_method(CHttpRequest::Method::GET);
|
request.set_method(CHttpRequest::Method::GET);
|
||||||
auto job = request.schedule();
|
auto job = request.schedule();
|
||||||
job->on_finish = [job, callback = move(callback)](bool success) {
|
++m_pending_loads;
|
||||||
|
if (on_load_counter_change)
|
||||||
|
on_load_counter_change();
|
||||||
|
job->on_finish = [this, job, callback = move(callback)](bool success) {
|
||||||
|
--m_pending_loads;
|
||||||
|
if (on_load_counter_change)
|
||||||
|
on_load_counter_change();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
dbg() << "HTTP job failed!";
|
dbg() << "HTTP job failed!";
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
|
|
@ -11,6 +11,12 @@ public:
|
||||||
|
|
||||||
void load(const URL&, Function<void(const ByteBuffer&)>);
|
void load(const URL&, Function<void(const ByteBuffer&)>);
|
||||||
|
|
||||||
|
Function<void()> on_load_counter_change;
|
||||||
|
|
||||||
|
int pending_loads() const { return m_pending_loads; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResourceLoader() {}
|
ResourceLoader() {}
|
||||||
|
|
||||||
|
int m_pending_loads { 0 };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue