[WIP] Disposable debugging

This commit is contained in:
Ali 2023-09-16 11:45:30 +02:00
parent 4bf474bbe5
commit 4330dc14d2
46 changed files with 168 additions and 75 deletions

View File

@ -109,7 +109,7 @@ private final class ContentNode: ASDisplayNode {
strongSelf.updateImage(image: image, size: size, spacing: spacing) strongSelf.updateImage(image: image, size: size, spacing: spacing)
} }
}) })
self.disposable = disposable self.disposable = disposable.strict()
} else { } else {
let image = generateImage(size, rotatedContext: { size, context in let image = generateImage(size, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size)) context.clear(CGRect(origin: CGPoint(), size: size))
@ -342,7 +342,7 @@ public final class AnimatedAvatarSetView: UIView {
strongSelf.updateImage(image: image, size: size, spacing: spacing) strongSelf.updateImage(image: image, size: size, spacing: spacing)
} }
}) })
self.disposable = disposable self.disposable = disposable.strict()
} else { } else {
let image = generateImage(size, rotatedContext: { size, context in let image = generateImage(size, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size)) context.clear(CGRect(origin: CGPoint(), size: size))

View File

@ -129,7 +129,7 @@ public final class DirectAnimatedStickerNode: ASDisplayNode, AnimatedStickerNode
strongSelf.setupPlayback(lottieInstance: lottieInstance) strongSelf.setupPlayback(lottieInstance: lottieInstance)
} }
}) }).strict()
} }
private func updatePlayback() { private func updatePlayback() {

View File

@ -94,7 +94,7 @@ private final class IconComponent: Component {
} else { } else {
self?.image = image self?.image = image
} }
}) }).strict()
} else { } else {
if let tintColor = component.tintColor { if let tintColor = component.tintColor {
self.image = generateTintedImage(image: UIImage(bundleImageName: component.name), color: tintColor, backgroundColor: nil) self.image = generateTintedImage(image: UIImage(bundleImageName: component.name), color: tintColor, backgroundColor: nil)
@ -1042,7 +1042,7 @@ final class AttachmentPanel: ASDisplayNode, UIScrollViewDelegate {
let _ = strongSelf.update(layout: layout, buttons: strongSelf.buttons, isSelecting: strongSelf.isSelecting, elevateProgress: strongSelf.elevateProgress, transition: .immediate) let _ = strongSelf.update(layout: layout, buttons: strongSelf.buttons, isSelecting: strongSelf.isSelecting, elevateProgress: strongSelf.elevateProgress, transition: .immediate)
} }
} }
}) }).strict()
} }
deinit { deinit {

View File

@ -84,7 +84,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
|> distinctUntilChanged |> distinctUntilChanged
|> deliverOnMainQueue).start(next: { [weak self] state in |> deliverOnMainQueue).start(next: { [weak self] state in
self?.updateState(state: state) self?.updateState(state: state)
}) }).strict()
} }
required public init(coder aDecoder: NSCoder) { required public init(coder aDecoder: NSCoder) {

View File

@ -563,7 +563,7 @@ public final class AvatarNode: ASDisplayNode {
return return
} }
self.imageNode.contents = image?.cgImage self.imageNode.contents = image?.cgImage
}) }).strict()
} }
} }
} }

View File

@ -180,7 +180,7 @@ public final class AvatarVideoNode: ASDisplayNode {
strongSelf.animationFile = file strongSelf.animationFile = file
strongSelf.setupAnimation() strongSelf.setupAnimation()
} }
}) }).strict()
case let .sticker(packReference, fileId): case let .sticker(packReference, fileId):
self.fileDisposable = (self.context.engine.stickers.loadedStickerPack(reference: packReference, forceActualized: false) self.fileDisposable = (self.context.engine.stickers.loadedStickerPack(reference: packReference, forceActualized: false)
|> map { pack -> TelegramMediaFile? in |> map { pack -> TelegramMediaFile? in
@ -194,7 +194,7 @@ public final class AvatarVideoNode: ASDisplayNode {
strongSelf.animationFile = file strongSelf.animationFile = file
strongSelf.setupAnimation() strongSelf.setupAnimation()
} }
}) }).strict()
} }
} }

View File

