aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.org8
-rw-r--r--config.lua2
-rw-r--r--lua/null-browser/api.lua3
-rw-r--r--src/LuaRuntime.hpp1
-rw-r--r--src/LuaRuntimeApi.hpp8
-rw-r--r--src/WindowActionRouter.cpp4
-rw-r--r--src/WindowMediator.hpp1
-rw-r--r--src/widgets/WebView.cpp16
-rw-r--r--src/widgets/WebView.hpp28
-rw-r--r--src/widgets/WebViewStack.cpp10
-rw-r--r--src/widgets/WebViewStack.hpp1
11 files changed, 80 insertions, 2 deletions
diff --git a/TODO.org b/TODO.org
index bf2511e..df1c04c 100644
--- a/TODO.org
+++ b/TODO.org
@@ -1,7 +1,7 @@
** Usable
-- [ ] Tests for api
- [X] Search text in page
-- [ ] Dev tools
+- [X] Dev tools
+- [ ] Tests for api
- [ ] Fullscreen
- [ ] Zoom in/out
- [ ] Scroll api (j/k/h/l/gg/G)
@@ -16,6 +16,7 @@
- [ ] INVESTIGATE: Errors in keymap/thread segfaults
** Next
+- [ ] Allow toggling devtools
- [ ] Tests for window
- [ ] More tests for stack
- [ ] Tests for router
@@ -111,4 +112,7 @@ web.event.add_listener('SearchChanged', {
-- OR inject js into view to show ui
end,
})
+
+web.view.open_devtools()
+web.view.open_devtools(2)
#+end_src
diff --git a/config.lua b/config.lua
index 79ab751..145d7a7 100644
--- a/config.lua
+++ b/config.lua
@@ -147,4 +147,6 @@ web.keymap.set('n', 'tp', function()
web.views.select(views[index].id)
end)
+web.keymap.set('n', '<c-i>', function() web.view.open_devtools() end)
+
print('ending...')
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua
index 5e4beab..dfbfe0f 100644
--- a/lua/null-browser/api.lua
+++ b/lua/null-browser/api.lua
@@ -189,4 +189,7 @@ function web.search.next(view_id) return __internals.search_next(view_id) end
-- TODO: Documentation please
function web.search.previous(view_id) return __internals.search_previous(view_id) end
+-- TODO: Documentation please
+function web.view.open_devtools(view_id) return __internals.view_open_devtools(view_id) end
+
print("api loaded")
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp
index 0855570..0d05a1d 100644
--- a/src/LuaRuntime.hpp
+++ b/src/LuaRuntime.hpp
@@ -55,6 +55,7 @@ signals:
void search_requested(const QString &text, WebViewId webview_id);
void search_next_requested(WebViewId webview_id);
void search_previous_requested(WebViewId webview_id);
+ void devtools_requested(WebViewId webview_id);
protected:
LuaRuntime();
diff --git a/src/LuaRuntimeApi.hpp b/src/LuaRuntimeApi.hpp
index b6302ff..ff2f46c 100644
--- a/src/LuaRuntimeApi.hpp
+++ b/src/LuaRuntimeApi.hpp
@@ -209,6 +209,13 @@ int lua_api_search_previous(lua_State *state) {
return 1;
}
+int lua_api_view_open_devtools(lua_State *state) {
+ WebViewId view_id = lua_isnoneornil(state, 1) ? 0 : lua_tointeger(state, 1);
+ auto &runtime = LuaRuntime::instance();
+ emit runtime.devtools_requested(view_id);
+ return 1;
+}
+
// NOLINTNEXTLINE
static luaL_Reg internals_api[] = {
luaL_Reg{"event_add_listener", &lua_event_register},
@@ -226,5 +233,6 @@ static luaL_Reg internals_api[] = {
luaL_Reg{"search_set_text", &lua_api_search_set_text},
luaL_Reg{"search_previous", &lua_api_search_previous},
luaL_Reg{"search_next", &lua_api_search_next},
+ luaL_Reg{"view_open_devtools", &lua_api_view_open_devtools},
luaL_Reg{nullptr, nullptr},
};
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 5f787c0..9cc9f71 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -75,6 +75,10 @@ void WindowActionRouter::initialize(Configuration *config) {
win_match.second->mediator()->set_search_text(this->current_search_text, webview_id, false);
})
});
+ connect(&runtime, &LuaRuntime::devtools_requested, this, [this](WebViewId webview_id) {
+ WITH_WEBVIEW_WINDOW(webview_id, window,
+ { win_match.second->mediator()->open_devtools(webview_id); })
+ });
}
void WindowActionRouter::add_window(BrowserWindow *window) {
diff --git a/src/WindowMediator.hpp b/src/WindowMediator.hpp
index 17190b3..2e341c0 100644
--- a/src/WindowMediator.hpp
+++ b/src/WindowMediator.hpp
@@ -17,6 +17,7 @@ public:
DELEGATE(webview_stack, current_webview_id, current_webview_id)
DELEGATE(webview_stack, get_webview_list, get_webview_list)
DELEGATE(webview_stack, set_search_text, set_search_text)
+ DELEGATE(webview_stack, open_devtools, open_devtools)
signals:
void history_back_requested(WebViewId webview_id, qsizetype history_index);
diff --git a/src/widgets/WebView.cpp b/src/widgets/WebView.cpp
index 300f8ae..aead605 100644
--- a/src/widgets/WebView.cpp
+++ b/src/widgets/WebView.cpp
@@ -1,3 +1,4 @@
+#include <QMainWindow>
#include <QWebEngineView>
#include <QtCore>
@@ -5,3 +6,18 @@
WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node)
: QWebEngineView(profile, parent_node), id(webview_id) {}
+
+void WebView::open_devtools() {
+ if (devtools_window != nullptr)
+ return;
+
+ devtools_window = new DevtoolsWindow(page()->profile());
+ devtools_window->show();
+
+ connect(devtools_window, &DevtoolsWindow::closed, this, [this]() {
+ devtools_window->deleteLater();
+ devtools_window = nullptr;
+ });
+
+ page()->setDevToolsPage(devtools_window->page());
+}
diff --git a/src/widgets/WebView.hpp b/src/widgets/WebView.hpp
index 98dceba..16c039c 100644
--- a/src/widgets/WebView.hpp
+++ b/src/widgets/WebView.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <QMainWindow>
#include <QWebEngineView>
#include <QtCore>
#include <cstdint>
@@ -7,6 +8,29 @@
#include "utils.hpp"
+class DevtoolsWindow : public QMainWindow {
+ Q_OBJECT
+
+public:
+ DevtoolsWindow(QWebEngineProfile *profile, QWidget *parent = nullptr,
+ Qt::WindowFlags flags = Qt::WindowFlags())
+ : QMainWindow(parent, flags) {
+ webengineview = new QWebEngineView(profile, this);
+ this->setCentralWidget(webengineview);
+ }
+
+ DELEGATE(webengineview, page, page)
+
+signals:
+ void closed();
+
+protected:
+ void closeEvent(QCloseEvent * /* event */) override { emit closed(); }
+
+private:
+ QWebEngineView *webengineview;
+};
+
class WebView : public QWebEngineView {
Q_OBJECT
@@ -14,6 +38,10 @@ public:
WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node = nullptr);
DEFINE_GETTER(get_id, id)
+ void open_devtools();
+
private:
uint32_t id;
+
+ DevtoolsWindow *devtools_window = nullptr;
};
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index 16fd3e9..9eef92a 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -199,6 +199,16 @@ void WebViewStack::focus_webview(WebViewId webview_id) {
layout->setCurrentIndex((int)webview_index);
}
+void WebViewStack::open_devtools(WebViewId webview_id) {
+ auto *webview = get_webview(webview_id);
+ if (webview == nullptr) {
+ qDebug() << "Webview does not exist";
+ return;
+ }
+
+ webview->open_devtools();
+}
+
void WebViewStack::set_search_text(const QString &text, WebViewId webview_id, bool forward) {
auto *webview = get_webview(webview_id);
if (webview == nullptr) {
diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp
index e41af43..fb78255 100644
--- a/src/widgets/WebViewStack.hpp
+++ b/src/widgets/WebViewStack.hpp
@@ -66,6 +66,7 @@ public slots:
void close(WebViewId webview_id);
void focus_webview(WebViewId webview_id);
void set_search_text(const QString &text, WebViewId webview_id, bool forward = true);
+ void open_devtools(WebViewId webview_id);
protected slots:
void on_new_webview_request(const QWebEngineNewWindowRequest &request);