diff options
Diffstat (limited to '.local/share')
-rwxr-xr-x | .local/share/bin/brave | 14 | ||||
-rw-r--r-- | .local/share/mode/reload.d/brave | 81 | ||||
-rw-r--r--[-rwxr-xr-x] | .local/share/mode/reload.d/gtk | 2 |
3 files changed, 82 insertions, 15 deletions
diff --git a/.local/share/bin/brave b/.local/share/bin/brave index c645f54..966b990 100755 --- a/.local/share/bin/brave +++ b/.local/share/bin/brave @@ -1,9 +1,7 @@ #!/bin/sh - -XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" -BRAVE_USER_FLAGS_FILE="$XDG_CONFIG_HOME/brave-flags.conf" -if [[ -f $BRAVE_USER_FLAGS_FILE ]]; then - USER_FLAGS="$(cat $BRAVE_USER_FLAGS_FILE | sed 's/#.*//')" -fi - -/usr/bin/brave $@ $USER_FLAGS +# the remote debugging is so brave can be hooked into by +# ~/.local/share/mode/reload.d/brave. this is probaby bad for security if +# you're not the only user on the system +/usr/bin/brave \ + --remote-debugging-port=9222 + "$@" diff --git a/.local/share/mode/reload.d/brave b/.local/share/mode/reload.d/brave index 62fb08c..beb0a91 100644 --- a/.local/share/mode/reload.d/brave +++ b/.local/share/mode/reload.d/brave @@ -1,11 +1,80 @@ #!/bin/sh +# WIP +browser='brave' +driver='chromedriver' +devtools_addr='localhost:9222' +url_base='http://localhost:9515' +command -v "$browser" > /dev/null && command -v "$driver" > /dev/null +[ $? -ne 0 ] && exit 0 -# - navigate to brave://settings -# - run `chrome.send("setBraveThemeType", [THEME_ENUM])` in js console -# values 1: dark -# 2: light -# - navigate to brave://extensions -# - run `chrome.send("setBraveThemeType", [THEME_ENUM])` in js console +get() { curl -s -o - -X GET "$@" ; } +post() { curl -s -o - -X POST -H 'Content-Type: application/json' -d @- "$@" ; } +delete() { curl -s -X DELETE "$@" > /dev/null ; } + +$driver --silent > /dev/null & +sleep 0.1 # (wait for chromedriver to start server) + +create_session() { + args="$(jq --raw-input --slurp 'split("\n") | map(select(. != ""))' << EOF +new-window +headless=new +EOF + )" + jq -nc \ + --arg name "$browser" \ + --arg debugger "$devtools_addr" \ + --argjson args "$args" \ + '{ + desiredCapabilities: { + "browserName": $name, + "goog:chromeOptions": { + binary: $name, + args: $args, + debuggerAddress: $debugger + }, + } + }' |\ + post "$url_base/session" |\ + jq --raw-output '.sessionId' +} + +navigate() { + jq -nc --arg url "$1" '{"url": $url}' |\ + post "$url_base/url" > /dev/null +} + +script() { + jq -nc --arg script "$1" '{"script": $script, args: []}' |\ + post "$url_base/execute/sync" > /dev/null +} + +create_tab() { + handle="$(jq -nc '{"type": "tab"}' |\ + post "$url_base/window/new" |\ + jq --raw-output '.value.handle')" + jq -nc --arg handle "$handle" '{"name": $handle}' |\ + post "$url_base/window" > /dev/null +} + +# create session +session_id="$(create_session)" +url_base="$url_base/session/$session_id" +create_tab + +# set chrome theme +navigate 'brave://settings' +script "chrome.send(\"setBraveThemeType\", [$([ "$mode" = "light" ] && echo "2" || echo "1")])" + +# todo: reload theme extension +# navigate 'brave://extensions' # - run `chrome.developerPrivate.loadUnpacked()` (TODO: how to handle inputting file path non-interactively) # TODO: how to use chromedriver from script (preferably without nodejs+npm or python3+pip dependencies?) + +# cleanup +delete "$url_base/window" +delete "$url_base" +kill $(jobs -rp) +wait $(jobs -rp) + +# reference: https://w3c.github.io/webdriver/ diff --git a/.local/share/mode/reload.d/gtk b/.local/share/mode/reload.d/gtk index 178f895..a6dbb34 100755..100644 --- a/.local/share/mode/reload.d/gtk +++ b/.local/share/mode/reload.d/gtk @@ -3,7 +3,7 @@ # reloading, and i don't like having it running constantly because it fucks # up fcitx5 and xbindkeys ( - fork xfsettingsd + fork xfsettingsd --replace sleep 1 killall xfsettingsd ) |