Skip to content

Commit

Permalink
Use unix socket instead of tcp/ip (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Qijia Liu <[email protected]>
  • Loading branch information
omegacoleman and eagleoflqj authored Jul 11, 2024
1 parent 4cef877 commit 48f1dbe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ add_subdirectory(assets)
option(BUILD_PREVIEW "" OFF)
add_subdirectory(fcitx5-webview)

set(ADDON_TYPE "StaticLibrary")
add_subdirectory(fcitx5-beast/src)
target_include_directories(beast PRIVATE "${PREBUILT_INSTALL_PATH}/include")

Expand Down
38 changes: 35 additions & 3 deletions assets/fcitx5-curl
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
#!/bin/zsh
set -eu

DEBUG="${DEBUG:-}"

if [[ $# -eq 0 || $# -eq 1 && ( "$1" == "-h" || "$1" == "--help" ) ]]; then
echo "Usage: fcitx5-curl path [curl options]"
echo "Example: fcitx5-curl /config/addon/rime/deploy -X POST -d '{}'"
exit 0
fi

source ~/.config/fcitx5/conf/beast.conf || Port=32489
url="http://127.0.0.1:$Port$1"
CONFIG_FILE_PATH="$HOME/.config/fcitx5/conf/beast.conf"

if [ -f "$CONFIG_FILE_PATH" ]
then
COMMUNICATION=$(sed -n 's/Communication=\([^ ]*.*\)/\1/p' "$CONFIG_FILE_PATH")
UDS_PATH=$(sed -n 's/Path=\([^ ]*.*\)/\1/p' "$CONFIG_FILE_PATH")
TCP_PORT=$(sed -n 's/Port=\([^ ]*.*\)/\1/p' "$CONFIG_FILE_PATH")
fi

COMMUNICATION="${COMMUNICATION:-UDS}"
UDS_PATH="${UDS_PATH:-/tmp/fcitx5.sock}"
TCP_PORT="${TCP_PORT:-32489}"

CURL_FLAGS=()

if [[ "$COMMUNICATION" == 'TCP' ]]; then
FCITX_BEAST_URL="http://127.0.0.1:$TCP_PORT$1"
else
CURL_FLAGS+=('--unix-socket' "$UDS_PATH")
FCITX_BEAST_URL="http://fcitx$1"
fi

shift
curl "$url" "$@"
CURL_FLAGS+=($@)

if [[ -n "$DEBUG" ]]; then
echo "COMMUNICATION=$COMMUNICATION"
echo "UDS_PATH=$UDS_PATH"
echo "TCP_PORT=$TCP_PORT"
echo "FCITX_BEAST_URL=$FCITX_BEAST_URL"
echo "CURL_FLAGS=$CURL_FLAGS"
fi

curl $CURL_FLAGS "$FCITX_BEAST_URL"
2 changes: 1 addition & 1 deletion fcitx5-beast

0 comments on commit 48f1dbe

Please sign in to comment.