mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 11:23:48 +00:00
Fix async
This commit is contained in:
parent
820e93daa4
commit
87e0b3bb62
@ -11,13 +11,13 @@ public func updateSGGHSettingsInteractivelly(context: AccountContext) {
|
|||||||
let _ = Task {
|
let _ = Task {
|
||||||
do {
|
do {
|
||||||
let settings = try await fetchSGGHSettings(locale: locale)
|
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
|
updateAppConfiguration(transaction: transaction, { configuration -> AppConfiguration in
|
||||||
var configuration = configuration
|
var configuration = configuration
|
||||||
configuration.sgGHSettings = settings
|
configuration.sgGHSettings = settings
|
||||||
return configuration
|
return configuration
|
||||||
})
|
})
|
||||||
}).task
|
}).task()
|
||||||
} catch {
|
} catch {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ func fetchSGGHSettings(locale: String) async throws -> SGGHSettings {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for attempt in 1...maxRetries {
|
attemptsOuter: for attempt in 1...maxRetries {
|
||||||
do {
|
do {
|
||||||
let (data, response) = try await URLSession.shared.data(from: url)
|
let (data, response) = try await URLSession.shared.data(from: url)
|
||||||
guard let httpResponse = response as? HTTPURLResponse else {
|
guard let httpResponse = response as? HTTPURLResponse else {
|
||||||
@ -78,7 +78,8 @@ func fetchSGGHSettings(locale: String) async throws -> SGGHSettings {
|
|||||||
throw SGGHFetchError.decodingFailed
|
throw SGGHFetchError.decodingFailed
|
||||||
}
|
}
|
||||||
case 404:
|
case 404:
|
||||||
break // Try the next fallback
|
SGLogger.shared.log("SGGHSettings", "[\(attempt)] Not found \(candidate) on the remote.")
|
||||||
|
break attemptsOuter
|
||||||
default:
|
default:
|
||||||
SGLogger.shared.log("SGGHSettings", "[\(attempt)] Fetch failed for \(candidate), status code: \(httpResponse.statusCode)")
|
SGLogger.shared.log("SGGHSettings", "[\(attempt)] Fetch failed for \(candidate), status code: \(httpResponse.statusCode)")
|
||||||
throw SGGHFetchError.fetchFailed(statusCode: httpResponse.statusCode)
|
throw SGGHFetchError.fetchFailed(statusCode: httpResponse.statusCode)
|
||||||
|
@ -86,28 +86,26 @@ public extension Signal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var task: () async throws -> T {
|
func task() async throws -> T {
|
||||||
{
|
let disposable = MetaDisposable()
|
||||||
let disposable = MetaDisposable()
|
return try await withTaskCancellationHandler(operation: {
|
||||||
return try await withTaskCancellationHandler(operation: {
|
return try await withCheckedThrowingContinuation { continuation in
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
disposable.set((self |> take(1)).startStandalone(
|
||||||
disposable.set((self |> take(1)).startStandalone(
|
next: { value in
|
||||||
next: { value in
|
continuation.resume(returning: value)
|
||||||
continuation.resume(returning: value)
|
},
|
||||||
},
|
error: { err in
|
||||||
error: { err in
|
continuation.resume(throwing: SignalError(err))
|
||||||
continuation.resume(throwing: SignalError(err))
|
}
|
||||||
}
|
))
|
||||||
))
|
}
|
||||||
}
|
}, onCancel: {
|
||||||
}, onCancel: {
|
disposable.dispose()
|
||||||
disposable.dispose()
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var stream: AsyncThrowingStream<T, Error> {
|
func stream() -> AsyncThrowingStream<T, Error> {
|
||||||
AsyncThrowingStream { continuation in
|
return AsyncThrowingStream { continuation in
|
||||||
let disposable = self.startStandalone(
|
let disposable = self.startStandalone(
|
||||||
next: { value in
|
next: { value in
|
||||||
continuation.yield(value)
|
continuation.yield(value)
|
||||||
@ -127,14 +125,12 @@ public extension Signal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public extension Signal where E == NoError {
|
public extension Signal where E == NoError {
|
||||||
var task: () async -> T {
|
func task() async -> T {
|
||||||
{
|
return await self.get()
|
||||||
await self.get()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var stream: AsyncStream<T> {
|
func stream() -> AsyncStream<T> {
|
||||||
AsyncStream { continuation in
|
return AsyncStream { continuation in
|
||||||
let disposable = self.startStandalone(
|
let disposable = self.startStandalone(
|
||||||
next: { value in
|
next: { value in
|
||||||
continuation.yield(value)
|
continuation.yield(value)
|
||||||
|
@ -2012,7 +2012,10 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
|||||||
SharedDisplayLinkDriver.shared.updateForegroundState(self.isActiveValue)
|
SharedDisplayLinkDriver.shared.updateForegroundState(self.isActiveValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runForegroundTasks(onlySG: Bool = false) {
|
func runForegroundTasks() {
|
||||||
|
|
||||||
|
|
||||||
|
var sgTasksLaunched: Bool = false
|
||||||
|
|
||||||
let _ = (self.sharedContextPromise.get()
|
let _ = (self.sharedContextPromise.get()
|
||||||
|> take(1)
|
|> take(1)
|
||||||
@ -2022,10 +2025,10 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
|||||||
|> deliverOnMainQueue).start(next: { activeAccounts in
|
|> deliverOnMainQueue).start(next: { activeAccounts in
|
||||||
for (_, context, _) in activeAccounts.accounts {
|
for (_, context, _) in activeAccounts.accounts {
|
||||||
// MARK: Swiftgram
|
// MARK: Swiftgram
|
||||||
updateSGWebSettingsInteractivelly(context: context)
|
if !sgTasksLaunched {
|
||||||
updateSGGHSettingsInteractivelly(context: context)
|
updateSGWebSettingsInteractivelly(context: context)
|
||||||
if onlySG {
|
updateSGGHSettingsInteractivelly(context: context)
|
||||||
continue
|
sgTasksLaunched = true
|
||||||
}
|
}
|
||||||
(context.downloadedMediaStoreManager as? DownloadedMediaStoreManagerImpl)?.runTasks()
|
(context.downloadedMediaStoreManager as? DownloadedMediaStoreManagerImpl)?.runTasks()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user