Skip to content

Commit 7bbd7af

Browse files
committed
자동 업데이트 확인
1 parent 6f3c7ae commit 7bbd7af

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

SokIM/AppDelegate.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2727
func applicationDidFinishLaunching(_ aNotification: Notification) {
2828
debug()
2929

30+
startCheckingUpdate()
3031
startMonitorsInitially()
3132

3233
// 사용자가 입력기를 변경하는 시점에 초기화
@@ -93,6 +94,47 @@ class AppDelegate: NSObject, NSApplicationDelegate {
9394
)
9495
}
9596

97+
private func startCheckingUpdate() {
98+
let block: (Timer) -> Void = { [self] _ in
99+
debug()
100+
101+
Task {
102+
let config = URLSessionConfiguration.ephemeral
103+
config.timeoutIntervalForResource = 15
104+
let url = URL(string: "https://api.github.com/repos/kiding/SokIM/releases/latest")!
105+
guard let data = try? await URLSession(configuration: config).data(from: url).0 else {
106+
warning("요청 실패: \(url)")
107+
return
108+
}
109+
110+
guard let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
111+
let name = json["name"] as? String else {
112+
warning("릴리스 이름 파싱 실패")
113+
return
114+
}
115+
116+
guard let latest = name.wholeMatch(of: /v[\d.]+ \((\d+)\)/)?.1 else {
117+
warning("알 수 없는 릴리스 이름: \(name)")
118+
return
119+
}
120+
121+
guard let current = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else {
122+
warning("CFBundleVersion 없음")
123+
return
124+
}
125+
126+
debug("current: \(current), latest: \(latest)")
127+
if current != latest {
128+
await MainActor.run {
129+
statusBar.setStatus("📥")
130+
statusBar.setNotice("📥 새로운 업데이트가 있습니다.")
131+
}
132+
}
133+
}
134+
}
135+
block(Timer.scheduledTimer(withTimeInterval: 86400 * 2, repeats: true, block: block))
136+
}
137+
96138
private func startMonitorsInitially() {
97139
debug()
98140

SokIM/SokIM.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<dict>
55
<key>com.apple.security.app-sandbox</key>
66
<true/>
7+
<key>com.apple.security.network.client</key>
8+
<true/>
79
<key>com.apple.security.temporary-exception.sbpl</key>
810
<array>
911
<string>(allow iokit-open)</string>

SokIM/StatusBar.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class StatusBar {
2121
/** 시스템 메시지 */
2222

2323
private let errorItem = NSMenuItem()
24+
private let noticeItem = NSMenuItem()
2425

2526
/** 한/A 전환키 */
2627

@@ -51,6 +52,11 @@ class StatusBar {
5152
errorItem.title = ""
5253
errorItem.isHidden = true
5354
menu.addItem(errorItem)
55+
56+
noticeItem.title = ""
57+
noticeItem.isHidden = true
58+
menu.addItem(noticeItem)
59+
5460
/** 업데이트 확인 */
5561

5662
let updateItem = NSMenuItem()
@@ -167,6 +173,18 @@ class StatusBar {
167173
}
168174
}
169175

176+
func setNotice(_ msg: String?) {
177+
debug()
178+
179+
if let msg {
180+
noticeItem.title = msg
181+
noticeItem.isHidden = false
182+
} else {
183+
noticeItem.isHidden = true
184+
noticeItem.title = ""
185+
}
186+
}
187+
170188
/** 한/A 전환키 */
171189

172190
@objc func toggleCapsLock(sender: NSMenuItem) {

0 commit comments

Comments
 (0)