|
2 | 2 |
|
3 | 3 | #include "duckdb/web/webdb.h" |
4 | 4 |
|
| 5 | +#include <emscripten/val.h> |
| 6 | + |
5 | 7 | #include <chrono> |
6 | 8 | #include <cstddef> |
7 | 9 | #include <cstdio> |
@@ -783,28 +785,52 @@ std::string WebDB::Tokenize(std::string_view text) { |
783 | 785 | /// Get the version |
784 | 786 | std::string_view WebDB::GetVersion() { return database_->LibraryVersion(); } |
785 | 787 |
|
786 | | -class ProgressBarCustom: public ProgressBarDisplay { |
787 | | -public: |
788 | | - ProgressBarCustom() { |
| 788 | +class ProgressBarCustom : public ProgressBarDisplay { |
| 789 | + double value{0.0}; |
| 790 | + double times{0.0}; |
| 791 | + double to_send{1.0}; |
| 792 | + |
| 793 | + public: |
| 794 | + ProgressBarCustom() { |
| 795 | + value = 0.0; |
| 796 | + times = 0.0; |
| 797 | + to_send = 1.0; |
| 798 | + } |
| 799 | + ~ProgressBarCustom() {} |
| 800 | + static void SendMessage(bool end, double percentage, double times) { |
| 801 | + emscripten::val::global("DUCKDB_RUNTIME").call<void>("progressUpdate", end, percentage, times); |
| 802 | + } |
| 803 | + |
| 804 | + public: |
| 805 | + void Update(double percentage) { |
| 806 | + if (percentage >= value + 1.0) { |
| 807 | + value = percentage; |
| 808 | + times = 1.0; |
| 809 | + SendMessage(false, percentage, times); |
| 810 | + to_send = 10.0; |
| 811 | + } else { |
| 812 | + times += 1.0; |
| 813 | + if (times >= to_send) { |
| 814 | + SendMessage(false, percentage, times); |
| 815 | + to_send *= 10.0; |
| 816 | + } |
789 | 817 | } |
790 | | - ~ProgressBarCustom() {} |
791 | | -public: |
792 | | - void Update(double percentage) { |
793 | | - std::cout << "ProgressBar::Update() called with " << percentage << "\n"; |
794 | | - } |
795 | | - void Finish() { |
796 | | - std::cout << "Finish() called\n"; |
797 | | - } |
798 | | - static unique_ptr<ProgressBarDisplay> GetProgressBar() { |
799 | | - return make_uniq<ProgressBarCustom>(); |
800 | | - } |
| 818 | + } |
| 819 | + void Finish() { |
| 820 | + SendMessage(true, value, times); |
| 821 | + value = 0.0; |
| 822 | + times = 0.0; |
| 823 | + to_send = 1.0; |
| 824 | + } |
| 825 | + static unique_ptr<ProgressBarDisplay> GetProgressBar() { return make_uniq<ProgressBarCustom>(); } |
801 | 826 | }; |
802 | 827 |
|
803 | 828 | /// Create a session |
804 | 829 | WebDB::Connection* WebDB::Connect() { |
805 | 830 | auto conn = duckdb::make_uniq<WebDB::Connection>(*this); |
806 | 831 | auto conn_ptr = conn.get(); |
807 | 832 | connections_.insert({conn_ptr, std::move(conn)}); |
| 833 | + ClientConfig::GetConfig(*conn_ptr->connection_.context).wait_time = 1; |
808 | 834 | ClientConfig::GetConfig(*conn_ptr->connection_.context).display_create_func = ProgressBarCustom::GetProgressBar; |
809 | 835 | return conn_ptr; |
810 | 836 | } |
|
0 commit comments