Files
qingjian/apps/macos/pkg/scripts/postinstall
T
jacklaoz 584c8297fa fix(macos): 装完菜单里没有青简时先提示注销重登 (#626)
macOS 27 上 --register 与系统设置里的添加都只让输入模式半启用,注销重登后才正常,安装器、postinstall 与文档改成先提示重登。
bundle.sh 用完即删 target 与 pkg 暂存目录里的 .app 并从 LaunchServices 注销,免得同一 bundle id 登记两份。
2026-10-15 11:00:47 +08:00

26 lines
1.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 装完之后:杀掉旧进程,再以当前登录用户的身份把输入源注册并启用。
# 安装器以 root 运行,而输入源是每个用户自己的设置,所以要切到用户的会话里去调 `qingjian-macos --register`。
set -u
APP="/Library/Input Methods/Qingjian.app"
BIN="$APP/Contents/MacOS/qingjian-macos"
pkill -x qingjian-macos 2>/dev/null || true
user="$(stat -f%Su /dev/console 2>/dev/null || true)"
if [ -n "$user" ] && [ "$user" != "root" ]; then
uid="$(id -u "$user")"
# 删掉这个用户的输入源缓存(共享的一份 + 每个沙盒应用各一份):注册时系统广播后,开着的应用作废内存里的表、
# 找不到磁盘缓存就从输入法目录重建,认得青简;不删的话它们重新载入装之前那份,Control+Space 切到青简时崩溃(#346)
cache="$(sudo -u "$user" getconf DARWIN_USER_CACHE_DIR 2>/dev/null)"
[ -n "$cache" ] && rm -f "$cache"com.apple.IntlDataCache.le* "$cache"*/com.apple.IntlDataCache.le* 2>/dev/null
if launchctl asuser "$uid" sudo -u "$user" "$BIN" --register; then
echo "青简:已为 $user 注册并启用输入源;输入法菜单里没有「青简」就注销后重新登录(系统在登录时才刷新输入法列表)"
else
echo "青简:自动注册输入源失败,请注销后重新登录;仍没有再到「系统设置 → 键盘 → 输入法 → 编辑… → +」的「简体中文」下添加「青简」"
fi
else
echo "青简:没找到登录用户,跳过自动注册"
fi
exit 0