From 26504893e75fb33e9d3f01abdebf1d61f362f1b1 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 5 Apr 2025 19:07:03 +0530 Subject: Set url for windows synchronously + handle title change in webview --- src/widgets/BrowserWindow.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/widgets/BrowserWindow.cpp') diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index ff05b0e..2867379 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -4,7 +4,6 @@ #include #include "Configuration.hpp" -#include "LuaRuntime.hpp" #include "WindowMediator.hpp" #include "keymap/KeymapEvaluator.hpp" #include "widgets/BrowserWindow.hpp" @@ -22,9 +21,19 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi centralWidget()->setLayout(layout); // Web engine - auto *web_view_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); - layout->addWidget(web_view_stack); + auto *webview_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); + layout->addWidget(webview_stack); + // Open webviews for given urls + if (urls.isEmpty()) { + webview_stack->open_url(configuration.new_tab_url.toString(), OpenType::OpenUrlInTab); + } else { + for (const auto &url : urls) { + webview_stack->open_url(url, OpenType::OpenUrlInTab); + } + } + + // Default keymaps auto &keymap_evaluator = KeymapEvaluator::instance(); // TODO: remove @@ -36,22 +45,16 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi }); keymap_evaluator.add_keymap(KeyMode::Normal, "a", []() { qDebug() << "Stuff"; }); - win_mediator = new WindowMediator(web_view_stack); + win_mediator = new WindowMediator(webview_stack); - connect(web_view_stack, &WebViewStack::current_webview_changed, this, [this](int index) { + // Update window title when webview changes + connect(webview_stack, &WebViewStack::current_webview_title_changed, this, [this](int index) { auto webviews = win_mediator->get_webview_list(); if (index >= 0 && index < webviews.count()) { const auto &webview = webviews.at(index); setWindowTitle(webview.title); } }); - - auto &lua = LuaRuntime::instance(); - lua.queue_task([this, urls]() { - for (const auto &url : urls) { - emit win_mediator->url_opened(url, OpenType::OpenUrlInTab, 0); - } - }); } void BrowserWindow::closeEvent(QCloseEvent * /*event*/) { emit closed(); } -- cgit v1.3.1