@ -1116,7 +1116,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz
strongSelf.updateActionButton() strongSelf.updateActionButton()
} }
}) }).strict()
self.addSubnode(self.actionButtonPanelNode) self.addSubnode(self.actionButtonPanelNode)
self.actionButtonPanelNode.addSubnode(self.actionButtonPanelSeparator) self.actionButtonPanelNode.addSubnode(self.actionButtonPanelSeparator)
@ -1140,7 +1140,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz
strongSelf.passwordTip = hint strongSelf.passwordTip = hint
} }
} }
}) }).strict()
self.actionButtonPanelSeparator.backgroundColor = self.presentationData.theme.rootController.navigationBar.separatorColor self.actionButtonPanelSeparator.backgroundColor = self.presentationData.theme.rootController.navigationBar.separatorColor
self.actionButtonPanelNode.backgroundColor = presentationData.theme.rootController.navigationBar.opaqueBackgroundColor self.actionButtonPanelNode.backgroundColor = presentationData.theme.rootController.navigationBar.opaqueBackgroundColor

View File

@ -49,7 +49,7 @@ final class BotCheckoutPaymentMethodSheetController: ActionSheetController {
if let strongSelf = self { if let strongSelf = self {
strongSelf.theme = ActionSheetControllerTheme(presentationData: presentationData) strongSelf.theme = ActionSheetControllerTheme(presentationData: presentationData)
} }
}) }).strict()
var items: [ActionSheetItem] = [] var items: [ActionSheetItem] = []

View File

@ -20,7 +20,7 @@ final class BotCheckoutPaymentShippingOptionSheetController: ActionSheetControll
if let strongSelf = self { if let strongSelf = self {
strongSelf.theme = ActionSheetControllerTheme(presentationData: presentationData) strongSelf.theme = ActionSheetControllerTheme(presentationData: presentationData)
} }
}) }).strict()
var items: [ActionSheetItem] = [] var items: [ActionSheetItem] = []

View File

@ -319,7 +319,7 @@ final class BotReceiptControllerNode: ItemListControllerNode {
strongSelf.receiptData.set(.single((receipt.invoice, receipt.info, receipt.shippingOption, receipt.credentialsTitle, receipt.invoiceMedia, receipt.tipAmount))) strongSelf.receiptData.set(.single((receipt.invoice, receipt.info, receipt.shippingOption, receipt.credentialsTitle, receipt.invoiceMedia, receipt.tipAmount)))
} }
}) }).strict()
self.actionButton.addTarget(self, action: #selector(self.actionButtonPressed), forControlEvents: .touchUpInside) self.actionButton.addTarget(self, action: #selector(self.actionButtonPressed), forControlEvents: .touchUpInside)

View File

@ -293,7 +293,7 @@ public class BrowserScreen: ViewController {
} }
strongSelf.contentState = state strongSelf.contentState = state
strongSelf.requestLayout(transition: .immediate) strongSelf.requestLayout(transition: .immediate)
}) }).strict()
self.content?.onScrollingUpdate = { [weak self] update in self.content?.onScrollingUpdate = { [weak self] update in
self?.onContentScrollingUpdate(update) self?.onContentScrollingUpdate(update)

View File

@ -87,7 +87,7 @@ private final class MediaPreviewView: SimpleLayer {
} }
strongSelf.contents = image.cgImage strongSelf.contents = image.cgImage
} }
}) }).strict()
} }
} }
} }
@ -1185,7 +1185,7 @@ public final class CalendarMessageScreen: ViewController {
return return
} }
strongSelf.calendarSource.loadMore() strongSelf.calendarSource.loadMore()
}) }).strict()
self.stateDisposable = (self.calendarSource.state self.stateDisposable = (self.calendarSource.state
|> deliverOnMainQueue).start(next: { [weak self] state in |> deliverOnMainQueue).start(next: { [weak self] state in
@ -1194,7 +1194,7 @@ public final class CalendarMessageScreen: ViewController {
} }
strongSelf.calendarState = state strongSelf.calendarState = state
strongSelf.reloadMediaInfo() strongSelf.reloadMediaInfo()
}) }).strict()
} }
deinit { deinit {

View File

@ -138,7 +138,7 @@ public final class CallListController: TelegramBaseController {
strongSelf.updateThemeAndStrings() strongSelf.updateThemeAndStrings()
} }
} }
}) }).strict()
self.scrollToTop = { [weak self] in self.scrollToTop = { [weak self] in
self?.controllerNode.scrollToLatest() self?.controllerNode.scrollToLatest()

View File

@ -198,7 +198,7 @@ final class ChatListContainerItemNode: ASDisplayNode {
} }
if let filter, case let .filter(id, _, _, data) = filter, data.isShared { if let filter, case let .filter(id, _, _, data) = filter, data.isShared {
self.pollFilterUpdatesDisposable = self.context.engine.peers.pollChatFolderUpdates(folderId: id).start() self.pollFilterUpdatesDisposable = self.context.engine.peers.pollChatFolderUpdates(folderId: id).start().strict()
self.chatFilterUpdatesDisposable = (self.context.engine.peers.subscribedChatFolderUpdates(folderId: id) self.chatFilterUpdatesDisposable = (self.context.engine.peers.subscribedChatFolderUpdates(folderId: id)
|> deliverOnMainQueue).start(next: { [weak self] result in |> deliverOnMainQueue).start(next: { [weak self] result in
guard let self else { guard let self else {
@ -221,7 +221,7 @@ final class ChatListContainerItemNode: ASDisplayNode {
self.updateLayout(size: size, insets: insets, visualNavigationHeight: visualNavigationHeight, originalNavigationHeight: originalNavigationHeight, inlineNavigationLocation: inlineNavigationLocation, inlineNavigationTransitionFraction: inlineNavigationTransitionFraction, storiesInset: storiesInset, transition: .animated(duration: 0.4, curve: .spring)) self.updateLayout(size: size, insets: insets, visualNavigationHeight: visualNavigationHeight, originalNavigationHeight: originalNavigationHeight, inlineNavigationLocation: inlineNavigationLocation, inlineNavigationTransitionFraction: inlineNavigationTransitionFraction, storiesInset: storiesInset, transition: .animated(duration: 0.4, curve: .spring))
} }
} }
}) }).strict()
} }
if case let .forum(peerId) = location { if case let .forum(peerId) = location {
@ -242,7 +242,7 @@ final class ChatListContainerItemNode: ASDisplayNode {
self.updateLayout(size: size, insets: insets, visualNavigationHeight: visualNavigationHeight, originalNavigationHeight: originalNavigationHeight, inlineNavigationLocation: inlineNavigationLocation, inlineNavigationTransitionFraction: inlineNavigationTransitionFraction, storiesInset: storiesInset, transition: .animated(duration: 0.4, curve: .spring)) self.updateLayout(size: size, insets: insets, visualNavigationHeight: visualNavigationHeight, originalNavigationHeight: originalNavigationHeight, inlineNavigationLocation: inlineNavigationLocation, inlineNavigationTransitionFraction: inlineNavigationTransitionFraction, storiesInset: storiesInset, transition: .animated(duration: 0.4, curve: .spring))
} }
} }
}) }).strict()
} }
} }

