File tree 4 files changed +14
-12
lines changed 4 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 18
18
19
19
import InfomaniakDI
20
20
import MailCore
21
- import Nuke
22
21
import OSLog
23
22
import SwiftUI
24
23
import UIKit
@@ -36,7 +35,6 @@ struct MailApp: App {
36
35
Logging . resetAppForUITestsIfNeeded ( )
37
36
Logger . general. info ( " Application starting in foreground ? \( UIApplication . shared. applicationState != . background) " )
38
37
refreshAppBackgroundTask. register ( )
39
- ImagePipeline . shared = ImagePipeline ( configuration: . withDataCache)
40
38
}
41
39
42
40
var body : some Scene {
Original file line number Diff line number Diff line change @@ -20,15 +20,17 @@ import Foundation
20
20
import Nuke
21
21
22
22
struct AttachmentCacheHelper {
23
+ let pipeline : ImagePipeline
24
+
23
25
func getCache( resource: String ? ) -> Data ? {
24
26
guard let resource, let resourceURL = URL ( string: resource) else { return nil }
25
27
let request = ImageRequest ( url: resourceURL)
26
- return ImagePipeline . shared . cache. cachedData ( for: request)
28
+ return pipeline . cache. cachedData ( for: request)
27
29
}
28
30
29
31
func storeCache( resource: String ? , data: Data ) {
30
32
guard let resource, let resourceURL = URL ( string: resource) else { return }
31
33
let request = ImageRequest ( url: resourceURL)
32
- ImagePipeline . shared . cache. storeCachedData ( data, for: request)
34
+ pipeline . cache. storeCachedData ( data, for: request)
33
35
}
34
36
}
Original file line number Diff line number Diff line change @@ -49,13 +49,12 @@ public extension MailboxManager {
49
49
throw CancellationError ( )
50
50
}
51
51
52
- let attachmentCacheHelper = AttachmentCacheHelper ( )
53
- let data : Data
54
- if let cachedData = attachmentCacheHelper. getCache ( resource: attachment. resource) {
55
- data = cachedData
52
+ @InjectService var cacheHelper : AttachmentCacheHelper
53
+ if let cachedData = cacheHelper. getCache ( resource: attachment. resource) {
54
+ return cachedData
56
55
} else {
57
- data = try await apiFetcher. attachment ( attachment: attachment, progressObserver: progressObserver)
58
- attachmentCacheHelper . storeCache ( resource: attachment. resource, data: data)
56
+ let data = try await apiFetcher. attachment ( attachment: attachment, progressObserver: progressObserver)
57
+ cacheHelper . storeCache ( resource: attachment. resource, data: data)
59
58
60
59
let safeAttachment = ThreadSafeReference ( to: attachment)
61
60
try ? writeTransaction { writableRealm in
@@ -65,9 +64,8 @@ public extension MailboxManager {
65
64
66
65
liveAttachment. saved = true
67
66
}
67
+ return data
68
68
}
69
-
70
- return data
71
69
}
72
70
73
71
func saveAttachmentLocally( attachment: Attachment , progressObserver: ( ( Double ) -> Void ) ? ) async {
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import InfomaniakDI
24
24
import InfomaniakLogin
25
25
import InfomaniakNotifications
26
26
import MyKSuite
27
+ import Nuke
27
28
import OSLog
28
29
29
30
private let realmRootPath = " mailboxes "
@@ -126,6 +127,9 @@ open class TargetAssembly {
126
127
} ,
127
128
Factory ( type: MyKSuiteStore . self) { _, _ in
128
129
MyKSuiteStore ( )
130
+ } ,
131
+ Factory ( type: AttachmentCacheHelper . self) { _, _ in
132
+ AttachmentCacheHelper ( pipeline: ImagePipeline ( configuration: . withDataCache) )
129
133
}
130
134
]
131
135
}
You can’t perform that action at this time.
0 commit comments