aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-08-12 01:21:15 +0530
committerAkshay Nair <phenax5@gmail.com>2025-08-12 01:21:15 +0530
commitec909d4211cd124a23f2ea878cc961b8b53f651a (patch)
tree1a04e951ec8fb59e488dc35b28728dbad2c1bf9e /src
parent4ccfb93b8c193851f6a208e1e0032ebc02bd768c (diff)
downloadnull-browser-ec909d4211cd124a23f2ea878cc961b8b53f651a.tar.gz
null-browser-ec909d4211cd124a23f2ea878cc961b8b53f651a.zip
Add null_docs_dir & null_assets_dir config options + use in lua
Diffstat (limited to 'src')
-rw-r--r--src/Configuration.hpp19
-rw-r--r--src/LuaRuntime.cpp2
-rw-r--r--src/LuaRuntime.hpp4
-rw-r--r--src/schemes/NullSchemeHandler.cpp5
-rw-r--r--src/schemes/NullSchemeHandler.hpp3
5 files changed, 16 insertions, 17 deletions
diff --git a/src/Configuration.hpp b/src/Configuration.hpp
index 7c97b72..1a0f0dc 100644
--- a/src/Configuration.hpp
+++ b/src/Configuration.hpp
@@ -9,15 +9,20 @@ class Configuration : public QObject {
Q_OBJECT
private:
+ QDir config_dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
std::unordered_map<QString, QVariant> config_map{
{"new_view_url", "https://duckduckgo.com"},
{"close_window_when_no_views", true},
{"user_agent", QWebEngineProfile::defaultProfile()->httpUserAgent()},
{"downloads_dir", QWebEngineProfile::defaultProfile()->downloadPath()},
- {"app_data_dir", QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)},
{"permissions_persistance", "always"},
};
- QDir config_dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
+ std::unordered_map<QString, QVariant> readonly_config_map{
+ {"app_data_dir", QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)},
+ {"config_dir", config_dir.path()},
+ {"null_assets_dir", PROJECT_ASSETS_PATH},
+ {"null_docs_dir", PROJECT_DOCS_PATH},
+ };
public:
using QObject::QObject;
@@ -28,13 +33,13 @@ public:
}
QVariant get_config(const QString &name, QVariant default_value = "") const {
- if (name == "config_dir") // readonly
- return config_dir.path();
+ if (readonly_config_map.contains(name))
+ return readonly_config_map.at(name);
- if (!config_map.contains(name))
- return default_value;
+ if (config_map.contains(name))
+ return config_map.at(name);
- return config_map.at(name);
+ return default_value;
}
bool close_window_when_no_views() const {
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index 76dfb11..52a1c14 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -70,7 +70,7 @@ void LuaRuntime::require_module(const QString &module_name) {
}
void LuaRuntime::init_builtins_package_path() {
- auto builtins_lua_path = QString(PROJECT_LUA_PATH);
+ auto builtins_lua_path = QString(PROJECT_LUA_PATH "/?.lua");
append_package_path(builtins_lua_path);
}
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp
index 8135d04..f8866fd 100644
--- a/src/LuaRuntime.hpp
+++ b/src/LuaRuntime.hpp
@@ -11,10 +11,6 @@
#include "widgets/Decorations.hpp"
#include "widgets/WebView.hpp"
-#ifndef PROJECT_LUA_PATH
-#define PROJECT_LUA_PATH ""
-#endif
-
#define preserve_top(STATE, BODY) \
{ \
const int __top = lua_gettop(STATE); \
diff --git a/src/schemes/NullSchemeHandler.cpp b/src/schemes/NullSchemeHandler.cpp
index 203e673..58ee078 100644
--- a/src/schemes/NullSchemeHandler.cpp
+++ b/src/schemes/NullSchemeHandler.cpp
@@ -16,7 +16,7 @@ void NullSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) {
}
QByteArray NullSchemeHandler::read_static_docs_file(const QString &path) {
- QFile file(NULL_DOCS_DIR + path);
+ QFile file(PROJECT_DOCS_PATH + path);
if (!file.exists())
return read_index_html();
@@ -29,7 +29,8 @@ QByteArray NullSchemeHandler::read_static_docs_file(const QString &path) {
}
QByteArray NullSchemeHandler::read_index_html() {
- QFile file(NULL_DOCS_DIR + QString("/index.html"));
+ // TODO: Change after index is defined
+ QFile file(PROJECT_DOCS_PATH + QString("/api/index.html"));
qDebug() << ":::" << file.exists();
if (file.open(QIODevice::ReadOnly)) {
auto contents = file.readAll();
diff --git a/src/schemes/NullSchemeHandler.hpp b/src/schemes/NullSchemeHandler.hpp
index bc05076..299f1f0 100644
--- a/src/schemes/NullSchemeHandler.hpp
+++ b/src/schemes/NullSchemeHandler.hpp
@@ -7,9 +7,6 @@
#include <qdebug.h>
#include <qurlquery.h>
-// TODO: Install doc dir and pass this path during build
-#define NULL_DOCS_DIR "./doc"
-
class NullSchemeHandler : public QWebEngineUrlSchemeHandler {
Q_OBJECT