View File

@ -401,7 +401,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
strongSelf.tabBarItem.badgeValue = compactNumericCountString(Int(count.0), decimalSeparator: presentationData.dateTimeFormat.decimalSeparator) strongSelf.tabBarItem.badgeValue = compactNumericCountString(Int(count.0), decimalSeparator: presentationData.dateTimeFormat.decimalSeparator)
} }
} }
}) }).strict()
self.presentationDataDisposable = (context.sharedContext.presentationData self.presentationDataDisposable = (context.sharedContext.presentationData
|> deliverOnMainQueue).start(next: { [weak self] presentationData in |> deliverOnMainQueue).start(next: { [weak self] presentationData in
@ -416,7 +416,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
strongSelf.updateThemeAndStrings() strongSelf.updateThemeAndStrings()
} }
} }
}) }).strict()
if !previewing { if !previewing {
/* /*

View File

@ -149,7 +149,7 @@ final class ChatListEmptyNode: ASDisplayNode {
if let (size, insets) = self.validLayout { if let (size, insets) = self.validLayout {
self.updateLayout(size: size, insets: insets, transition: .immediate) self.updateLayout(size: size, insets: insets, transition: .immediate)
} }
}) }).strict()
} }
} }

View File

@ -501,7 +501,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
strongSelf.updateTheme(theme: presentationData.theme) strongSelf.updateTheme(theme: presentationData.theme)
} }
} }
}) }).strict()
if case let .forum(peerId) = location { if case let .forum(peerId) = location {
let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId))

View File

@ -2656,7 +2656,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
} }
}) })
} }
}) }).strict()
self.recentListNode.beganInteractiveDragging = { _ in self.recentListNode.beganInteractiveDragging = { _ in
interaction.dismissInput() interaction.dismissInput()
@ -2733,7 +2733,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
} }
} }
strongSelf.playlistLocation = playlistStateAndType?.1.playlistLocation strongSelf.playlistLocation = playlistStateAndType?.1.playlistLocation
}) }).strict()
} }
self.deletedMessagesDisposable = (context.account.stateManager.deletedMessages self.deletedMessagesDisposable = (context.account.stateManager.deletedMessages
@ -2758,7 +2758,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
return state return state
} }
} }
}) }).strict()
} }
deinit { deinit {
@ -3056,7 +3056,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
} }
} }
}, completed: { }, completed: {
}) }).strict()
cancelImpl = { cancelImpl = {
self?.playlistPreloadDisposable?.dispose() self?.playlistPreloadDisposable?.dispose()
} }

View File

@ -683,7 +683,7 @@ final class ChatListSearchMediaNode: ASDisplayNode, UIScrollViewDelegate {
for (_, itemNode) in strongSelf.visibleMediaItems { for (_, itemNode) in strongSelf.visibleMediaItems {
itemNode.updateHiddenMedia() itemNode.updateHiddenMedia()
} }
}) }).strict()
} }
deinit { deinit {

View File

@ -134,7 +134,7 @@ private final class ChatListSearchPendingPane {
|> deliverOnMainQueue).start(next: { [weak self] _ in |> deliverOnMainQueue).start(next: { [weak self] _ in
self?.isReady = true self?.isReady = true
hasBecomeReady(key) hasBecomeReady(key)
}) }).strict()
} }
deinit { deinit {

View File

@ -1832,7 +1832,7 @@ public final class ChatListNode: ListView {
|> distinctUntilChanged |> distinctUntilChanged
self.suggestedChatListNotice.set(suggestedChatListNoticeSignal) self.suggestedChatListNotice.set(suggestedChatListNoticeSignal)
}) }).strict()
let storageInfo: Signal<Double?, NoError> let storageInfo: Signal<Double?, NoError>
if !"".isEmpty, case .chatList(groupId: .root) = location, chatListFilter == nil { if !"".isEmpty, case .chatList(groupId: .root) = location, chatListFilter == nil {
@ -2723,7 +2723,7 @@ public final class ChatListNode: ListView {
return state return state
} }
} }
}) }).strict()
self.reorderItem = { [weak self] fromIndex, toIndex, transactionOpaqueState -> Signal<Bool, NoError> in self.reorderItem = { [weak self] fromIndex, toIndex, transactionOpaqueState -> Signal<Bool, NoError> in
guard let strongSelf = self, let filteredEntries = (transactionOpaqueState as? ChatListOpaqueTransactionState)?.chatListView.filteredEntries else { guard let strongSelf = self, let filteredEntries = (transactionOpaqueState as? ChatListOpaqueTransactionState)?.chatListView.filteredEntries else {

View File

@ -75,7 +75,7 @@ public final class ChatSendMessageActionSheetController: ViewController {
strongSelf.controllerNode.updatePresentationData(presentationData) strongSelf.controllerNode.updatePresentationData(presentationData)
} }
} }
}) }).strict()
self.statusBar.statusBarStyle = .Hide self.statusBar.statusBarStyle = .Hide
self.statusBar.ignoreInCall = true self.statusBar.ignoreInCall = true

View File

@ -93,7 +93,7 @@ public final class ReactionIconView: PortalSourceView {
} }
strongSelf.file = files[fileId] strongSelf.file = files[fileId]
strongSelf.reloadFile() strongSelf.reloadFile()
}) }).strict()
} }
} }

View File

@ -151,7 +151,7 @@ public final class ReactionImageNode: ASDisplayNode {
strongSelf.iconNode.image = image strongSelf.iconNode.image = image
} }
} }
}) }).strict()
} else if let file = file { } else if let file = file {
self.size = file.dimensions?.cgSize ?? displayPixelSize self.size = file.dimensions?.cgSize ?? displayPixelSize
self.isAnimation = false self.isAnimation = false
@ -169,7 +169,7 @@ public final class ReactionImageNode: ASDisplayNode {
strongSelf.iconNode.image = image strongSelf.iconNode.image = image
} }
} }
}) }).strict()
} else { } else {
self.size = displayPixelSize self.size = displayPixelSize
self.isAnimation = false self.isAnimation = false

View File

@ -163,7 +163,7 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent
} }
strongSelf.file = file strongSelf.file = file
strongSelf.updateReactionLayer() strongSelf.updateReactionLayer()
}) }).strict()
} }
} else { } else {
let iconNode = ASImageNode() let iconNode = ASImageNode()
@ -507,7 +507,7 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent
} }
strongSelf.file = file strongSelf.file = file
strongSelf.updateReactionLayer() strongSelf.updateReactionLayer()
}) }).strict()
} }
} else { } else {
self.file = nil self.file = nil
@ -825,7 +825,7 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent
itemNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) itemNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
} }
} }
}) }).strict()
} }
deinit { deinit {

View File

@ -267,7 +267,7 @@ open class ViewControllerComponentContainer: ViewController {
strongSelf.containerLayoutUpdated(layout, transition: .immediate) strongSelf.containerLayoutUpdated(layout, transition: .immediate)
} }
} }
}) }).strict()
switch statusBarStyle { switch statusBarStyle {
case .none: case .none:

View File

@ -1385,7 +1385,7 @@ public final class ContactListNode: ASDisplayNode {
} }
} }
} }
}) }).strict()
self.listNode.didEndScrolling = { [weak self] _ in self.listNode.didEndScrolling = { [weak self] _ in
if let strongSelf = self { if let strongSelf = self {

View File

@ -184,7 +184,7 @@ public class ContactsController: ViewController {
strongSelf.updateThemeAndStrings() strongSelf.updateThemeAndStrings()
} }
} }
}) }).strict()
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) { if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
self.authorizationDisposable = (combineLatest(DeviceAccess.authorizationStatus(subject: .contacts), combineLatest(context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.permissionWarningKey(permission: .contacts)!), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings])) self.authorizationDisposable = (combineLatest(DeviceAccess.authorizationStatus(subject: .contacts), combineLatest(context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.permissionWarningKey(permission: .contacts)!), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]))
@ -211,7 +211,7 @@ public class ContactsController: ViewController {
strongSelf.tabBarItem.badgeValue = status != .allowed && !suppressed ? "!" : nil strongSelf.tabBarItem.badgeValue = status != .allowed && !suppressed ? "!" : nil
strongSelf.sortOrderPromise.set(.single(sortOrder)) strongSelf.sortOrderPromise.set(.single(sortOrder))
} }
}) }).strict()
} else { } else {
self.sortOrderPromise.set(context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]) self.sortOrderPromise.set(context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings])
|> map { sharedData -> ContactsSortOrder in |> map { sharedData -> ContactsSortOrder in

View File

@ -143,7 +143,7 @@ final class ContactsControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
strongSelf.updateThemeAndStrings() strongSelf.updateThemeAndStrings()
} }
} }
}) }).strict()
addNearbyImpl = { [weak self] in addNearbyImpl = { [weak self] in
if let strongSelf = self { if let strongSelf = self {
@ -243,7 +243,7 @@ final class ContactsControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
self.contactListNode.storySubscriptions.set(.single(storySubscriptions)) self.contactListNode.storySubscriptions.set(.single(storySubscriptions))
self.storiesReady.set(.single(true)) self.storiesReady.set(.single(true))
})*/ }).strict()*/
self.contactListNode.openStories = { [weak self] peer, sourceNode in self.contactListNode.openStories = { [weak self] peer, sourceNode in
guard let self else { guard let self else {

View File

@ -67,7 +67,7 @@ public class InviteContactsController: ViewController, MFMessageComposeViewContr
strongSelf.updateThemeAndStrings() strongSelf.updateThemeAndStrings()
} }
} }
}) }).strict()
self.searchContentNode = NavigationBarSearchContentNode(theme: self.presentationData.theme, placeholder: self.presentationData.strings.Common_Search, activate: { [weak self] in self.searchContentNode = NavigationBarSearchContentNode(theme: self.presentationData.theme, placeholder: self.presentationData.strings.Common_Search, activate: { [weak self] in
self?.activateSearch() self?.activateSearch()

View File

@ -325,7 +325,7 @@ final class InviteContactsControllerNode: ASDisplayNode {
strongSelf.updateThemeAndStrings() strongSelf.updateThemeAndStrings()
} }
} }
}) }).strict()
let selectionStateSignal = self.selectionStatePromise.get() let selectionStateSignal = self.selectionStatePromise.get()
let transition: Signal<InviteContactsTransition, NoError> let transition: Signal<InviteContactsTransition, NoError>
@ -428,7 +428,7 @@ final class InviteContactsControllerNode: ASDisplayNode {
self.disposable = transition.start(next: { [weak self] transition in self.disposable = transition.start(next: { [weak self] transition in
self?.enqueueTransition(transition) self?.enqueueTransition(transition)
}) }).strict()
shareImpl = { [weak self] in shareImpl = { [weak self] in
if let strongSelf = self { if let strongSelf = self {

View File

@ -210,7 +210,7 @@ public final class ContextActionNode: ASDisplayNode, ContextActionNodeProtocol {
return return
} }
strongSelf.iconNode.image = image strongSelf.iconNode.image = image
}) }).strict()
} }
} }

