Skip to content

Commit

Permalink
Merge pull request #563 from youknowone/exp-noti
Browse files Browse the repository at this point in the history
실험버전 업데이트 알림에 별도로 표시
  • Loading branch information
youknowone committed Jun 13, 2019
2 parents dc00480 + c8f2239 commit 958c94f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion GureumTests/GureumTests.swift
Expand Up @@ -68,7 +68,7 @@ class GureumTests: XCTestCase {
XCTFail()
return
}
let versionInfo = UpdateManager.VersionInfo(data: versionInfoJSON)
let versionInfo = UpdateManager.VersionInfo(data: versionInfoJSON, experimental: true)
UpdateManager.shared.notifyUpdate(info: versionInfo)
XCTAssertEqual("최신 버전: 1.10.0 현재 버전: \(UpdateManager.bundleVersion ?? "-")\nMojave 대응을 포함한 대형 업데이트", lastNotification.informativeText)
XCTAssertEqual(["url": "https://github.com/gureum/gureum/releases/tag/1.10.0"], lastNotification.userInfo as! [String: String])
Expand Down
1 change: 1 addition & 0 deletions GureumTests/MockInputClient.m
Expand Up @@ -27,6 +27,7 @@ - (NSString *)selectedString {
}

- (void)insertText:(id)string replacementRange:(NSRange)replacementRange {
// NSAssert(replacementRange.location == NSNotFound || replacementRange.length != 0, @"-");
[super insertText:string replacementRange:replacementRange];
}

Expand Down
18 changes: 12 additions & 6 deletions OSX/UpdateManager.swift
Expand Up @@ -16,8 +16,10 @@ class UpdateManager {
class VersionInfo {
let current: String? = UpdateManager.bundleVersion
let data: [String: String]
init(data: [String: String]) {
let experimental: Bool
init(data: [String: String], experimental: Bool) {
self.data = data
self.experimental = experimental
}

var recent: String? {
Expand All @@ -36,7 +38,7 @@ class UpdateManager {
}
}

func fetchVersionInfo(from url: URL) -> VersionInfo? {
func fetchVersionInfo(from url: URL, experimental: Bool) -> VersionInfo? {
var request = URLRequest(url: url)
request.timeoutInterval = 0.5
request.cachePolicy = .reloadIgnoringCacheData
Expand All @@ -49,17 +51,17 @@ class UpdateManager {
guard let info = try? JSONSerialization.jsonObject(with: data as Data) as? [String: String] else {
return nil
}
return VersionInfo(data: info)
return VersionInfo(data: info, experimental: experimental)
}

func fetchOfficialVersionInfo() -> VersionInfo? {
let url = URL(string: "http://gureum.io/version.json")!
return fetchVersionInfo(from: url)
return fetchVersionInfo(from: url, experimental: false)
}

func fetchExperimentalVersionInfo() -> VersionInfo? {
let url = URL(string: "http://gureum.io/version-experimental.json")!
return fetchVersionInfo(from: url)
return fetchVersionInfo(from: url, experimental: true)
}

func fetchAutoUpdateVersionInfo() -> VersionInfo? {
Expand All @@ -75,7 +77,11 @@ class UpdateManager {

func notifyUpdate(info: VersionInfo) {
let notification = NSUserNotification()
notification.title = "구름 입력기 업데이트 알림"
var title = "구름 입력기 업데이트 알림"
if info.experimental {
title += " (실험 버전)"
}
notification.title = title
notification.hasActionButton = true
notification.hasReplyButton = false
notification.actionButtonTitle = "업데이트"
Expand Down

0 comments on commit 958c94f

Please sign in to comment.