aboutsummaryrefslogtreecommitdiff
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
parent4ccfb93b8c193851f6a208e1e0032ebc02bd768c (diff)
downloadnull-browser-ec909d4211cd124a23f2ea878cc961b8b53f651a.tar.gz
null-browser-ec909d4211cd124a23f2ea878cc961b8b53f651a.zip
Add null_docs_dir & null_assets_dir config options + use in lua
-rw-r--r--CMakeLists.txt7
-rw-r--r--Makefile1
-rw-r--r--lua/null-browser/api.lua8
-rw-r--r--lua/null-browser/extras/hints.lua3
-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
9 files changed, 27 insertions, 25 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a70771..07dce10 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,16 +15,15 @@ set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
find_package(PkgConfig REQUIRED)
-# message(COMMENT "${CMAKE_INSTALL_PREFIX} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}")
+message(COMMENT "${CMAKE_INSTALL_PREFIX} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}")
# Lua path
if(NOT DEFINED CMAKE_INSTALL_PREFIX OR NOT CMAKE_INSTALL_PREFIX)
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX not defined")
endif()
set(PROJECT_TARGET_PATH "${CMAKE_INSTALL_PREFIX}")
-set(NULL_LUA_PREFIX "${PROJECT_TARGET_PATH}/lua")
-set(PROJECT_LUA_PATH "${NULL_LUA_PREFIX}/?.lua")
-add_compile_definitions(PROJECT_LUA_PATH="${PROJECT_LUA_PATH}"
+message(COMMENT "${PROJECT_TARGET_PATH}")
+add_compile_definitions(PROJECT_LUA_PATH="${PROJECT_TARGET_PATH}/lua"
PROJECT_DOCS_PATH="${PROJECT_TARGET_PATH}/docs"
PROJECT_ASSETS_PATH="${PROJECT_TARGET_PATH}/assets")
diff --git a/Makefile b/Makefile
index 39097f3..87f0571 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ dev-setup:
@cp build/compile_commands.json .
build-dev: build-source dev-setup
+ cd build && cmake --install . --prefix "${PREFIX}"
build:
RELEASE=1 make build-source LUA_PREFIX="${PREFIX}/lua"
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua
index e06691e..ee861f0 100644
--- a/lua/null-browser/api.lua
+++ b/lua/null-browser/api.lua
@@ -229,6 +229,8 @@ function web.get(key) return __internals.config_get(key) end
--- @field config_dir string (readonly) Directory where app config is stored
--- @field downloads_dir string Directory where downloaded files go
--- @field new_view_url string URL used when view url is not specified (default: 'https://duckduckgo.com')
+--- @field null_assets_dir string (readonly) Directory where null assets are installed
+--- @field null_docs_dir string (readonly) Directory where null docs are installed
--- @field permissions_persistance 'always'|'session'|'never' How to persist choices for permissions (default: 'always')
--- @field user_agent string User agent sent by the browser
@@ -361,8 +363,8 @@ web.decorations.right = create_decoration_api('right')
--- Get a list of items for help
function web.help.get_items()
- -- TODO: Use proper path from build
- local file, _ = io.open('./docs/api/symbols.json', 'r')
+ local symbols_json = web.opts.null_docs_dir .. '/api/symbols.json'
+ local file, _ = io.open(symbols_json, 'r')
if file then
local contents, _ = file:read('a')
return web.json.decode(contents)
@@ -377,7 +379,7 @@ end
--- @param opts.view number?
function web.help.show(item, opts)
opts = opts or {}
- local url = 'null://docs/api#' .. (item or '')
+ local url = 'null://docs/api/index.html#' .. (item or '')
if opts.view ~= nil then
web.view.set_url(url, opts.view)
else
diff --git a/lua/null-browser/extras/hints.lua b/lua/null-browser/extras/hints.lua
index d708d69..df518cd 100644
--- a/lua/null-browser/extras/hints.lua
+++ b/lua/null-browser/extras/hints.lua
@@ -56,7 +56,8 @@ function hints.stop()
end
function hints._load_hints_js(on_ready)
- web.uv.fs_open('./assets/javascript/hints.js', 'r', 438, function(err, file)
+ local hints_js = web.opts.null_assets_dir .. '/javascript/hints.js'
+ web.uv.fs_open(hints_js, 'r', 438, function(err, file)
if err then return end
if not file then return {} end
local stat = assert(web.uv.fs_fstat(file))
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