Skip to content

Commit

Permalink
Merge pull request #719 from youknowone/update-config
Browse files Browse the repository at this point in the history
 업데이트 설정
  • Loading branch information
youknowone committed Jul 17, 2020
2 parents 7b2a444 + 67487c2 commit 970a96d
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 74 deletions.
12 changes: 10 additions & 2 deletions Gureum.xcodeproj/project.pbxproj
Expand Up @@ -107,6 +107,8 @@
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"; }; };
38C4A39B24C21965001B5208 /* BundleVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C4A39A24C21965001B5208 /* BundleVersion.swift */; };
38C4A39C24C21B0A001B5208 /* BundleVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C4A39A24C21965001B5208 /* BundleVersion.swift */; };
38EE977619FFD65600AD19B8 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38EE977519FFD65600AD19B8 /* Carbon.framework */; };
38F85961215BD27000CD80AE /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F85960215BD27000CD80AE /* main.swift */; };
38F85969215BF4BA00CD80AE /* Preferences.prefPane in Resources */ = {isa = PBXBuildFile; fileRef = 382E68641A1314D900031D1D /* Preferences.prefPane */; };
Expand Down Expand Up @@ -363,6 +365,7 @@
38BFE81F18B4F181004B2B2E /* NSPrefPaneBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPrefPaneBundle.h; sourceTree = "<group>"; };
38C253EA19F4EE320020FE92 /* Gureum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Gureum.entitlements; sourceTree = "<group>"; };
38C2AE4C208795E700FE211A /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
38C4A39A24C21965001B5208 /* BundleVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleVersion.swift; sourceTree = "<group>"; };
38C75C8B1F153A74004BE02A /* RomanComposer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RomanComposer.swift; sourceTree = "<group>"; };
38D3E42A21213E9700751191 /* HangulComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HangulComposer.swift; sourceTree = "<group>"; };
38D6F1CB194003C7003F25EE /* command.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = command.png; path = Icons/command.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -630,6 +633,7 @@
E54B8381214299EB00527218 /* GureumComposer.swift */,
19E257A12327412500952E64 /* KeyCode.swift */,
19A122B32349D18A00525AEC /* SearchPool.swift */,
38C4A39A24C21965001B5208 /* BundleVersion.swift */,
3835B4E21F5DAA7100896BEC /* data */,
);
path = OSXCore;
Expand Down Expand Up @@ -1291,6 +1295,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
38C4A39C24C21B0A001B5208 /* BundleVersion.swift in Sources */,
19A122A523477E1D00525AEC /* GureumPreferencePane.swift in Sources */,
19A1229A23477D2700525AEC /* TISInputSource+.swift in Sources */,
19A122A323477DE900525AEC /* GureumShortcutValidator.swift in Sources */,
Expand Down Expand Up @@ -1328,6 +1333,7 @@
3881869121EB2DC0004B7FDB /* Debug.swift in Sources */,
388186A121EB3055004B7FDB /* GureumComposer.swift in Sources */,
3881868921EB2D8D004B7FDB /* InputReceiver.swift in Sources */,
38C4A39B24C21965001B5208 /* BundleVersion.swift in Sources */,
386BEC5524A388A90066BF95 /* TISInputSource+.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1559,7 +1565,7 @@
CODE_SIGN_ENTITLEMENTS = OSX/Gureum.entitlements;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = "${VERSION}";
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -1575,6 +1581,7 @@
INFOPLIST_FILE = OSXCore/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MARKETING_VERSION = "${VERSION}";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.youknowone.OSXCore;
Expand All @@ -1597,7 +1604,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = "${VERSION}";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 9384JEL3M9;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -1608,6 +1615,7 @@
INFOPLIST_FILE = OSXCore/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MARKETING_VERSION = "${VERSION}";
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.youknowone.OSXCore;
PRODUCT_NAME = GureumCore;
Expand Down
4 changes: 2 additions & 2 deletions GureumTests/GureumTests.swift
Expand Up @@ -69,8 +69,8 @@ class GureumTests: XCTestCase {
return
}
let versionInfo = UpdateManager.VersionInfo(data: versionInfoJSON, experimental: true)
UpdateManager.shared.notifyUpdate(info: versionInfo)
XCTAssertEqual("최신 버전: 1.10.0 현재 버전: \(UpdateManager.bundleVersion ?? "-")\nMojave 대응을 포함한 대형 업데이트", lastNotification.informativeText)
UpdateManager.notifyUpdate(info: versionInfo)
XCTAssertEqual("최신 버전: 1.10.0 현재 버전: \(Bundle.main.version ?? "-")\nMojave 대응을 포함한 대형 업데이트", lastNotification.informativeText)
XCTAssertEqual(["url": "https://github.com/gureum/gureum/releases/tag/1.10.0"], lastNotification.userInfo as! [String: String])
}

Expand Down
2 changes: 1 addition & 1 deletion OSX/GureumMenu.swift
Expand Up @@ -31,7 +31,7 @@ extension InputController {

@IBAction func checkRecentVersion(_: Any) {
answers.logMenu(name: "check-version")
guard let info = UpdateManager.shared.fetchOfficialVersionInfo() else {
guard let info = UpdateManager.shared.fetchStableVersionInfo() else {
let alert = NSAlert()
alert.messageText = "구름 입력기 업데이트 확인"
alert.addButton(withTitle: "확인")
Expand Down
20 changes: 10 additions & 10 deletions OSX/UpdateManager.swift
Expand Up @@ -8,13 +8,13 @@

import Foundation
import FoundationExtension
import GureumCore

class UpdateManager {
static let shared = UpdateManager()
static let bundleVersion: String? = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String

class VersionInfo {
let current: String? = UpdateManager.bundleVersion
let current: String? = Bundle.main.version
let data: [String: String]
let experimental: Bool
init(data: [String: String], experimental: Bool) {
Expand Down Expand Up @@ -54,7 +54,7 @@ class UpdateManager {
return VersionInfo(data: info, experimental: experimental)
}

func fetchOfficialVersionInfo() -> VersionInfo? {
func fetchStableVersionInfo() -> VersionInfo? {
let url = URL(string: "http://gureum.io/version.json")!
return fetchVersionInfo(from: url, experimental: false)
}
Expand All @@ -65,17 +65,17 @@ class UpdateManager {
}

func fetchAutoUpdateVersionInfo() -> VersionInfo? {
guard let current = UpdateManager.bundleVersion else {
switch Configuration.shared.updateMode {
case .None:
return nil
}
if current.contains("-experimental") || current.contains("-rc") {
case .Stable:
return fetchStableVersionInfo()
case .Experimental:
return fetchExperimentalVersionInfo()
} else {
return fetchOfficialVersionInfo()
}
}

func notifyUpdate(info: VersionInfo) {
class func notifyUpdate(info: VersionInfo) {
let notification = NSUserNotification()
var title = "구름 입력기 업데이트 알림"
if info.experimental {
Expand Down Expand Up @@ -105,6 +105,6 @@ class UpdateManager {
guard info.url != nil else {
return
}
notifyUpdate(info: info)
UpdateManager.notifyUpdate(info: info)
}
}
22 changes: 22 additions & 0 deletions OSXCore/BundleVersion.swift
@@ -0,0 +1,22 @@
//
// BundleVersion.swift
// OSXCore
//
// Created by Jeong YunWon on 2020/07/18.
// Copyright © 2020 youknowone.org. All rights reserved.
//

import Foundation

public extension Bundle {
var version: String? {
Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
}

var isExperimental: Bool {
guard let current = version else {
return false
}
return current.contains("-experimental") || current.contains("-rc")
}
}
78 changes: 64 additions & 14 deletions OSXCore/Configuration.swift
Expand Up @@ -41,6 +41,11 @@ enum ConfigurationName {
public static let hangulForceStrictCombinationRule = "HangulForceStrictCombinationRule"
/// 우측 커맨드 키로 언어 전환
public static let switchLanguageForRightGui = "SwitchLanguageForRightGui"

/// 업데이트 알림 받기
public static let updateNotification = "UpdateNotification"
/// 실험버전 업데이트 알림 받기
public static let updateNotificationExperimental = "UpdateNotificationExperimental"
}

// MARK: - Configuration 클래스
Expand All @@ -54,6 +59,12 @@ public class Configuration: UserDefaults {

public typealias Shortcut = (KeyCode, NSEvent.ModifierFlags)

public enum UpdateMode {
case None
case Stable
case Experimental
}

class func convertShortcutToConfiguration(_ shortcut: Shortcut?) -> [String: Any] {
guard let shortcut = shortcut else {
return [:]
Expand Down Expand Up @@ -87,6 +98,9 @@ public class Configuration: UserDefaults {
ConfigurationName.hangulNonChoseongCombination: false,
ConfigurationName.hangulForceStrictCombinationRule: false,
ConfigurationName.switchLanguageForRightGui: false,

ConfigurationName.updateNotification: true,
ConfigurationName.updateNotificationExperimental: false,
])
}

Expand All @@ -98,10 +112,12 @@ public class Configuration: UserDefaults {
return persistentDomain(forName: Configuration.sharedSuiteName) ?? [:]
}

// TODO: code generation

/// 마지막 한글 입력 모드.
public var lastHangulInputMode: String {
get {
return string(forKey: ConfigurationName.lastHangulInputMode)!
string(forKey: ConfigurationName.lastHangulInputMode)!
}
set {
set(newValue, forKey: ConfigurationName.lastHangulInputMode)
Expand All @@ -111,7 +127,7 @@ public class Configuration: UserDefaults {
/// 마지막 로마자 입력 모드.
public var lastRomanInputMode: String {
get {
return string(forKey: ConfigurationName.lastRomanInputMode)!
string(forKey: ConfigurationName.lastRomanInputMode)!
}
set {
set(newValue, forKey: ConfigurationName.lastRomanInputMode)
Expand All @@ -121,7 +137,7 @@ public class Configuration: UserDefaults {
/// 옵션 키 동작.
public var optionKeyBehavior: Int {
get {
return integer(forKey: ConfigurationName.optionKeyBehavior)
integer(forKey: ConfigurationName.optionKeyBehavior)
}
set {
set(newValue, forKey: ConfigurationName.optionKeyBehavior)
Expand All @@ -131,7 +147,7 @@ public class Configuration: UserDefaults {
/// 기본 키보드 레이아웃.
public var overridingKeyboardName: String {
get {
return string(forKey: ConfigurationName.overridingKeyboardName)!
string(forKey: ConfigurationName.overridingKeyboardName)!
}
set {
set(newValue, forKey: ConfigurationName.overridingKeyboardName)
Expand All @@ -141,7 +157,7 @@ public class Configuration: UserDefaults {
/// 입력기 바꾸기 단축키.
public var inputModeExchangeKey: Shortcut? {
get {
return shortcut(forKey: ConfigurationName.inputModeExchangeKey)
shortcut(forKey: ConfigurationName.inputModeExchangeKey)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeExchangeKey)
Expand All @@ -151,7 +167,7 @@ public class Configuration: UserDefaults {
/// 한자 및 이모지 검색 단축키.
public var inputModeSearchKey: Shortcut? {
get {
return shortcut(forKey: ConfigurationName.inputModeSearchKey)
shortcut(forKey: ConfigurationName.inputModeSearchKey)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeSearchKey)
Expand All @@ -161,7 +177,7 @@ public class Configuration: UserDefaults {
/// 로마자로 바꾸기 단축키.
public var inputModeEnglishKey: Shortcut? {
get {
return shortcut(forKey: ConfigurationName.inputModeEnglishKey)
shortcut(forKey: ConfigurationName.inputModeEnglishKey)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeEnglishKey)
Expand All @@ -171,7 +187,7 @@ public class Configuration: UserDefaults {
/// 한글로 바꾸기 단축키.
public var inputModeKoreanKey: Shortcut? {
get {
return shortcut(forKey: ConfigurationName.inputModeKoreanKey)
shortcut(forKey: ConfigurationName.inputModeKoreanKey)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeKoreanKey)
Expand All @@ -181,7 +197,7 @@ public class Configuration: UserDefaults {
/// Esc 키로 로마자 자판으로 전환 (vi 모드).
public var romanModeByEscapeKey: Bool {
get {
return bool(forKey: ConfigurationName.romanModeByEscapeKey)
bool(forKey: ConfigurationName.romanModeByEscapeKey)
}
set {
set(newValue, forKey: ConfigurationName.romanModeByEscapeKey)
Expand All @@ -191,7 +207,7 @@ public class Configuration: UserDefaults {
/// 한글 입력기일 때 역따옴표(`)로 원화 기호(₩) 입력.
public var hangulWonCurrencySymbolForBackQuote: Bool {
get {
return bool(forKey: ConfigurationName.hangulWonCurrencySymbolForBackQuote)
bool(forKey: ConfigurationName.hangulWonCurrencySymbolForBackQuote)
}
set {
set(newValue, forKey: ConfigurationName.hangulWonCurrencySymbolForBackQuote)
Expand All @@ -201,7 +217,7 @@ public class Configuration: UserDefaults {
/// 완성되지 않은 낱자 자동 교정 (모아치기).
public var hangulAutoReorder: Bool {
get {
return bool(forKey: ConfigurationName.hangulAutoReorder)
bool(forKey: ConfigurationName.hangulAutoReorder)
}
set {
set(newValue, forKey: ConfigurationName.hangulAutoReorder)
Expand All @@ -211,7 +227,7 @@ public class Configuration: UserDefaults {
/// 두벌식 초성 조합 중에도 종성 결합 허용 (MS윈도 호환).
public var hangulNonChoseongCombination: Bool {
get {
return bool(forKey: ConfigurationName.hangulNonChoseongCombination)
bool(forKey: ConfigurationName.hangulNonChoseongCombination)
}
set {
set(newValue, forKey: ConfigurationName.hangulNonChoseongCombination)
Expand All @@ -221,7 +237,7 @@ public class Configuration: UserDefaults {
/// 세벌식 정석 강요.
public var hangulForceStrictCombinationRule: Bool {
get {
return bool(forKey: ConfigurationName.hangulForceStrictCombinationRule)
bool(forKey: ConfigurationName.hangulForceStrictCombinationRule)
}
set {
set(newValue, forKey: ConfigurationName.hangulForceStrictCombinationRule)
Expand All @@ -231,12 +247,46 @@ public class Configuration: UserDefaults {
/// 우측 커맨드 키로 언어 전환
public var switchLanguageForRightGui: Bool {
get {
return bool(forKey: ConfigurationName.switchLanguageForRightGui)
bool(forKey: ConfigurationName.switchLanguageForRightGui)
}
set {
set(newValue, forKey: ConfigurationName.switchLanguageForRightGui)
}
}

public var updateNotification: Bool {
get {
bool(forKey: ConfigurationName.updateNotification)
}
set {
set(newValue, forKey: ConfigurationName.updateNotification)
}
}

public var updateNotificationExperimental: Bool {
get {
if Bundle.main.isExperimental {
return true
} else {
return bool(forKey: ConfigurationName.updateNotificationExperimental)
}
}
set {
assert(!Bundle.main.isExperimental)
set(newValue, forKey: ConfigurationName.updateNotificationExperimental)
}
}

public var updateMode: UpdateMode {
switch (updateNotification, updateNotificationExperimental) {
case (false, _):
return .None
case (true, false):
return .Stable
case (true, true):
return .Experimental
}
}
}

private extension Configuration {
Expand Down
2 changes: 1 addition & 1 deletion OSXCore/Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down

0 comments on commit 970a96d

Please sign in to comment.