跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

native-ime-session.sh

73 行 · 2.9 KB历史下载
1#!/usr/bin/env bash
2set -euo pipefail
3# Existing environments can still open Desktop before their next maintenance
4# update installs IBus. Their established committed-text path remains usable.
5if ! command -v ibus-daemon >/dev/null || ! /usr/bin/python3 -c 'import gi; gi.require_version("IBus", "1.0")' 2>/dev/null; then
6 exec "$@"
7fi
8umask 077
9input_root="$HOME/.cache/cage-input"
10if [ "${CAGE_PHONE_DESKTOP_INPUT:-}" = 1 ]; then input_root=/run/cage-phone-desktop/input; fi
11mkdir -p "$input_root"
12chmod 700 "$input_root"
13export IBUS_ADDRESS="unix:path=$input_root/bus"
14export GTK_IM_MODULE=ibus QT_IM_MODULE=ibus XMODIFIERS=@im=ibus
15bus_pid='' bridge_pid='' app_pid='' session_pid=''
16cleanup() {
17 if [ -n "$app_pid" ]; then
18 kill -TERM "$app_pid" 2>/dev/null || true
19 # Let Node close Chromium and flush its profile before closing the buses.
20 wait "$app_pid" 2>/dev/null || true
21 fi
22 for pid in "$bridge_pid" "$bus_pid" "$session_pid"; do
23 if [ -n "$pid" ]; then kill -TERM "$pid" 2>/dev/null || true; fi
24 done
25 rm -f "$input_root/ready" "$input_root/input.sock"
26}
27trap cleanup EXIT
28trap 'exit 143' TERM
29trap 'exit 130' INT
30# GTK's IBus portal needs a shared session bus. For the browser, allow only
31# that service to activate, preserving its existing absence of a desktop
32# keyring/portal session. Desktop keeps its already-owned keyring bus.
33if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ]; then
34 mkdir -p "$input_root/services"
35 cp /usr/share/dbus-1/services/org.freedesktop.portal.IBus.service "$input_root/services/"
36 cat > "$input_root/session.conf" <<CONFIG
37<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
38<busconfig>
39 <type>session</type><listen>unix:path=$input_root/session-bus</listen><auth>EXTERNAL</auth>
40 <servicedir>$input_root/services</servicedir>
41 <policy context="default"><allow send_destination="*"/><allow receive_sender="*"/><allow own="*"/></policy>
42</busconfig>
43CONFIG
44 rm -f "$input_root/session-bus"
45 dbus-daemon --nofork --config-file="$input_root/session.conf" >/dev/null 2>&1 &
46 session_pid=$!
47 for i in $(seq 1 100); do
48 kill -0 "$session_pid"
49 if [ -S "$input_root/session-bus" ]; then break; fi
50 sleep .05
51 done
52 test -S "$input_root/session-bus"
53 export DBUS_SESSION_BUS_ADDRESS="unix:path=$input_root/session-bus"
54fi
55rm -f "$input_root/ready" "$input_root/bus" "$input_root/input.sock"
56ibus-daemon --single --panel=disable --config=disable --emoji-extension=disable --cache=none --address="$IBUS_ADDRESS" &
57bus_pid=$!
58for i in $(seq 1 100); do
59 kill -0 "$bus_pid"
60 if [ -S "$input_root/bus" ]; then break; fi
61 sleep .05
62done
63/usr/local/bin/cage-native-input &
64bridge_pid=$!
65for i in $(seq 1 100); do
66 kill -0 "$bridge_pid"
67 if [ -f "$input_root/ready" ]; then break; fi
68 sleep .05
69done
70test -f "$input_root/ready"
71"$@" &
72app_pid=$!
73wait "$app_pid"