From 028a7f38d0b82bd8c51f07abbbafac97a82fbb5d Mon Sep 17 00:00:00 2001 From: Kylmakalle Date: Sun, 13 Jul 2025 00:14:15 +0300 Subject: [PATCH] Fix async --- .../SGGHSettings/Sources/SGGHSettings.swift | 9 ++-- .../Sources/SGSwiftSignalKit.swift | 48 +++++++++---------- .../TelegramUI/Sources/AppDelegate.swift | 13 +++-- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Swiftgram/SGGHSettings/Sources/SGGHSettings.swift b/Swiftgram/SGGHSettings/Sources/SGGHSettings.swift index dce84ca986..750943d252 100644 --- a/Swiftgram/SGGHSettings/Sources/SGGHSettings.swift +++ b/Swiftgram/SGGHSettings/Sources/SGGHSettings.swift @@ -11,13 +11,13 @@ public func updateSGGHSettingsInteractivelly(context: AccountContext) { let _ = Task { do { let settings = try await fetchSGGHSettings(locale: locale) - let _ = (context.account.postbox.transaction { transaction in + let _ = await (context.account.postbox.transaction { transaction in updateAppConfiguration(transaction: transaction, { configuration -> AppConfiguration in var configuration = configuration configuration.sgGHSettings = settings return configuration }) - }).task + }).task() } catch { return } @@ -57,7 +57,7 @@ func fetchSGGHSettings(locale: String) async throws -> SGGHSettings { continue } - for attempt in 1...maxRetries { + attemptsOuter: for attempt in 1...maxRetries { do { let (data, response) = try await URLSession.shared.data(from: url) guard let httpResponse = response as? HTTPURLResponse else { @@ -78,7 +78,8 @@ func fetchSGGHSettings(locale: String) async throws -> SGGHSettings { throw SGGHFetchError.decodingFailed } case 404: - break // Try the next fallback + SGLogger.shared.log("SGGHSettings", "[\(attempt)] Not found \(candidate) on the remote.") + break attemptsOuter default: SGLogger.shared.log("SGGHSettings", "[\(attempt)] Fetch failed for \(candidate), status code: \(httpResponse.statusCode)") throw SGGHFetchError.fetchFailed(statusCode: httpResponse.statusCode) diff --git a/Swiftgram/SGSwiftSignalKit/Sources/SGSwiftSignalKit.swift b/Swiftgram/SGSwiftSignalKit/Sources/SGSwiftSignalKit.swift index 7b75120bb5..94cf367af5 100644 --- a/Swiftgram/SGSwiftSignalKit/Sources/SGSwiftSignalKit.swift +++ b/Swiftgram/SGSwiftSignalKit/Sources/SGSwiftSignalKit.swift @@ -86,28 +86,26 @@ public extension Signal { } } - var task: () async throws -> T { - { - let disposable = MetaDisposable() - return try await withTaskCancellationHandler(operation: { - return try await withCheckedThrowingContinuation { continuation in - disposable.set((self |> take(1)).startStandalone( - next: { value in - continuation.resume(returning: value) - }, - error: { err in - continuation.resume(throwing: SignalError(err)) - } - )) - } - }, onCancel: { - disposable.dispose() - }) - } + func task() async throws -> T { + let disposable = MetaDisposable() + return try await withTaskCancellationHandler(operation: { + return try await withCheckedThrowingContinuation { continuation in + disposable.set((self |> take(1)).startStandalone( + next: { value in + continuation.resume(returning: value) + }, + error: { err in + continuation.resume(throwing: SignalError(err)) + } + )) + } + }, onCancel: { + disposable.dispose() + }) } - var stream: AsyncThrowingStream { - AsyncThrowingStream { continuation in + func stream() -> AsyncThrowingStream { + return AsyncThrowingStream { continuation in let disposable = self.startStandalone( next: { value in continuation.yield(value) @@ -127,14 +125,12 @@ public extension Signal { } public extension Signal where E == NoError { - var task: () async -> T { - { - await self.get() - } + func task() async -> T { + return await self.get() } - var stream: AsyncStream { - AsyncStream { continuation in + func stream() -> AsyncStream { + return AsyncStream { continuation in let disposable = self.startStandalone( next: { value in continuation.yield(value) diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index 7d2c082fc1..983a248156 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -2012,7 +2012,10 @@ private func extractAccountManagerState(records: AccountRecordsView take(1) @@ -2022,10 +2025,10 @@ private func extractAccountManagerState(records: AccountRecordsView deliverOnMainQueue).start(next: { activeAccounts in for (_, context, _) in activeAccounts.accounts { // MARK: Swiftgram - updateSGWebSettingsInteractivelly(context: context) - updateSGGHSettingsInteractivelly(context: context) - if onlySG { - continue + if !sgTasksLaunched { + updateSGWebSettingsInteractivelly(context: context) + updateSGGHSettingsInteractivelly(context: context) + sgTasksLaunched = true } (context.downloadedMediaStoreManager as? DownloadedMediaStoreManagerImpl)?.runTasks() }