Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unix socket instead of tcp/ip #176

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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