View File

@ -804,7 +804,7 @@ final class ContextActionsContainerNode: ASDisplayNode {
strongSelf.tip = tip strongSelf.tip = tip
requestLayout() requestLayout()
}) }).strict()
} }
} }

View File

@ -2540,7 +2540,7 @@ public final class ContextController: ViewController, StandalonePresentableContr
return return
} }
strongSelf.dismiss(result: .default, completion: {}) strongSelf.dismiss(result: .default, completion: {})
}) }).strict()
case let .reference(referenceSource): case let .reference(referenceSource):
self.statusBar.statusBarStyle = .Ignore self.statusBar.statusBarStyle = .Ignore
@ -2552,7 +2552,7 @@ public final class ContextController: ViewController, StandalonePresentableContr
return return
} }
strongSelf.dismiss(result: .default, completion: {}) strongSelf.dismiss(result: .default, completion: {})
}) }).strict()
case let .extracted(extractedSource): case let .extracted(extractedSource):
if extractedSource.blurBackground { if extractedSource.blurBackground {
self.statusBar.statusBarStyle = .Hide self.statusBar.statusBarStyle = .Hide
@ -2567,7 +2567,7 @@ public final class ContextController: ViewController, StandalonePresentableContr
return return
} }
strongSelf.dismiss(result: .default, completion: {}) strongSelf.dismiss(result: .default, completion: {})
}) }).strict()
case .controller: case .controller:
self.statusBar.statusBarStyle = .Hide self.statusBar.statusBarStyle = .Hide
} }

