File tree Expand file tree Collapse file tree 4 files changed +22
-20
lines changed Expand file tree Collapse file tree 4 files changed +22
-20
lines changed Original file line number Diff line number Diff line change 587
587
GCC_WARN_UNUSED_FUNCTION = YES;
588
588
GCC_WARN_UNUSED_VARIABLE = YES;
589
589
MACOSX_DEPLOYMENT_TARGET = 11.0;
590
- MARKETING_VERSION = 0.4.4 ;
590
+ MARKETING_VERSION = 0.4.5b ;
591
591
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
592
592
MTL_FAST_MATH = YES;
593
593
ONLY_ACTIVE_ARCH = YES;
643
643
GCC_WARN_UNUSED_FUNCTION = YES;
644
644
GCC_WARN_UNUSED_VARIABLE = YES;
645
645
MACOSX_DEPLOYMENT_TARGET = 11.0;
646
- MARKETING_VERSION = 0.4.4 ;
646
+ MARKETING_VERSION = 0.4.5b ;
647
647
MTL_ENABLE_DEBUG_INFO = NO;
648
648
MTL_FAST_MATH = YES;
649
649
SDKROOT = macosx;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class MenuController: NSObject {
23
23
self . menu = createMenu ( )
24
24
self . statusItem!. menu = menu
25
25
26
- imagesUpdated ( )
26
+ showNewestImage ( )
27
27
}
28
28
29
29
private func createStatusBarItem( ) -> NSStatusItem {
@@ -186,16 +186,21 @@ class MenuController: NSObject {
186
186
if description == nil { return " " }
187
187
return description? . split ( separator: " ( " ) . last? . replacingOccurrences ( of: " ) " , with: " " ) ?? " "
188
188
}
189
+
190
+ @MainActor
191
+ private func showNewestImage( ) {
192
+ self . descriptors = Database . instance. allImageDescriptors ( )
193
+ . filter { $0. image. isOnDisk ( ) }
194
+ selectedDescriptorIndex = self . descriptors. firstIndex ( where: { $0 == self . descriptors. last } ) ?? self . descriptors. endIndex
195
+ updateSelectedImage ( newSelectedDescriptorIndex: selectedDescriptorIndex)
196
+ }
189
197
}
190
198
191
199
// MARK: - Delegates
192
200
193
201
extension MenuController : UpdateManagerDelegate {
194
- func imagesUpdated( ) {
195
- self . descriptors = Database . instance. allImageDescriptors ( )
196
- . filter { $0. image. isOnDisk ( ) }
197
- selectedDescriptorIndex = self . descriptors. firstIndex ( where: { $0 == self . descriptors. last } ) ?? self . descriptors. endIndex
198
- updateSelectedImage ( newSelectedDescriptorIndex: selectedDescriptorIndex)
202
+ func downloadedNewImage( ) {
203
+ showNewestImage ( )
199
204
}
200
205
}
201
206
Original file line number Diff line number Diff line change @@ -24,11 +24,12 @@ class Image {
24
24
return try Data ( contentsOf: downloadPath)
25
25
}
26
26
27
- func download ( ) async throws -> Data {
27
+ func downloadAndSaveToDisk ( ) async throws {
28
28
guard let descriptor else {
29
29
throw Error . missingDescriptor
30
30
}
31
- return try await DownloadManager . downloadBinary ( from: descriptor. imageUrl)
31
+ let imageData = try await DownloadManager . downloadBinary ( from: descriptor. imageUrl)
32
+ try FileHandler . saveImageDataToDisk ( imageData: imageData, toUrl: downloadPath)
32
33
}
33
34
34
35
static func isSavedToDisk( descriptor: ImageDescriptor ) -> Bool {
@@ -39,9 +40,4 @@ class Image {
39
40
func isOnDisk( ) -> Bool {
40
41
return FileManager . default. fileExists ( atPath: downloadPath. relativePath)
41
42
}
42
-
43
- func saveToDisk( imageData: Data ) throws {
44
- try FileHandler . saveImageDataToDisk ( imageData: imageData, toUrl: downloadPath)
45
- }
46
-
47
43
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import AppKit
3
3
4
4
protocol UpdateManagerDelegate : AnyObject {
5
5
@MainActor
6
- func imagesUpdated ( )
6
+ func downloadedNewImage ( )
7
7
}
8
8
9
9
class UpdateManager {
@@ -84,17 +84,18 @@ class UpdateManager {
84
84
85
85
for descriptor in newDescriptors {
86
86
do {
87
- let imageData = try await descriptor. image. download ( )
88
- try descriptor. image. saveToDisk ( imageData: imageData)
87
+ try await descriptor. image. downloadAndSaveToDisk ( )
89
88
} catch {
90
- print ( " Failed to download and store image with error: \( error. localizedDescription) " )
89
+ print ( " Failed to download and store image \( descriptor . imageUrl ) with error: \( error. localizedDescription) " )
91
90
}
92
91
}
93
92
94
93
await MainActor . run { [ weak self] in
95
94
guard let self = self else { return }
96
95
self . cleanup ( )
97
- self . delegate? . imagesUpdated ( )
96
+ if newDescriptors. isEmpty == false {
97
+ self . delegate? . downloadedNewImage ( )
98
+ }
98
99
let fetchInterval = UpdateScheduleManager . nextFetchTimeInterval ( )
99
100
print ( " Update complete, next update at \( Date ( ) . addingTimeInterval ( fetchInterval) ) " )
100
101
You can’t perform that action at this time.
0 commit comments