Files
qingjian/apps/macos/pkg/scripts/postinstall
T
kyuiazusa 1eced5e34e fix(installer): 注册前清掉用户的输入源缓存,修开着的沙盒应用切到青简闪退 (#421)
沙盒应用各自缓存一份输入源表,装青简前生成的那份查不到青简,切过来时系统框架对 NULL 调 CFRelease 崩溃;postinstall 注册前删掉这些缓存,系统重建后就认得青简。

Closes #407
Closes #346
2026-10-12 12:51:15 +08:00

26 lines
1.4 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