Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TISGetInputSourcePropertyで取得したInputSource配列をretainする #283

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions macSKK/InputSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ struct InputSource: Hashable, Identifiable {
guard let id = getStringProperty(inputSource, key: kTISPropertyInputSourceID) else { return nil }
guard let localizedName = getStringProperty(inputSource, key: kTISPropertyLocalizedName) else { return nil }
// 第一言語が英語じゃないものは弾く。
// APIドキュメントには特に書いてないけどCFGetRetainCountで見るとretainedな値を返してそうなのでtakeRetainedValueで変換
if let languagesPointer = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceLanguages),
let languages = Unmanaged<CFArray>.fromOpaque(languagesPointer).takeRetainedValue() as? Array<String> {
let languages = Unmanaged<CFArray>.fromOpaque(languagesPointer).takeUnretainedValue() as? Array<String> {
if let first = languages.first {
if first != "en" {
return nil
Expand All @@ -41,6 +40,6 @@ struct InputSource: Hashable, Identifiable {

static func getStringProperty(_ tisInputSource: TISInputSource, key: NSString) -> String? {
guard let pointer = TISGetInputSourceProperty(tisInputSource, key) else { return nil }
return unsafeBitCast(pointer, to: CFString.self) as String
return String(Unmanaged<CFString>.fromOpaque(pointer).takeUnretainedValue())
}
}
Loading