Permalink
Browse files

refactor input manager

더이상 릴리즈/디버그/테스트의 connection name이 겹치지 않는다
  • Loading branch information...
youknowone committed Jan 2, 2019
1 parent 9551956 commit 1a1f2b124436528cf78416ccbe0eddbd1eb9b637
@@ -10,10 +10,6 @@ import Foundation
import Cocoa

@objc protocol CIMApplicationDelegate: NSObjectProtocol {
/*!
@brief 공용 입력 처리기
*/
@objc var sharedInputManager: CIMInputManager! { get }
/*!
@brief 합성기 생성
@@ -19,9 +19,6 @@
#define DEBUG_INPUTCONTROLLER FALSE
#define DEBUG_LOGGING FALSE

#define CIMSharedInputManager CIMAppDelegate.sharedInputManager
#define CIMAppDelegate ((NSObject<CIMApplicationDelegate> *)[[NSApplication sharedApplication] delegate])

TISInputSource *_USSource() {
static NSString *mainSourceID = @"com.apple.keylayout.US";
static TISInputSource *source = nil;
@@ -32,6 +32,16 @@ let CIMKeyMapUpper = [
]


extension IMKServer {
convenience init?(bundle: Bundle) {
guard let connectionName = bundle.infoDictionary!["InputMethodConnectionName"] as? String else {
return nil
}
self.init(name: connectionName, bundleIdentifier: bundle.bundleIdentifier)
}
}


/*!
@brief 공통적인 OSX의 입력기 구조를 다룬다.
@@ -42,22 +52,31 @@ let CIMKeyMapUpper = [
@coclass IMKServer CIMComposer
*/
@objcMembers public class CIMInputManager: NSObject, CIMInputTextDelegate {
static let shared = CIMInputManager()
//! @brief 현재 입력중인 서버
private var server: IMKServer
//! @property
private var candidates: IMKCandidates
//! @brief 입력기가 inputText: 문맥에 있는지 여부를 저장
public var inputting: Bool = false

override init() {
dlog(true, "** CharmInputManager Init")

let mainBundle = Bundle.main
var connectionName = mainBundle.infoDictionary!["InputMethodConnectionName"] as! String
convenience override init() {
let bundle = Bundle.main
var name = bundle.infoDictionary!["InputMethodConnectionName"] as! String
#if DEBUG
connectionName += "_Debug"
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil {
name += "_Test" + String(describing: Int.random(in: 0..<0x10000))
} else {
name += "_Debug"
}
#endif
self.server = IMKServer(name: connectionName, bundleIdentifier: mainBundle.bundleIdentifier)
self.init(name: name)
}

init(name: String) {
dlog(true, "** CIMInputManager Init")

self.server = IMKServer(name: name, bundleIdentifier: Bundle.main.bundleIdentifier)
self.candidates = IMKCandidates(server: server, panelType: kIMKSingleColumnScrollingCandidatePanel)

super.init()
@@ -131,7 +150,6 @@ let CIMKeyMapUpper = [
dlog(false, "******* FINAL STATE: %d", result.rawValue);
// 합성 후보가 있다면 보여준다
if controller.composer.hasCandidates {
let candidates = self.candidates
candidates.update()
candidates.show(kIMKLocateCandidatesLeftHint)
}
@@ -21,7 +21,7 @@ import Cocoa
dlog(DEBUG_INPUTCONTROLLER, "**** NEW INPUT CONTROLLER INIT **** WITH SERVER: %@ / DELEGATE: %@ / CLIENT: %@", server, (delegate as? NSObject) ?? "(nil)", (client as? NSObject) ?? "(nil)");
let appDelegate = NSApplication.shared.delegate as! CIMApplicationDelegate
self.composer = appDelegate.composer(server: server, client: client)
self.composer.manager = appDelegate.sharedInputManager
self.composer.manager = CIMInputManager.shared
self.inputClient = client
self.controller = controller
}
@@ -35,15 +35,10 @@ class NotificationCenterDelegate: NSObject, NSUserNotificationCenterDelegate {

@objcMembers class GureumAppDelegate: NSObject, NSApplicationDelegate, CIMApplicationDelegate {
@IBOutlet @objc var menu: NSMenu!
@objc public var sharedInputManager: CIMInputManager!

let configuration = GureumConfiguration.shared
let notificationCenterDelegate = NotificationCenterDelegate()

@objc override func awakeFromNib(){
HGKeyboard.initialize()
sharedInputManager = CIMInputManager()
}

func applicationDidFinishLaunching(_ notification: Notification) {
NSUserNotificationCenter.default.delegate = notificationCenterDelegate

@@ -61,6 +56,10 @@ class NotificationCenterDelegate: NSObject, NSUserNotificationCenterDelegate {

let updateManager = UpdateManager.shared
updateManager.notifyUpdateIfNeeded()

HGKeyboard.initialize()
// IMKServer를 띄워야만 입력기가 동작한다
let _ = CIMInputManager.shared
}

@objc func composer(server: IMKServer!, client: Any!) -> CIMComposer {
Submodule libhangul-objc updated 1 files
+2 −1 Hangul.xcodeproj/project.pbxproj

0 comments on commit 1a1f2b1

Please sign in to comment.