mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-19 11:43:24 +01:00
Fixes strong reference cycles in Source view controllers
* SourcesViewController * SourcesDetailContentViewController
This commit is contained in:
@@ -293,12 +293,12 @@ private extension SourceDetailContentViewController
|
|||||||
{
|
{
|
||||||
let dataSource = RSTDynamicCollectionViewDataSource<NSManagedObject>()
|
let dataSource = RSTDynamicCollectionViewDataSource<NSManagedObject>()
|
||||||
dataSource.numberOfSectionsHandler = { 1 }
|
dataSource.numberOfSectionsHandler = { 1 }
|
||||||
dataSource.numberOfItemsHandler = { _ in self.source.localizedDescription == nil ? 0 : 1 }
|
dataSource.numberOfItemsHandler = { [source] _ in source.localizedDescription == nil ? 0 : 1 }
|
||||||
dataSource.cellIdentifierHandler = { _ in "AboutCell" }
|
dataSource.cellIdentifierHandler = { _ in "AboutCell" }
|
||||||
dataSource.cellConfigurationHandler = { [weak self] (cell, _, indexPath) in
|
dataSource.cellConfigurationHandler = { [source] (cell, _, indexPath) in
|
||||||
let cell = cell as! TextViewCollectionViewCell
|
let cell = cell as! TextViewCollectionViewCell
|
||||||
cell.contentView.layoutMargins = .zero // Fixes incorrect margins if not initially on screen.
|
cell.contentView.layoutMargins = .zero // Fixes incorrect margins if not initially on screen.
|
||||||
cell.textView.text = self?.source.localizedDescription
|
cell.textView.text = source.localizedDescription
|
||||||
cell.textView.isCollapsed = false
|
cell.textView.isCollapsed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ private extension SourcesViewController
|
|||||||
{
|
{
|
||||||
let dataSource = RSTCompositeCollectionViewDataSource<Source>(dataSources: [self.addedSourcesDataSource, self.trustedSourcesDataSource])
|
let dataSource = RSTCompositeCollectionViewDataSource<Source>(dataSources: [self.addedSourcesDataSource, self.trustedSourcesDataSource])
|
||||||
dataSource.proxy = self
|
dataSource.proxy = self
|
||||||
dataSource.cellConfigurationHandler = { (cell, source, indexPath) in
|
dataSource.cellConfigurationHandler = { [weak self] (cell, source, indexPath) in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
let tintColor = UIColor.altPrimary
|
let tintColor = UIColor.altPrimary
|
||||||
|
|
||||||
let cell = cell as! AppBannerCollectionViewCell
|
let cell = cell as! AppBannerCollectionViewCell
|
||||||
@@ -337,9 +339,9 @@ private extension SourcesViewController
|
|||||||
|
|
||||||
func fetchTrustedSources()
|
func fetchTrustedSources()
|
||||||
{
|
{
|
||||||
func finish(_ result: Result<[Source], Error>)
|
// Closure instead of local function so we can capture `self` weakly.
|
||||||
{
|
let finish: (Result<[Source], Error>) -> Void = { [weak self] result in
|
||||||
self.fetchTrustedSourcesResult = result.map { _ in () }
|
self?.fetchTrustedSourcesResult = result.map { _ in () }
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
do
|
do
|
||||||
@@ -348,19 +350,19 @@ private extension SourcesViewController
|
|||||||
print("Fetched trusted sources:", sources.map { $0.identifier })
|
print("Fetched trusted sources:", sources.map { $0.identifier })
|
||||||
|
|
||||||
let sectionUpdate = RSTCellContentChange(type: .update, sectionIndex: 0)
|
let sectionUpdate = RSTCellContentChange(type: .update, sectionIndex: 0)
|
||||||
self.trustedSourcesDataSource.setItems(sources, with: [sectionUpdate])
|
self?.trustedSourcesDataSource.setItems(sources, with: [sectionUpdate])
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
print("Error fetching trusted sources:", error)
|
print("Error fetching trusted sources:", error)
|
||||||
|
|
||||||
let sectionUpdate = RSTCellContentChange(type: .update, sectionIndex: 0)
|
let sectionUpdate = RSTCellContentChange(type: .update, sectionIndex: 0)
|
||||||
self.trustedSourcesDataSource.setItems([], with: [sectionUpdate])
|
self?.trustedSourcesDataSource.setItems([], with: [sectionUpdate])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fetchTrustedSourcesOperation = AppManager.shared.updateKnownSources { result in
|
self.fetchTrustedSourcesOperation = AppManager.shared.updateKnownSources { [weak self] result in
|
||||||
switch result
|
switch result
|
||||||
{
|
{
|
||||||
case .failure(let error): finish(.failure(error))
|
case .failure(let error): finish(.failure(error))
|
||||||
@@ -370,7 +372,7 @@ private extension SourcesViewController
|
|||||||
|
|
||||||
// This context is never saved, but keeps the managed sources alive.
|
// This context is never saved, but keeps the managed sources alive.
|
||||||
let context = DatabaseManager.shared.persistentContainer.newBackgroundSavingViewContext()
|
let context = DatabaseManager.shared.persistentContainer.newBackgroundSavingViewContext()
|
||||||
self._fetchTrustedSourcesContext = context
|
self?._fetchTrustedSourcesContext = context
|
||||||
|
|
||||||
let dispatchGroup = DispatchGroup()
|
let dispatchGroup = DispatchGroup()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user