@@ -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
0 commit comments