Skip to content

Commit

Permalink
initialize profile (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Nov 9, 2024
1 parent 1b3fafa commit b097a16
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ option(HALLELUJAH "" OFF)
option(RIME "" OFF)

set(ADDONS)
set(DEFAULT_INPUT_METHODS)

if (HALLELUJAH)
add_definitions(-DHALLELUJAH)
add_subdirectory(engines/fcitx5-hallelujah)
list(APPEND ADDONS hallelujah)
list(APPEND DEFAULT_INPUT_METHODS hallelujah)
endif()
if (RIME)
# RIME_DATA_DIR is not actually used but must exist.
Expand All @@ -88,8 +90,18 @@ if (RIME)
add_definitions(-DRIME)
add_subdirectory(engines/fcitx5-rime)
list(APPEND ADDONS rime)
list(APPEND DEFAULT_INPUT_METHODS rime)
endif()

add_custom_command(
OUTPUT "${PROJECT_BINARY_DIR}/profile"
COMMAND python scripts/configure.py ${DEFAULT_INPUT_METHODS}
DEPENDS "${PROJECT_SOURCE_DIR}/default"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Generating profile"
)
add_custom_target(gen_profile DEPENDS "${PROJECT_BINARY_DIR}/profile")

if (HALLELUJAH)
list(APPEND ADDONS spell)
endif()
Expand Down
10 changes: 10 additions & 0 deletions common/util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public let logger = Logger(subsystem: "org.fcitx.Fcitx5", category: "FcitxLog")
public let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
public let appGroup = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: "org.fcitx.Fcitx5")!
public let appGroupConfig = appGroup.appendingPathComponent("config")
public let appGroupTmp = appGroup.appendingPathComponent("tmp")
public let appGroupData = appGroup.appendingPathComponent("data")

Expand Down Expand Up @@ -90,3 +91,12 @@ public func removeFile(_ file: URL) -> Bool {
return false
}
}

// Call on both app and keyboard to initialize input method list after install.
public func initProfile() {
mkdirP(appGroupConfig.path)
let profileURL = appGroupConfig.appendingPathComponent("profile")
if !profileURL.exists() {
try? FileManager.default.copyItem(at: Bundle.main.bundleURL.appendingPathComponent("profile"), to: profileURL)
}
}
11 changes: 11 additions & 0 deletions keyboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ target_link_libraries(keyboard PRIVATE
SwiftUtil
${ADDONS}
)

add_dependencies(keyboard gen_profile)
add_custom_command(
TARGET keyboard
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy
${PROJECT_BINARY_DIR}/profile
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/profile
\"
)
1 change: 1 addition & 0 deletions keyboard/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
mainStackView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0),
])

initProfile()
startFcitx(Bundle.main.bundlePath, appGroup.path)

// Perform custom UI setup here
Expand Down
25 changes: 25 additions & 0 deletions scripts/configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys

PROFILE_HEADER = '''
[Groups/0]
Name=Default
Default Layout=us
DefaultIM={0}
'''

PROFILE_ITEM = '''
[Groups/0/Items/{0}]
Name={1}
Layout=
'''

PROFILE_TAIL = '''
[GroupOrder]
0=Default
'''

with open('build/profile', 'w') as f:
f.write(PROFILE_HEADER.format(sys.argv[1]))
for i in range(len(sys.argv) - 1):
f.write(PROFILE_ITEM.format(i, sys.argv[i + 1]))
f.write(PROFILE_TAIL)
1 change: 1 addition & 0 deletions src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
initProfile()
startFcitx(Bundle.main.bundlePath, appGroup.path)
return true
}
Expand Down
21 changes: 10 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ target_link_libraries(${BUNDLE_NAME} PRIVATE
${ADDONS}
)

add_custom_command(
TARGET ${BUNDLE_NAME}
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/assets/${ICON_FILE}
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app
\"
)

add_dependencies(${BUNDLE_NAME} keyboard)

set_target_properties(${BUNDLE_NAME} PROPERTIES
Expand All @@ -59,7 +49,8 @@ add_custom_command(
\"
)

# Embed keyboard.appex in app and copy share directory.
# Embed keyboard.appex in app.
# Copy share directory, icon and profile.
add_custom_command(
TARGET ${BUNDLE_NAME}
POST_BUILD COMMAND /bin/sh -c
Expand All @@ -71,5 +62,13 @@ add_custom_command(
${CMAKE_COMMAND} -E copy_directory
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/share
\;
${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/assets/${ICON_FILE}
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app
\;
${CMAKE_COMMAND} -E copy
${PROJECT_BINARY_DIR}/profile
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/profile
\"
)

0 comments on commit b097a16

Please sign in to comment.