diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-29 12:19:15 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-29 12:20:11 +0530 |
| commit | ed15eba453b7ddd0f4962c2d381fe40751973131 (patch) | |
| tree | 29f8dea45aeb882adfe600b24d789d24da7354dc | |
| parent | bcecbced7e1af9d99443a7e823f18328c7943f09 (diff) | |
| download | null-browser-ed15eba453b7ddd0f4962c2d381fe40751973131.tar.gz null-browser-ed15eba453b7ddd0f4962c2d381fe40751973131.zip | |
Handle default for webview id
Diffstat (limited to '')
| -rw-r--r-- | config.lua | 5 | ||||
| -rw-r--r-- | src/AsyncEventLoop.cpp | 2 | ||||
| -rw-r--r-- | src/LuaRuntime.cpp | 8 | ||||
| -rw-r--r-- | src/LuaRuntime.hpp | 2 | ||||
| -rw-r--r-- | src/WindowActionRouter.cpp | 8 | ||||
| -rw-r--r-- | src/WindowMediator.hpp | 2 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 22 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 4 |
8 files changed, 37 insertions, 16 deletions
@@ -5,7 +5,10 @@ web = web --- @type table uv = uv -local function trim(s) return s:gsub("^%s*(.-)%s*$", "%1") end +local function trim(s) + local res, _ = string.gsub(s, "^%s*(.-)%s*$", "%1") + return res +end local function get_current_tab_index() local currentTab = web.tabs.current(); diff --git a/src/AsyncEventLoop.cpp b/src/AsyncEventLoop.cpp index 0ee9986..f11babb 100644 --- a/src/AsyncEventLoop.cpp +++ b/src/AsyncEventLoop.cpp @@ -47,9 +47,7 @@ void AsyncEventLoop::process_tasks() { void AsyncEventLoop::run_loop() { is_loop_running = true; while (is_loop_running) { - // qDebug() << "loop iteration" << uv_loop_alive(loop); uv_run(loop, UV_RUN_NOWAIT); - // qDebug() << "uv_run() returned: " << result; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index 523fe59..0ef7ef8 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -96,6 +96,7 @@ void LuaRuntime::init_web_lib() { {"current", &LuaRuntime::lua_tab_current}, {"list", &LuaRuntime::lua_tab_list}, {"select", &LuaRuntime::lua_tab_select}, + {"set_url", &LuaRuntime::lua_open_url}, {nullptr, nullptr}, }; luaL_newlib(state, webtabs); @@ -130,16 +131,17 @@ QVariant LuaRuntime::get_lua_value(int idx, QVariant default_value) { } int LuaRuntime::lua_open_url(lua_State *state) { - const char *url = luaL_optstring(state, 1, ""); + const char *url = lua_tostring(state, 1); + WebViewId tab_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); auto *runtime = LuaRuntime::instance(); - emit runtime->url_opened(url, OpenType::OpenUrl); + emit runtime->url_opened(url, OpenType::OpenUrl, tab_id); return 1; } int LuaRuntime::lua_tab_create(lua_State *state) { const char *url = luaL_optstring(state, 1, ""); auto *runtime = LuaRuntime::instance(); - emit runtime->url_opened(url, OpenType::OpenUrlInTab); + emit runtime->url_opened(url, OpenType::OpenUrlInTab, 0); return 1; } diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp index 7ad96df..ade8ed3 100644 --- a/src/LuaRuntime.hpp +++ b/src/LuaRuntime.hpp @@ -46,7 +46,7 @@ signals: void history_back_requested(WebViewId webview_id, qsizetype history_index); void history_forward_requested(WebViewId webview_id, qsizetype history_index); void keymap_added(QString mode, QString keyseq, std::function<void()>); - void url_opened(QString url, OpenType open_type); + void url_opened(QString url, OpenType open_type, WebViewId webview_id); void webview_closed(WebViewId webview_id); void webview_selected(WebViewId webview_id); diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp index 160164d..e530455 100644 --- a/src/WindowActionRouter.cpp +++ b/src/WindowActionRouter.cpp @@ -3,6 +3,7 @@ #include "LuaRuntime.hpp" #include "WindowActionRouter.hpp" +#include "widgets/WebViewStack.hpp" WindowActionRouter::WindowActionRouter() { auto *runtime = LuaRuntime::instance(); @@ -20,7 +21,6 @@ WindowActionRouter::WindowActionRouter() { [this](WebViewId webview_id, qsizetype history_index) { for (auto &win : window_map) { auto *mediator = win.second->mediator(); - qDebug() << "BACK" << webview_id; if (mediator->has_webview(webview_id)) { emit mediator->history_back_requested(webview_id, history_index); @@ -39,10 +39,12 @@ WindowActionRouter::WindowActionRouter() { }); connect(runtime, &LuaRuntime::url_opened, this, - [this](const QString &url, OpenType open_type) { + [this](const QString &url, OpenType open_type, WebViewId webview_id) { for (auto &win : window_map) { auto *mediator = win.second->mediator(); - emit mediator->url_opened(url, open_type); + if (mediator->has_webview(webview_id)) { + emit mediator->url_opened(url, open_type, webview_id); + } } }); connect(runtime, &LuaRuntime::webview_closed, this, diff --git a/src/WindowMediator.hpp b/src/WindowMediator.hpp index 3c35de2..f04763c 100644 --- a/src/WindowMediator.hpp +++ b/src/WindowMediator.hpp @@ -23,7 +23,7 @@ signals: void history_back_requested(WebViewId webview_id, qsizetype history_index); void history_forward_requested(WebViewId webview_id, qsizetype history_index); void keymap_added(QString mode, QString keyseq, std::function<void()>); - void url_opened(QString url, OpenType open_type); + void url_opened(QString url, OpenType open_type, WebViewId webview_id); void webview_closed(WebViewId webview_id); void webview_selected(WebViewId webview_id); diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index f1c799f..6265855 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -18,10 +18,11 @@ WebViewStack::WebViewStack(const Configuration *configuration, create_new_webview(configuration->new_tab_url, true); } -void WebViewStack::open_url(const QUrl &url, OpenType open_type) { +void WebViewStack::open_url(const QUrl &url, OpenType open_type, + WebViewId webview_id) { switch (open_type) { case OpenType::OpenUrl: - set_current_url(url); + set_webview_url(url, webview_id); break; case OpenType::OpenUrlInTab: create_new_webview(url, true); @@ -77,8 +78,12 @@ void WebViewStack::on_new_webview_request( } int32_t WebViewStack::get_webview_index(WebViewId webview_id) { - if (webview_id == 0 && window()->isActiveWindow()) - webview_id = current_webview_id(); + if (webview_id == 0) { + if (window()->isActiveWindow()) + webview_id = current_webview_id(); + else + return -1; + } int index = 0; for (auto &webview : webview_list) { @@ -203,3 +208,12 @@ void WebViewStack::set_current_url(const QUrl &url) { webview->setUrl(url); } +void WebViewStack::set_webview_url(const QUrl &url, WebViewId webview_id) { + auto *webview = get_webview(webview_id); + if (webview == nullptr) { + qDebug() << "No current webview"; + return; + } + + webview->setUrl(url); +} diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index f9ce397..03581e8 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -38,6 +38,7 @@ public: WebViewId current_webview_id(); uint32_t count(); QUrl current_url(); + void set_webview_url(const QUrl &url, WebViewId webview_id); bool has_webview(WebViewId webview_id); @@ -53,7 +54,8 @@ protected: WebView *get_webview(WebViewId webview_id); public slots: - void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl); + void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl, + WebViewId webview_id = 0); void webview_history_back(WebViewId webview_id, qsizetype history_index); void webview_history_forward(WebViewId webview_id, qsizetype history_index); void close(WebViewId webview_id); |