View File

@ -296,7 +296,7 @@ private final class ContextControllerActionsListActionItemNode: HighlightTrackin
return return
} }
strongSelf.iconNode.image = image strongSelf.iconNode.image = image
}) }).strict()
} }
} else if let image = self.iconNode.image { } else if let image = self.iconNode.image {
iconSize = image.size iconSize = image.size
@ -1122,7 +1122,7 @@ final class ContextControllerActionsStackNode: ASDisplayNode {
} }
strongSelf.tip = tip strongSelf.tip = tip
requestUpdate(.immediate) requestUpdate(.immediate)
}) }).strict()
} }
} }

View File

@ -26,7 +26,7 @@ public final class DateSelectionActionSheetController: ActionSheetController {
if let strongSelf = self { if let strongSelf = self {
strongSelf.theme = ActionSheetControllerTheme(presentationData: presentationData) strongSelf.theme = ActionSheetControllerTheme(presentationData: presentationData)
} }
}) }).strict()
self._ready.set(.single(true)) self._ready.set(.single(true))

View File

@ -56,7 +56,7 @@ final class NavigationOverlayContainer: ASDisplayNode {
strongSelf.isReadyUpdated?() strongSelf.isReadyUpdated?()
} }
} }
}) }).strict()
} }
deinit { deinit {

View File

@ -559,7 +559,7 @@ public class StickerPickerScreen: ViewController {
} else { } else {
strongSelf.gifMode = hasRecentGifs ? .recent : .trending strongSelf.gifMode = hasRecentGifs ? .recent : .trending
} }
}) }).strict()
self.trendingGifsPromise.set(.single(nil)) self.trendingGifsPromise.set(.single(nil))
self.trendingGifsPromise.set(paneGifSearchForQuery(context: context, query: "", offset: nil, incompleteResults: true, delayRequest: false, updateActivity: nil) self.trendingGifsPromise.set(paneGifSearchForQuery(context: context, query: "", offset: nil, incompleteResults: true, delayRequest: false, updateActivity: nil)

View File

@ -402,7 +402,7 @@ public final class ChatMediaInputTrendingPane: ChatMediaInputPane {
strongSelf.didSetReady = true strongSelf.didSetReady = true
strongSelf._ready.set(.single(Void())) strongSelf._ready.set(.single(Void()))
} }
}) }).strict()
} }
public override func updateLayout(size: CGSize, topInset: CGFloat, bottomInset: CGFloat, isExpanded: Bool, isVisible: Bool, deviceMetrics: DeviceMetrics, transition: ContainedViewLayoutTransition) { public override func updateLayout(size: CGSize, topInset: CGFloat, bottomInset: CGFloat, isExpanded: Bool, isVisible: Bool, deviceMetrics: DeviceMetrics, transition: ContainedViewLayoutTransition) {

View File

@ -422,7 +422,7 @@ private final class FeaturedStickersScreenNode: ViewControllerTracingNode {
strongSelf.didSetReady = true strongSelf.didSetReady = true
strongSelf._ready.set(.single(true)) strongSelf._ready.set(.single(true))
} }
}) }).strict()
self.controller?.searchNavigationNode?.setQueryUpdated({ [weak self] query, languageCode in self.controller?.searchNavigationNode?.setQueryUpdated({ [weak self] query, languageCode in
guard let strongSelf = self else { guard let strongSelf = self else {

View File

@ -1120,7 +1120,7 @@ public class GalleryController: ViewController, StandalonePresentableController,
if let strongSelf = self, strongSelf.traceVisibility() { if let strongSelf = self, strongSelf.traceVisibility() {
let _ = strongSelf.context.engine.messages.addSecretChatMessageScreenshot(peerId: id.peerId).start() let _ = strongSelf.context.engine.messages.addSecretChatMessageScreenshot(peerId: id.peerId).start()
} }
}) }).strict()
} }
default: default:
break break

