Skip to content

Commit 4da497d

Browse files
committed
configure app group; change data&config directory
1 parent bf6cb1a commit 4da497d

File tree

10 files changed

+78
-10
lines changed

10 files changed

+78
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
git apply --directory=fcitx5 patches/fcitx5.patch
4747
git apply --directory=engines/fcitx5-hallelujah patches/hallelujah.patch
4848
git apply --directory=engines/fcitx5-rime patches/rime.patch
49-
PKG_CONFIG_PATH=build/sysroot/usr/lib/pkgconfig cmake -B build -G Xcode \
49+
cmake -B build -G Xcode \
5050
-DHALLELUJAH=ON \
5151
-DRIME=ON \
5252
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake \

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ set(KEYBOARD_LANGUAGE "zh-Hans")
2929
set(PREBUILDER_LIB_DIR "${PROJECT_BINARY_DIR}/sysroot/usr/lib")
3030
set(PREBUILDER_SHARE_DIR "${PROJECT_BINARY_DIR}/sysroot/usr/share")
3131

32+
set(ENV{PKG_CONFIG_PATH} "${PREBUILDER_LIB_DIR}/pkgconfig")
33+
3234
# For dependencies not to be find via pkg-config
3335
set(LibIntl_DIR "${PREBUILDER_LIB_DIR}/cmake")
3436
find_package(LibIntl)

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,44 @@
22

33
[Fcitx5](https://github.com/fcitx/fcitx5) input method framework ported to iOS.
44

5+
## Build
6+
This project is NOT managed by Xcode,
7+
but Xcode is needed for iOS SDK.
8+
9+
### Install dependencies
10+
```sh
11+
brew install cmake extra-cmake-modules gettext
12+
IOS_PLATFORM=SIMULATOR ./install-deps.sh
13+
```
14+
15+
### Apply patches
16+
```sh
17+
git apply --directory=fcitx5 patches/fcitx5.patch
18+
git apply --directory=engines/fcitx5-rime patches/rime.patch # if building with Rime
19+
```
20+
21+
### Build with CMake
22+
```sh
23+
cmake -B build -G Xcode \
24+
-DRIME=ON \
25+
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake \
26+
-DIOS_PLATFORM=SIMULATOR
27+
cmake --build build --config Debug
28+
```
29+
30+
### Play with simulator
31+
```sh
32+
xcrun simctl list devices
33+
xcrun simctl boot UUID
34+
xcrun simctl install booted build/src/Debug-iphonesimulator/Fcitx5.app
35+
```
36+
After the first time you execute `xcrun simctl install`,
37+
you need to add Fcitx5 in Settings -> General -> Keyboard -> Keyboards -> Add New Keyboard.
38+
39+
* Simulator is not emulator (virtual machine). Simulator file system is mapped from host filesystem. A process in simulator is a process in macOS.
40+
* App and input method (custom keyboard extension) are different programs. They share a directory (via App Group) in ~/Library/Developer/CoreSimulator/Devices/UUID/data/Containers/Shared/AppGroup.
41+
542
## Credits
43+
* [fcitx5](https://github.com/fcitx/fcitx5): LGPL-2.1-or-later
44+
* [ios-cmake](https://github.com/sheldonth/ios-cmake): MIT
645
* [swift-cmake-examples](https://github.com/apple/swift-cmake-examples): Apache-2.0

assets/app.entitlements

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.application-groups</key>
6+
<array>
7+
<string>org.fcitx.Fcitx5</string>
8+
</array>
9+
</dict>
10+
</plist>

assets/keyboard.entitlements

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.application-groups</key>
6+
<array>
7+
<string>org.fcitx.Fcitx5</string>
8+
</array>
9+
</dict>
10+
</plist>

keyboard/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set_target_properties(keyboard PROPERTIES
55
XCODE_PRODUCT_TYPE "com.apple.product-type.app-extension"
66
)
77

8+
set_xcode_property(keyboard CODE_SIGN_ENTITLEMENTS ${PROJECT_SOURCE_DIR}/assets/keyboard.entitlements)
9+
810
target_include_directories(keyboard PRIVATE
911
"${CMAKE_CURRENT_SOURCE_DIR}"
1012
"${CMAKE_CURRENT_BINARY_DIR}/../fcitx5"

keyboard/KeyboardViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
3535
mainStackView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0),
3636
])
3737

38-
startFcitx(Bundle.main.bundlePath)
38+
startFcitx(
39+
Bundle.main.bundlePath,
40+
FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "org.fcitx.Fcitx5")!
41+
.path)
3942

4043
// Perform custom UI setup here
4144
self.nextKeyboardButton = UIButton(type: .system)

keyboard/fcitx.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,27 @@ void setupLog() {
5555
fcitx::Log::setLogRule("*=5,notimedate");
5656
}
5757

58-
void setupEnv(const char *bundlePath) {
58+
void setupEnv(const char *bundlePath, const char *appGroupPath) {
5959
fs::path bundle = bundlePath;
60-
fs::path home = getenv("HOME");
60+
fs::path group = appGroupPath;
6161
std::string xdg_data_dirs = bundle / "share";
62-
std::string xdg_data_home = home / "Documents";
63-
std::string fcitx_config_home = home / "Library/config";
62+
std::string xdg_data_home = group / "data";
63+
std::string fcitx_config_home = group / "config";
6464
setenv("XDG_DATA_DIRS", xdg_data_dirs.c_str(), 1);
6565
setenv("XDG_DATA_HOME", xdg_data_home.c_str(), 1);
6666
// By default FCITX_DATA_HOME is XDG_DATA_HOME/fcitx5. Flatten it like f5a.
6767
setenv("FCITX_DATA_HOME", xdg_data_home.c_str(), 1);
6868
// By default FCITX_CONFIG_HOME is XDG_CONFIG_HOME/fcitx5. Move it from
69-
// ~/.config/fcitx5 to ~/Library/config.
69+
// ~/.config/fcitx5 to appGroupPath/config.
7070
setenv("FCITX_CONFIG_HOME", fcitx_config_home.c_str(), 1);
7171
}
7272

73-
void startFcitx(const char *bundlePath) {
73+
void startFcitx(const char *bundlePath, const char *appGroupPath) {
7474
if (instance) {
7575
return;
7676
}
7777
setupLog();
78-
setupEnv(bundlePath);
78+
setupEnv(bundlePath, appGroupPath);
7979

8080
instance = std::make_unique<fcitx::Instance>(0, nullptr);
8181
instance->setInputMethodMode(fcitx::InputMethodMode::OnScreenKeyboard);

keyboard/fcitx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <objc/objc.h>
44

5-
void startFcitx(const char *bundlePath);
5+
void startFcitx(const char *bundlePath, const char *appGroupPath);
66
void focusIn(id client);
77
void focusOut();
88
bool processKey(const char *key);

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ set_target_properties(${BUNDLE_NAME} PROPERTIES
2121
XCODE_EMBED_APP_EXTENSIONS keyboard
2222
)
2323

24+
set_xcode_property(${BUNDLE_NAME} CODE_SIGN_ENTITLEMENTS ${PROJECT_SOURCE_DIR}/assets/app.entitlements)
25+
2426
add_custom_command(
2527
TARGET ${BUNDLE_NAME}
2628
POST_BUILD COMMAND /bin/sh -c

0 commit comments

Comments
 (0)