Skip to content

Commit 02c7ccf

Browse files
committed
fix: install converter launch agent from pkg
1 parent 11fa5cb commit 02c7ccf

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

pkg-scripts/postinstall

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
service_name="dev.ensan.inputmethod.azooKeyMac.ConverterServer"
5+
app_path="/Library/Input Methods/azooKeyMac.app"
6+
server_path="${app_path}/Contents/MacOS/ConverterServer"
7+
agent_dir="/Library/LaunchAgents"
8+
agent_path="${agent_dir}/${service_name}.plist"
9+
10+
if [ ! -x "${server_path}" ]; then
11+
echo "ConverterServer not found: ${server_path}" >&2
12+
exit 1
13+
fi
14+
15+
mkdir -p "${agent_dir}"
16+
cat > "${agent_path}" <<PLIST
17+
<?xml version="1.0" encoding="UTF-8"?>
18+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
19+
<plist version="1.0">
20+
<dict>
21+
<key>Label</key>
22+
<string>${service_name}</string>
23+
<key>ProgramArguments</key>
24+
<array>
25+
<string>${server_path}</string>
26+
</array>
27+
<key>MachServices</key>
28+
<dict>
29+
<key>${service_name}</key>
30+
<true/>
31+
</dict>
32+
<key>KeepAlive</key>
33+
<true/>
34+
<key>RunAtLoad</key>
35+
<true/>
36+
<key>StandardOutPath</key>
37+
<string>/tmp/${service_name}.stdout.log</string>
38+
<key>StandardErrorPath</key>
39+
<string>/tmp/${service_name}.stderr.log</string>
40+
</dict>
41+
</plist>
42+
PLIST
43+
44+
chmod 644 "${agent_path}"
45+
chown root:wheel "${agent_path}"
46+
47+
console_user="$(stat -f %Su /dev/console)"
48+
if [ -z "${console_user}" ] || [ "${console_user}" = "root" ] || [ "${console_user}" = "_mbsetupuser" ]; then
49+
echo "No active console user; ${service_name} will start on next login."
50+
exit 0
51+
fi
52+
53+
console_uid="$(id -u "${console_user}")"
54+
gui_domain="gui/${console_uid}"
55+
legacy_agent_path="$(eval echo "~${console_user}")/Library/LaunchAgents/${service_name}.plist"
56+
57+
launchctl bootout "${gui_domain}/${service_name}" >/dev/null 2>&1 || true
58+
if [ -f "${legacy_agent_path}" ]; then
59+
launchctl bootout "${gui_domain}" "${legacy_agent_path}" >/dev/null 2>&1 || true
60+
rm -f "${legacy_agent_path}"
61+
fi
62+
launchctl bootstrap "${gui_domain}" "${agent_path}"
63+
launchctl kickstart -k "${gui_domain}/${service_name}"
64+
launchctl print "${gui_domain}/${service_name}" >/dev/null
65+
66+
echo "Installed and started ${service_name}"

pkgbuild.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CONFIGURATION="Release"
66
ARCHIVE_PATH="./build/archive.xcarchive"
77
EXPORT_PATH="./build/export"
88
EXPORT_OPTIONS_PLIST="./exportOptions.plist"
9+
PKG_SCRIPTS_PATH="./pkg-scripts"
910

1011
# 1. Clean Build
1112
rm -rf ./build
@@ -58,6 +59,7 @@ rm ${EXPORT_PATH}/ExportOptions.plist
5859

5960
# Create a temporary package
6061
pkgbuild --root ${EXPORT_PATH} \
62+
--scripts ${PKG_SCRIPTS_PATH} \
6163
--component-plist pkg.plist --identifier dev.ensan.inputmethod.azooKeyMac \
6264
--version 0 \
6365
--install-location /Library/Input\ Methods \

0 commit comments

Comments
 (0)