Skip to content
Permalink
Browse files

SystemConfigurationWatcher

  • Loading branch information...
youknowone committed Jun 8, 2019
1 parent 4c7ec18 commit 8dd50bd8b5ecbbacc04c1c31649c2a13788a63d7
@@ -90,6 +90,7 @@
388E2A611469249700ADBDA5 /* Hangul.strings in Resources */ = {isa = PBXBuildFile; fileRef = 388E2A601469249700ADBDA5 /* Hangul.strings */; };
38946A6B19F4F3FD00920E09 /* InputMethodKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38946A6A19F4F3FD00920E09 /* InputMethodKit.framework */; };
38B9547B229ED9BC00A9D6E1 /* AnswersHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38B9547A229ED9BC00A9D6E1 /* AnswersHelper.swift */; };
38B9551022A833E900A9D6E1 /* SystemConfigurationWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38B9550D22A833E900A9D6E1 /* SystemConfigurationWatcher.swift */; };
38BFE80218B45419004B2B2E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 38BFE80018B45419004B2B2E /* InfoPlist.strings */; };
38BFE80418B45419004B2B2E /* GureumObjCTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 38BFE80318B45419004B2B2E /* GureumObjCTests.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
38EE977619FFD65600AD19B8 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38EE977519FFD65600AD19B8 /* Carbon.framework */; };
@@ -333,6 +334,7 @@
38946A6A19F4F3FD00920E09 /* InputMethodKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = InputMethodKit.framework; path = System/Library/Frameworks/InputMethodKit.framework; sourceTree = SDKROOT; };
38AC8D49217C4EDA00E4B332 /* InputReceiver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputReceiver.swift; sourceTree = "<group>"; };
38B9547A229ED9BC00A9D6E1 /* AnswersHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnswersHelper.swift; sourceTree = "<group>"; };
38B9550D22A833E900A9D6E1 /* SystemConfigurationWatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemConfigurationWatcher.swift; sourceTree = "<group>"; };
38BFE7FA18B45419004B2B2E /* OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
38BFE7FF18B45419004B2B2E /* GureumTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GureumTests-Info.plist"; sourceTree = "<group>"; };
38BFE80118B45419004B2B2E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@@ -592,6 +594,7 @@
381DB19A21678B74005A37B9 /* Debug.swift */,
E5D234EE2141260E00595FA0 /* GureumApplicationDelegate.swift */,
38C2AE4C208795E700FE211A /* Configuration.swift */,
38B9550D22A833E900A9D6E1 /* SystemConfigurationWatcher.swift */,
38AC8D49217C4EDA00E4B332 /* InputReceiver.swift */,
E5BB72CC214A788100E35558 /* InputController.swift */,
871B807B2153DDFA0013EE69 /* InputMethodServer.swift */,
@@ -1094,12 +1097,14 @@
"${PODS_ROOT}/Target Support Files/Pods-OSX/Pods-OSX-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/FoundationExtension/FoundationExtension.framework",
"${BUILT_PRODUCTS_DIR}/SwiftCarbon/SwiftCarbon.framework",
"${BUILT_PRODUCTS_DIR}/SwiftCoreServices/SwiftCoreServices.framework",
"${BUILT_PRODUCTS_DIR}/SwiftIOKit/SwiftIOKit.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FoundationExtension.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftCarbon.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftCoreServices.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftIOKit.framework",
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1193,13 +1198,15 @@
"${BUILT_PRODUCTS_DIR}/FoundationExtension/FoundationExtension.framework",
"${BUILT_PRODUCTS_DIR}/MASShortcut/MASShortcut.framework",
"${BUILT_PRODUCTS_DIR}/SwiftCarbon/SwiftCarbon.framework",
"${BUILT_PRODUCTS_DIR}/SwiftCoreServices/SwiftCoreServices.framework",
"${BUILT_PRODUCTS_DIR}/SwiftIOKit/SwiftIOKit.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FoundationExtension.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MASShortcut.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftCarbon.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftCoreServices.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftIOKit.framework",
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1256,6 +1263,7 @@
3881869021EB2D8D004B7FDB /* BaseComposer.swift in Sources */,
388186B121EB453E004B7FDB /* InputController.swift in Sources */,
3881869F21EB3055004B7FDB /* HanjaComposer.swift in Sources */,
38B9551022A833E900A9D6E1 /* SystemConfigurationWatcher.swift in Sources */,
3881869D21EB3055004B7FDB /* EmoticonComposer.swift in Sources */,
3881869121EB2DC0004B7FDB /* Debug.swift in Sources */,
388186A121EB3055004B7FDB /* GureumComposer.swift in Sources */,
@@ -71,5 +71,6 @@ class GureumAppDelegate: NSObject, NSApplicationDelegate, GureumApplicationDeleg
Timer.scheduledTimer(withTimeInterval: 3600, repeats: true) { _ in
answers.logUptime()
}
watcher.reloadConfiguration()
}
}
@@ -33,7 +33,7 @@ public class Configuration: UserDefaults {
public static let sharedSuiteName = "org.youknowone.Gureum"
public static var shared = Configuration()

var enableCapslockToToggleInputMode: Bool = true
var enableCapslockToToggleInputMode: Bool = false

typealias Shortcut = (UInt, NSEvent.ModifierFlags)

@@ -70,12 +70,6 @@ public class Configuration: UserDefaults {
ConfigurationName.hangulNonChoseongCombination.rawValue: false,
ConfigurationName.hangulForceStrictCombinationRule.rawValue: false,
])

