aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--TODO.org30
-rw-r--r--docs/api/index.html441
-rw-r--r--docs/api/symbols.json2
-rw-r--r--init.lua12
-rw-r--r--lua/null-browser/api.lua4
-rw-r--r--lua/null-browser/events.lua79
-rw-r--r--lua/null-browser/utils.lua32
-rw-r--r--src/App.cpp2
-rw-r--r--src/Configuration.hpp8
-rw-r--r--src/InstanceManager.hpp1
-rw-r--r--src/widgets/BrowserApp.cpp6
12 files changed, 579 insertions, 39 deletions
diff --git a/Makefile b/Makefile
index 87f0571..5c86d6d 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,7 @@ check: fmt
clang-tidy --config-file=.clang-tidy ./src/**/*.{hpp,cpp}
docs:
+ rm -rf ./docs/api;
# API reference pages
ldoc -p null-browser -t "Null browser api" \
--merge --ignore --lls \
diff --git a/TODO.org b/TODO.org
index 8ca498b..ad08829 100644
--- a/TODO.org
+++ b/TODO.org
@@ -17,17 +17,17 @@
- [X] Embed docs in app (`null:/docs`)
- [X] web.decorations.*.set_size()
- [X] Vertical tabline ui
-- [ ] Document events and event opts
+- [X] Install docs/ and assets/ in build
+- [X] Make the asset/config/lua paths readable via lua
+- [X] json encode/decode
+- [X] Fix path to symbols.json in web.help.get_items (use docs path)
+- [X] Document events and event opts
- [ ] Update all api to use opts table pattern
-- [ ] Install docs/ and assets/ in build
- [ ] web.keymap.configure_mode(modename, { passthrough = false })
- [ ] Fullscreen
- [ ] Zoom in/out/reset
- [ ] Remove unwanted "async"-ness in lua calls
- [ ] Api for enabling rpc api in view
-- [ ] Make the asset/config/lua paths readable via lua
-- [ ] json encode/decode
-- [ ] Fix path to symbols.json in web.help.get_items (use docs path)
** Bugs
- [ ] Closing webview should close devtools window
@@ -127,22 +127,6 @@ web.decorations.top.disable()
web.decorations.top.set_size(20)
local view_id = web.decorations.top.view()
web.view.set_html('<div>Hello world</div>', { view = view })
-web.decorations.top.destroy() -- Maybe to destroy unwanted webviews
-
--- Show tabs in top decoration
-web.view.expose_js('openTab', function(tabId)
- web.view.select({ view = tabId })
-end, { view = web.decorations.top.view() })
-web.event.add_listener({ 'TabOpen', 'TabClose' }, {
- callback = function()
- local tabs_html = ''
- local views = web.view.list()
- for index, view in ipairs(web.view.list()) do
- local text = index..': '..view.title..' ('..view.url..')'
- local tab = '<span onclick="_nullbrowser.rpc.openTab('..view.id..')">' .. text .. '</span>')
- tabs_html = tabs_html .. tab
- end
- web.view.set_html(tabs_html, { view = web.decorations.top.view() })
- end,
-})
+-- Hide/unhide
+web.decorations.top.set_visible(false)
#+end_src
diff --git a/docs/api/index.html b/docs/api/index.html
index fa2ab5a..cfa0023 100644
--- a/docs/api/index.html
+++ b/docs/api/index.html
@@ -177,6 +177,18 @@
<td class="summary">Open help docs for a given item</td>
</tr>
<tr>
+ <td class="name" nowrap><a href="#print">print (value)</a></td>
+ <td class="summary">Print a lua object to inspect</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#web.json.encode">web.json.encode (obj, opts)</a></td>
+ <td class="summary">Encodes lua object as json into a string</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#web.json.decode">web.json.decode (json_str, opts)</a></td>
+ <td class="summary">Decodes a string into a lua object</td>
+ </tr>
+ <tr>
<td class="name" nowrap><a href="#web.utils.string_trim">web.utils.string_trim (str)</a></td>
<td class="summary">Trim whitespace from start and end of a string</td>
</tr>
@@ -203,6 +215,46 @@
<td class="name" nowrap><a href="#WebOpts">WebOpts</a></td>
<td class="summary">Maps to values defined in ./src/Configuration.hpp</td>
</tr>
+ <tr>
+ <td class="name" nowrap><a href="#WebEvents">WebEvents</a></td>
+ <td class="summary">Events that can be listened to with web.events.add_listener</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#WinCreatedEventOpts">WinCreatedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#ViewCreatedEventOpts">ViewCreatedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#ViewSelectedEventOpts">ViewSelectedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#ViewClosedEventOpts">ViewClosedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#UrlChangedEventOpts">UrlChangedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#PermissionRequestedEventOpts">PermissionRequestedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#ModeChangedEventOpts">ModeChangedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#KeyPressedEventOpts">KeyPressedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#NotificationReceivedEventOpts">NotificationReceivedEventOpts</a></td>
+ <td class="summary"></td>
+ </tr>
</table>
<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
@@ -676,12 +728,16 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
+ <h3>See also:</h3>
+ <ul>
+ <a href="index.html#WebEvents">WebEvents</a>
+ </ul>
<h3>Usage:</h3>
<ul>
<pre class="example">web.event.<span class="function-name">add_listener</span>(<span class="string">'UrlChanged'</span>, {
callback = <span class="keyword">function</span>(opts)
- <span class="global">print</span>(opts.url, opts.tab, opts.win)
+ <span class="global">print</span>(opts.url, opts.view, opts.win)
<span class="keyword">end</span>,
})</pre>
</ul>
@@ -1040,6 +1096,93 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
<dt>
+ <a name = "print"></a>
+ <strong>print (value)</strong>
+ </dt>
+ <dd>
+ Print a lua object to inspect
+
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">value</span>
+ <span class="types"><span class="type">any</span></span>
+
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "web.json.encode"></a>
+ <strong>web.json.encode (obj, opts)</strong>
+ </dt>
+ <dd>
+ Encodes lua object as json into a string
+
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">obj</span>
+ <span class="types"><span class="type">any</span></span>
+ Value to encode into json string
+ </li>
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">indent</span>
+ boolean? Whether to enable indentation (default: false)
+ </li>
+ </li></ul>
+ </ul>
+
+ <h3>Returns:</h3>
+ <ol>
+
+ <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+
+ </ol>
+
+
+
+
+</dd>
+ <dt>
+ <a name = "web.json.decode"></a>
+ <strong>web.json.decode (json_str, opts)</strong>
+ </dt>
+ <dd>
+ Decodes a string into a lua object
+
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">json_str</span>
+ <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Json string to decode
+ </li>
+ <li><span class="parameter">opts</span> Options
+ <ul>
+ <li><span class="parameter">null</span>
+ any What to use as null value (default: nil)
+ </li>
+ </li></ul>
+ </ul>
+
+ <h3>Returns:</h3>
+ <ol>
+
+ <span class="types"><span class="type">any</span></span>
+
+ </ol>
+
+
+
+
+</dd>
+ <dt>
<a name = "web.utils.string_trim"></a>
<strong>web.utils.string_trim (str)</strong>
</dt>
@@ -1211,6 +1354,12 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
<li><span class="parameter">new_view_url</span>
string URL used when view url is not specified (default: 'https://duckduckgo.com')
</li>
+ <li><span class="parameter">null_assets_dir</span>
+ string (readonly) Directory where null assets are installed
+ </li>
+ <li><span class="parameter">null_docs_dir</span>
+ string (readonly) Directory where null docs are installed
+ </li>
<li><span class="parameter">permissions_persistance</span>
'always'|'session'|'never' How to persist choices for permissions (default: 'always')
</li>
@@ -1224,6 +1373,296 @@ web.view.<span class="function-name">reload</span>({ view = <span class="number"
</dd>
+ <dt>
+ <a name = "WebEvents"></a>
+ <strong>WebEvents</strong>
+ </dt>
+ <dd>
+ Events that can be listened to with web.events.add_listener
+
+
+
+
+
+ <h3>See also:</h3>
+ <ul>
+ <li><a href="index.html#KeyPressedEventOpts">KeyPressedEventOpts</a></li>
+ <li><a href="index.html#ModeChangedEventOpts">ModeChangedEventOpts</a></li>
+ <li><a href="index.html#NotificationReceivedEventOpts">NotificationReceivedEventOpts</a></li>
+ <li><a href="index.html#PermissionRequestedEventOpts">PermissionRequestedEventOpts</a></li>
+ <li><a href="index.html#UrlChangedEventOpts">UrlChangedEventOpts</a></li>
+ <li><a href="index.html#ViewClosedEventOpts">ViewClosedEventOpts</a></li>
+ <li><a href="index.html#ViewCreatedEventOpts">ViewCreatedEventOpts</a></li>
+ <li><a href="index.html#ViewSelectedEventOpts">ViewSelectedEventOpts</a></li>
+ <li><a href="index.html#WinCreatedEventOpts">WinCreatedEventOpts</a></li>
+ <li><a href="index.html#web.event.add_listener">web.event.add_listener</a></li>
+ </ul>
+
+ <h3>Usage:</h3>
+ <ul>
+ <pre class="example">web.events.<span class="function-name">add_listener</span>(<span class="string">'UrlChanged'</span>, {
+ callback = <span class="keyword">function</span>(opts)
+ <span class="global">print</span>(opts.url)
+ },
+<span class="keyword">end</span>)</pre>
+ </ul>
+
+</dd>
+ <dt>
+ <a name = "WinCreatedEventOpts"></a>
+ <strong>WinCreatedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'WinCreated'
+ </li>
+ <li><span class="parameter">view</span>
+ integer
+ </li>
+ <li><span class="parameter">win</span>
+ integer
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "ViewCreatedEventOpts"></a>
+ <strong>ViewCreatedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'ViewCreated'
+ </li>
+ <li><span class="parameter">view</span>
+ integer
+ </li>
+ <li><span class="parameter">win</span>
+ integer
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "ViewSelectedEventOpts"></a>
+ <strong>ViewSelectedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'ViewSelected'
+ </li>
+ <li><span class="parameter">view</span>
+ integer
+ </li>
+ <li><span class="parameter">win</span>
+ integer
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "ViewClosedEventOpts"></a>
+ <strong>ViewClosedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'ViewClosed'
+ </li>
+ <li><span class="parameter">view</span>
+ integer
+ </li>
+ <li><span class="parameter">win</span>
+ integer
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "UrlChangedEventOpts"></a>
+ <strong>UrlChangedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'UrlChanged'
+ </li>
+ <li><span class="parameter">view_id</span>
+ integer
+ </li>
+ <li><span class="parameter">win_id</span>
+ integer
+ </li>
+ <li><span class="parameter">url</span>
+ string
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "PermissionRequestedEventOpts"></a>
+ <strong>PermissionRequestedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'PermissionRequested'
+ </li>
+ <li><span class="parameter">premission_type</span>
+ 'MediaAudioCapture' | 'MediaVideoCapture' | 'MediaAudioVideoCapture' | 'DesktopVideoCapture' | 'DesktopAudioVideoCapture' | 'MouseLock' | 'Notifications' | 'Geolocation' | 'ClipboardReadWrite' | 'LocalFontsAccess' | 'Unsupported'
+ </li>
+ <li><span class="parameter">webview_id</span>
+ integer
+ </li>
+ <li><span class="parameter">win_id</span>
+ integer
+ </li>
+ <li><span class="parameter">accept</span>
+ fun():nil
+ </li>
+ <li><span class="parameter">reject</span>
+ fun():nil
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "ModeChangedEventOpts"></a>
+ <strong>ModeChangedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'ModeChanged'
+ </li>
+ <li><span class="parameter">mode</span>
+ string
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "KeyPressedEventOpts"></a>
+ <strong>KeyPressedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'KeyPressed'
+ </li>
+ <li><span class="parameter">key</span>
+ string
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "NotificationReceivedEventOpts"></a>
+ <strong>NotificationReceivedEventOpts</strong>
+ </dt>
+ <dd>
+
+
+
+ <h3>Fields:</h3>
+ <ul>
+ <li><span class="parameter">type</span>
+ 'NotificationReceived'
+ </li>
+ <li><span class="parameter">title</span>
+ string
+ </li>
+ <li><span class="parameter">message</span>
+ string
+ </li>
+ <li><span class="parameter">tag</span>
+ string
+ </li>
+ <li><span class="parameter">origin</span>
+ string
+ </li>
+ <li><span class="parameter">click</span>
+ fun():nil
+ </li>
+ <li><span class="parameter">show</span>
+ fun():nil
+ </li>
+ <li><span class="parameter">close</span>
+ fun():nil
+ </li>
+ </ul>
+
+
+
+
+
+</dd>
</dl>
<h2 class="section-header "><a name="Fields"></a>Fields</h2>
diff --git a/docs/api/symbols.json b/docs/api/symbols.json
index aa356c5..8b5319e 100644
--- a/docs/api/symbols.json
+++ b/docs/api/symbols.json
@@ -1 +1 @@
-["_G.__internals","schedule","web.keymap.set","web.keymap.set_mode","web.keymap.get_mode","web.view.close","web.view.create","web.view.current","web.view.list","web.view.select","web.view.set_url","web.view.set_html","web.view.run_js","web.view.reload","web.view.expose","web.view.open_devtools","web.view.current_index","web.event.add_listener","set","get","WebOpts","opts","web.history.back","web.history.forward","web.search.set_text","web.search.reset","web.search.get_text","web.search.next","web.search.previous","web.view.scroll","web.view.scroll_to_top","web.view.scroll_to_bottom","web.help.get_items","web.help.show","uv","inspect","web.utils.string_trim","web.utils.table_merge","web.utils.table_keys","web.utils.equals","web.utils.table_contains"] \ No newline at end of file
+["_G.__internals","schedule","web.keymap.set","web.keymap.set_mode","web.keymap.get_mode","web.view.close","web.view.create","web.view.current","web.view.list","web.view.select","web.view.set_url","web.view.set_html","web.view.run_js","web.view.reload","web.view.expose","web.view.open_devtools","web.view.current_index","web.event.add_listener","set","get","WebOpts","opts","web.history.back","web.history.forward","web.search.set_text","web.search.reset","web.search.get_text","web.search.next","web.search.previous","web.view.scroll","web.view.scroll_to_top","web.view.scroll_to_bottom","web.help.get_items","web.help.show","WebEvents","WinCreatedEventOpts","ViewCreatedEventOpts","ViewSelectedEventOpts","ViewClosedEventOpts","UrlChangedEventOpts","PermissionRequestedEventOpts","ModeChangedEventOpts","KeyPressedEventOpts","NotificationReceivedEventOpts","uv","inspect","print","web.json.encode","web.json.decode","web.utils.string_trim","web.utils.table_merge","web.utils.table_keys","web.utils.equals","web.utils.table_contains"] \ No newline at end of file
diff --git a/init.lua b/init.lua
index d2a8e23..622bd79 100644
--- a/init.lua
+++ b/init.lua
@@ -165,9 +165,15 @@ end)
local hints = require 'null-browser.extras.hints'
hints.init()
-web.keymap.set('n', 'f', function() hints.start('a[href], button', hints.action.open_in_view) end)
-web.keymap.set('n', '<s-f>', function() hints.start('a[href], button', hints.action.open_in_new_view) end)
-web.keymap.set('n', 'yl', function() hints.start('a[href]', hints.action.copy_link) end)
+web.keymap.set('n', 'f', function()
+ hints.start('a[href], button, [role="button"]', hints.action.open_in_view)
+end)
+web.keymap.set('n', '<s-f>', function()
+ hints.start('a[href], button, [role="button"]', hints.action.open_in_new_view)
+end)
+web.keymap.set('n', 'yl', function()
+ hints.start('a[href]', hints.action.copy_link)
+end)
web.keymap.set('n', 'gi', function()
local input_selectors = {
'input:not([type="hidden"])',
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua
index ee861f0..0625869 100644
--- a/lua/null-browser/api.lua
+++ b/lua/null-browser/api.lua
@@ -187,10 +187,12 @@ end
--- @param opts table Options
--- @param opts.callback fun(opts:any):nil Callback called when that event occurs
---
+--- @see WebEvents
+---
--- @usage
--- web.event.add_listener('UrlChanged', {
--- callback = function(opts)
---- print(opts.url, opts.tab, opts.win)
+--- print(opts.url, opts.view, opts.win)
--- end,
--- })
function web.event.add_listener(events, opts)
diff --git a/lua/null-browser/events.lua b/lua/null-browser/events.lua
new file mode 100644
index 0000000..1e55999
--- /dev/null
+++ b/lua/null-browser/events.lua
@@ -0,0 +1,79 @@
+---@diagnostic disable: doc-field-no-class, undefined-doc-param, undefined-doc-name
+--- Lua api for configuring null browser.
+--- @module web
+
+-- TODO: Make all opts naming consistent
+
+--- Events that can be listened to with web.events.add_listener
+---
+--- @table WebEvents
+--- @see KeyPressedEventOpts
+--- @see ModeChangedEventOpts
+--- @see NotificationReceivedEventOpts
+--- @see PermissionRequestedEventOpts
+--- @see UrlChangedEventOpts
+--- @see ViewClosedEventOpts
+--- @see ViewCreatedEventOpts
+--- @see ViewSelectedEventOpts
+--- @see WinCreatedEventOpts
+--- @see web.event.add_listener
+---
+--- @usage
+--- web.events.add_listener('UrlChanged', {
+--- callback = function(opts)
+--- print(opts.url)
+--- },
+--- end)
+
+--- @table WinCreatedEventOpts
+--- @field type 'WinCreated'
+--- @field view integer
+--- @field win integer
+
+--- @table ViewCreatedEventOpts
+--- @field type 'ViewCreated'
+--- @field view integer
+--- @field win integer
+
+--- @table ViewSelectedEventOpts
+--- @field type 'ViewSelected'
+--- @field view integer
+--- @field win integer
+
+--- @table ViewClosedEventOpts
+--- @field type 'ViewClosed'
+--- @field view integer
+--- @field win integer
+
+--- @table UrlChangedEventOpts
+--- @field type 'UrlChanged'
+--- @field view_id integer
+--- @field win_id integer
+--- @field url string
+
+--- @table PermissionRequestedEventOpts
+--- @field type 'PermissionRequested'
+--- @field premission_type 'MediaAudioCapture' | 'MediaVideoCapture' | 'MediaAudioVideoCapture' | 'DesktopVideoCapture' | 'DesktopAudioVideoCapture' | 'MouseLock' | 'Notifications' | 'Geolocation' | 'ClipboardReadWrite' | 'LocalFontsAccess' | 'Unsupported'
+--- @field webview_id integer
+--- @field win_id integer
+--- @field accept fun():nil
+--- @field reject fun():nil
+
+--- @table ModeChangedEventOpts
+--- @field type 'ModeChanged'
+--- @field mode string
+
+--- @table KeyPressedEventOpts
+--- @field type 'KeyPressed'
+--- @field key string
+
+--- @table NotificationReceivedEventOpts
+--- @field type 'NotificationReceived'
+--- @field title string
+--- @field message string
+--- @field tag string
+--- @field origin string
+--- @field click fun():nil
+--- @field show fun():nil
+--- @field close fun():nil
+
diff --git a/lua/null-browser/utils.lua b/lua/null-browser/utils.lua
index 2c9aba4..907f20c 100644
--- a/lua/null-browser/utils.lua
+++ b/lua/null-browser/utils.lua
@@ -17,10 +17,38 @@ local inspector = require 'null-browser.inspect'
--- @return string
web.inspect = inspector.inspect
+--- Print a lua object to inspect
+--- @param value any
+function web.print(value)
+ print(web.inspect(value))
+end
+
web.json = web.json or {}
local json = require 'null-browser.json'
-web.json.encode = json.encode
-web.json.decode = json.decode
+
+--- Encodes lua object as json into a string
+--- @param obj any Value to encode into json string
+--- @param opts table? Options
+--- @param opts.indent boolean? Whether to enable indentation (default: false)
+--- @return string
+web.json.encode = function(obj, opts)
+ opts = opts or {}
+ local state = { indent = opts.indent or false }
+ return tostring(json.encode(obj, state))
+end
+
+--- Decodes a string into a lua object
+--- @diagnostic disable-next-line: undefined-doc-param
+--- @param json_str string Json string to decode
+--- @param opts table Options
+--- @param opts.null any What to use as null value (default: nil)
+--- @return any
+web.json.decode = function(json_str, opts)
+ opts = opts or {}
+ local value, _, err = json.decode(json_str, nil, opts.null)
+ if err then error(err) end
+ return value
+end
--- Trim whitespace from start and end of a string
--- @param str string
diff --git a/src/App.cpp b/src/App.cpp
index 7ce8932..63ecfa6 100644
--- a/src/App.cpp
+++ b/src/App.cpp
@@ -16,7 +16,7 @@ void App::run() {
auto config_dir = get_cli_config_dir();
if (!config_dir.isEmpty())
- configuration.set_config_dir(config_dir);
+ configuration.set_user_config_dir(config_dir);
if (instance_manager.is_server()) {
init_server();
diff --git a/src/Configuration.hpp b/src/Configuration.hpp
index 1a0f0dc..587205b 100644
--- a/src/Configuration.hpp
+++ b/src/Configuration.hpp
@@ -65,11 +65,11 @@ public:
return QWebEngineProfile::PersistentPermissionsPolicy::StoreOnDisk;
}
- DEFINE_GETTER(get_config_dir, config_dir)
- DEFINE_SETTER(set_config_dir, config_dir)
+ DEFINE_GETTER(get_user_config_dir, config_dir)
+ DEFINE_SETTER(set_user_config_dir, config_dir)
- QString get_config_lua_init_file() const { return config_dir.filePath("init.lua"); }
- QString get_config_lua_dir() const { return config_dir.filePath("lua"); }
+ QString get_user_config_lua_init_file() const { return config_dir.filePath("init.lua"); }
+ QString get_user_config_lua_dir() const { return config_dir.filePath("lua"); }
private:
void on_update(const QString &name, const QVariant &value) {
diff --git a/src/InstanceManager.hpp b/src/InstanceManager.hpp
index 47d4932..5d70347 100644
--- a/src/InstanceManager.hpp
+++ b/src/InstanceManager.hpp
@@ -41,6 +41,7 @@ private:
bool is_server_mode = false;
// TODO: On windows, \\.\pipe\null-browser
+ // TODO: Use path unique to app data
const char *socket_path = "/tmp/null-browser-socket.sock";
};
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp
index e57b923..9bf86d6 100644
--- a/src/widgets/BrowserApp.cpp
+++ b/src/widgets/BrowserApp.cpp
@@ -24,13 +24,13 @@ BrowserApp::BrowserApp(Configuration &configuration) : configuration(configurati
// Global event filter
qApp->installEventFilter(this);
- qDebug() << "Config dir:" << configuration.get_config_dir().path();
+ qDebug() << "Config dir:" << configuration.get_user_config_dir().path();
// Load lua directory into package path
- lua.append_package_path(configuration.get_config_lua_dir());
+ lua.append_package_path(configuration.get_user_config_lua_dir());
// Load init.lua
- auto lua_init_file = configuration.get_config_lua_init_file();
+ auto lua_init_file = configuration.get_user_config_lua_init_file();
if (QFile::exists(lua_init_file)) {
lua.load_file_sync(lua_init_file);
} else {