View File

@ -156,7 +156,7 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
if let strongSelf = self { if let strongSelf = self {
strongSelf.pagingEnabled = pagingEnabled strongSelf.pagingEnabled = pagingEnabled
} }
}) }).strict()
} }
deinit { deinit {

View File

@ -516,7 +516,7 @@ private final class PictureInPictureContentImpl: NSObject, PictureInPictureConte
strongSelf.pictureInPictureController?.invalidatePlaybackState() strongSelf.pictureInPictureController?.invalidatePlaybackState()
} }
} }
}) }).strict()
} }
deinit { deinit {
@ -938,7 +938,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
} else { } else {
strongSelf.footerContentNode.setFramePreviewImage(image: nil) strongSelf.footerContentNode.setFramePreviewImage(image: nil)
} }
}) }).strict()
self.alternativeDismiss = { [weak self] in self.alternativeDismiss = { [weak self] in
guard let strongSelf = self, strongSelf.hasPictureInPicture else { guard let strongSelf = self, strongSelf.hasPictureInPicture else {
@ -973,7 +973,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
if let strongSelf = self { if let strongSelf = self {
strongSelf.updateControlsVisibility(false) strongSelf.updateControlsVisibility(false)
} }
}) }).strict()
} }
deinit { deinit {

View File

@ -4,6 +4,32 @@ public protocol Disposable: AnyObject {
func dispose() func dispose()
} }
public final class StrictDisposable: Disposable {
private let disposable: Disposable
private let isDisposed = Atomic<Bool>(value: false)
public init(_ disposable: Disposable) {
self.disposable = disposable
}
deinit {
#if DEBUG
assert(self.isDisposed.with({ $0 }))
#endif
}
public func dispose() {
let _ = self.isDisposed.swap(true)
self.disposable.dispose()
}
}
public extension Disposable {
func strict() -> Disposable {
return StrictDisposable(self)
}
}
final class _EmptyDisposable: Disposable { final class _EmptyDisposable: Disposable {
func dispose() { func dispose() {
} }

View File

@ -23,18 +23,37 @@ public func |> <T, U>(value: T, function: ((T) -> U)) -> U {
return function(value) return function(value)
} }
private final class SubscriberDisposable<T, E> : Disposable { private final class SubscriberDisposable<T, E>: Disposable, CustomStringConvertible {
private let subscriber: Subscriber<T, E> private let subscriber: Subscriber<T, E>
private let disposable: Disposable
init(subscriber: Subscriber<T, E>, disposable: Disposable) { private var lock = pthread_mutex_t()
private var disposable: Disposable?
init(subscriber: Subscriber<T, E>, disposable: Disposable?) {
self.subscriber = subscriber self.subscriber = subscriber
self.disposable = disposable self.disposable = disposable
pthread_mutex_init(&self.lock, nil)
}
deinit {
pthread_mutex_destroy(&self.lock)
} }
func dispose() { func dispose() {
subscriber.markTerminatedWithoutDisposal() self.subscriber.markTerminatedWithoutDisposal()
disposable.dispose()
var disposeItem: Disposable?
pthread_mutex_lock(&self.lock)
disposeItem = self.disposable
self.disposable = nil
pthread_mutex_unlock(&self.lock)
disposeItem?.dispose()
}
public var description: String {
return "SubscriberDisposable { disposable: \(self.disposable == nil ? "nil" : "hasValue") }"
} }
} }

View File

@ -1,13 +1,21 @@
import Foundation import Foundation
public final class Subscriber<T, E> { #if DEBUG
// Signals keep themselves in memory until terminated (dispose, putError, putCompletion)
private final class LiveSubscribers {
var dict: [ObjectIdentifier: AnyObject] = [:]
}
private let liveSubscribers = Atomic<LiveSubscribers>(value: LiveSubscribers())
#endif
public final class Subscriber<T, E>: CustomStringConvertible {
private var next: ((T) -> Void)! private var next: ((T) -> Void)!
private var error: ((E) -> Void)! private var error: ((E) -> Void)!
private var completed: (() -> Void)! private var completed: (() -> Void)!
private var lock = pthread_mutex_t() private var lock = pthread_mutex_t()
private var terminated = false private var terminated = false
internal var disposable: Disposable! internal var disposable: Disposable?
public init(next: ((T) -> Void)! = nil, error: ((E) -> Void)! = nil, completed: (() -> Void)! = nil) { public init(next: ((T) -> Void)! = nil, error: ((E) -> Void)! = nil, completed: (() -> Void)! = nil) {
self.next = next self.next = next
@ -16,6 +24,10 @@ public final class Subscriber<T, E> {
pthread_mutex_init(&self.lock, nil) pthread_mutex_init(&self.lock, nil)
} }
public var description: String {
return "Subscriber { next: \(self.next == nil ? "nil" : "hasValue"), error: \(self.error == nil ? "nil" : "hasValue"), completed: \(self.completed == nil ? "nil" : "hasValue"), disposable: \(self.disposable == nil ? "nil" : "hasValue"), terminated: \(self.terminated) }"
}
deinit { deinit {
var freeDisposable: Disposable? var freeDisposable: Disposable?
pthread_mutex_lock(&self.lock) pthread_mutex_lock(&self.lock)
@ -34,6 +46,12 @@ public final class Subscriber<T, E> {
} }
internal func assignDisposable(_ disposable: Disposable) { internal func assignDisposable(_ disposable: Disposable) {
#if DEBUG
liveSubscribers.with { impl in
//let _ = impl.dict[ObjectIdentifier(self)] = self
}
#endif
var dispose = false var dispose = false
pthread_mutex_lock(&self.lock) pthread_mutex_lock(&self.lock)
if self.terminated { if self.terminated {
@ -49,14 +67,33 @@ public final class Subscriber<T, E> {
} }
internal func markTerminatedWithoutDisposal() { internal func markTerminatedWithoutDisposal() {
var freeDisposable: Disposable?
pthread_mutex_lock(&self.lock) pthread_mutex_lock(&self.lock)
if !self.terminated { if !self.terminated {
self.terminated = true self.terminated = true
self.next = nil self.next = nil
self.error = nil self.error = nil
self.completed = nil self.completed = nil
if let disposable = self.disposable {
freeDisposable = disposable
self.disposable = nil
}
} }
pthread_mutex_unlock(&self.lock) pthread_mutex_unlock(&self.lock)
if let freeDisposableValue = freeDisposable {
withExtendedLifetime(freeDisposableValue, {
})
freeDisposable = nil
}
#if DEBUG
liveSubscribers.with { impl in
let _ = impl.dict.removeValue(forKey: ObjectIdentifier(self))
}
#endif
} }
public func putNext(_ next: T) { public func putNext(_ next: T) {
@ -86,7 +123,6 @@ public final class Subscriber<T, E> {
self.terminated = true self.terminated = true
disposeDisposable = self.disposable disposeDisposable = self.disposable
self.disposable = nil self.disposable = nil
} }
pthread_mutex_unlock(&self.lock) pthread_mutex_unlock(&self.lock)
@ -97,6 +133,12 @@ public final class Subscriber<T, E> {
if let disposeDisposable = disposeDisposable { if let disposeDisposable = disposeDisposable {
disposeDisposable.dispose() disposeDisposable.dispose()
} }
#if DEBUG
liveSubscribers.with { impl in
let _ = impl.dict.removeValue(forKey: ObjectIdentifier(self))
}
#endif
} }
public func putCompletion() { public func putCompletion() {
@ -141,5 +183,11 @@ public final class Subscriber<T, E> {
if let disposeDisposable = disposeDisposable { if let disposeDisposable = disposeDisposable {
disposeDisposable.dispose() disposeDisposable.dispose()
} }
#if DEBUG
liveSubscribers.with { impl in
let _ = impl.dict.removeValue(forKey: ObjectIdentifier(self))
}
#endif
} }
} }