// 시스템 설정 읽어와서 반영한다. 여기도 observer 설정 가능한지 확인 필요
let libraryUrl = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.libraryDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0])
let globalPreferences = NSDictionary(contentsOf: URL(fileURLWithPath: "Preferences/.GlobalPreferences.plist", relativeTo: libraryUrl))!
let state: Int = (globalPreferences["TISRomanSwitchState"] as? NSNumber)?.intValue ?? 1
enableCapslockToToggleInputMode = state > 0
}

convenience init() {
@@ -0,0 +1,41 @@
//
// SystemConfigurationWatcher.swift
// OSXCore
//
// Created by Jeong YunWon on 06/06/2019.
// Copyright © 2019 youknowone.org. All rights reserved.
//
import SwiftCoreServices

typealias FSEventStream = SFSEventStream

public class SystemConfigurationWatcher {
var configuration: Configuration

static let globalPreferencesPath: String = {
let libraryUrl = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.libraryDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0])
let fileUrl = URL(fileURLWithPath: "Preferences/.GlobalPreferences.plist", relativeTo: libraryUrl)
return fileUrl.path
}()

init(configuration: inout Configuration) {
self.configuration = configuration

let stream = FSEventStream.create(paths: [SystemConfigurationWatcher.globalPreferencesPath], eventId: FSEventStream.EventIdSinceNow, latancy: 5.0, flags: FSEventStream.CreateFlag.fileEvents) {
[weak self] _, _ in
NSLog("Reloading system configuration by watcher")
self?.reloadConfiguration()
}!
stream.schedule(runLoop: .current, mode: .default)
stream.start()
}

public func reloadConfiguration() {
let globalPreferences = NSDictionary(contentsOf: URL(fileURLWithPath: SystemConfigurationWatcher.globalPreferencesPath))!
let state: Int = (globalPreferences["TISRomanSwitchState"] as? NSNumber)?.intValue ?? 1
configuration.enableCapslockToToggleInputMode = state > 0
}
}

public let watcher = SystemConfigurationWatcher(configuration: &Configuration.shared)
@@ -8,6 +8,7 @@ target 'OSXCore' do
pod 'FoundationExtension', '~> 2.0.0'
pod 'SwiftIOKit'
pod 'SwiftCarbon'
pod 'SwiftCoreServices'
end
target 'OSX' do
platform :osx, "10.13"
@@ -19,6 +19,7 @@ PODS:
- SwiftCarbon/HIToolbox (0.1.0)
- SwiftCarbon/SwiftCarbon (0.1.0):
- SwiftCarbon/HIToolbox
- SwiftCoreServices (0.1.1)
- SwiftIOKit (0.1.0)

DEPENDENCIES:
@@ -28,6 +29,7 @@ DEPENDENCIES:
- FoundationExtension (~> 2.0.0)
- MASShortcut
- SwiftCarbon
- SwiftCoreServices
- SwiftIOKit

SPEC REPOS:
@@ -38,6 +40,7 @@ SPEC REPOS:
- FoundationExtension
- MASShortcut
- SwiftCarbon
- SwiftCoreServices
- SwiftIOKit

SPEC CHECKSUMS:
@@ -47,8 +50,9 @@ SPEC CHECKSUMS:
FoundationExtension: 0c3615327b9d7844ca5f65bfb4dd7563baab197a
MASShortcut: 9c215e8a8a78f3d01ce56da48e2730ab66b538fa
SwiftCarbon: c48bbbff6c451022e89c46b85d0e9b44c64ef61b
SwiftCoreServices: e4aebffc7143ff3e06920ecb89654f7c81f9768a
SwiftIOKit: 9dce3dec67e00dc74b95fde86f257aca78239853

PODFILE CHECKSUM: 09ed8ee4b5f8a5b490e474da126dc82f42e846c5
PODFILE CHECKSUM: f267d6545e41b1c9581e708a70198800d75eae36

COCOAPODS: 1.7.1

0 comments on commit 8dd50bd

Please sign in to comment.
You can’t perform that action at this time.