mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Attempt to fix iOS 14 crash
This commit is contained in:
parent
64c904706b
commit
3c306ee71d
@ -65,43 +65,57 @@ public class SGLocalizationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func downloadLocale(_ locale: String) {
|
public func downloadLocale(_ locale: String) {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.2")
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
SGLogger.shared.log("Strings", "DEBUG ignoring locale download: \(locale)")
|
SGLogger.shared.log("Strings", "DEBUG ignoring locale download: \(locale)")
|
||||||
if ({ return true }()) {
|
if ({ return true }()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3")
|
||||||
let sanitizedLocale = self.sanitizeLocale(locale)
|
let sanitizedLocale = self.sanitizeLocale(locale)
|
||||||
|
SGLogger.shared.log("DEBUG", "3.4")
|
||||||
guard let url = URL(string: self.getStringsUrl(for: sanitizedLocale)) else {
|
guard let url = URL(string: self.getStringsUrl(for: sanitizedLocale)) else {
|
||||||
SGLogger.shared.log("Strings", "Invalid URL for locale: \(sanitizedLocale)")
|
SGLogger.shared.log("Strings", "Invalid URL for locale: \(sanitizedLocale)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
SGLogger.shared.log("DEBUG", "3.5")
|
||||||
DispatchQueue.global(qos: .background).async {
|
DispatchQueue.global(qos: .background).async {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.6")
|
||||||
if let localeDict = NSDictionary(contentsOf: url) as? [String: String] {
|
if let localeDict = NSDictionary(contentsOf: url) as? [String: String] {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.7")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.8")
|
||||||
self.webLocalizations[sanitizedLocale] = localeDict
|
self.webLocalizations[sanitizedLocale] = localeDict
|
||||||
|
SGLogger.shared.log("DEBUG", "3.9")
|
||||||
SGLogger.shared.log("Strings", "Successfully downloaded locale \(sanitizedLocale)")
|
SGLogger.shared.log("Strings", "Successfully downloaded locale \(sanitizedLocale)")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.10")
|
||||||
SGLogger.shared.log("Strings", "Failed to download \(sanitizedLocale)")
|
SGLogger.shared.log("Strings", "Failed to download \(sanitizedLocale)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func sanitizeLocale(_ locale: String) -> String {
|
private func sanitizeLocale(_ locale: String) -> String {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.1")
|
||||||
var sanitizedLocale = locale
|
var sanitizedLocale = locale
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.2")
|
||||||
let rawSuffix = "-raw"
|
let rawSuffix = "-raw"
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.3")
|
||||||
if locale.hasSuffix(rawSuffix) {
|
if locale.hasSuffix(rawSuffix) {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.4")
|
||||||
sanitizedLocale = String(locale.dropLast(rawSuffix.count))
|
sanitizedLocale = String(locale.dropLast(rawSuffix.count))
|
||||||
}
|
}
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.5")
|
||||||
if sanitizedLocale == "pt-br" {
|
if sanitizedLocale == "pt-br" {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.6")
|
||||||
sanitizedLocale = "pt"
|
sanitizedLocale = "pt"
|
||||||
} else if sanitizedLocale == "nb" {
|
} else if sanitizedLocale == "nb" {
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.7")
|
||||||
sanitizedLocale = "no"
|
sanitizedLocale = "no"
|
||||||
}
|
}
|
||||||
|
SGLogger.shared.log("DEBUG", "3.3.8")
|
||||||
return sanitizedLocale
|
return sanitizedLocale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1336,14 +1336,24 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
|||||||
self.resetIntentsIfNeeded(context: context.context)
|
self.resetIntentsIfNeeded(context: context.context)
|
||||||
|
|
||||||
// MARK: Swiftgram
|
// MARK: Swiftgram
|
||||||
|
SGLogger.shared.log("DEBUG", "iOS \(UIDevice.current.systemVersion), APP \(Bundle.main.infoDictionary?[kCFBundleVersionKey as String] ?? "")")
|
||||||
|
SGLogger.shared.log("DEBUG", "1")
|
||||||
updateSGWebSettingsInteractivelly(context: context.context)
|
updateSGWebSettingsInteractivelly(context: context.context)
|
||||||
let _ = (context.context.sharedContext.presentationData.start(next: { presentationData in
|
SGLogger.shared.log("DEBUG", "2")
|
||||||
SGLocalizationManager.shared.downloadLocale(presentationData.strings.baseLanguageCode)
|
let presentationData = context.context.sharedContext.currentPresentationData.with({ $0 })
|
||||||
}))
|
SGLogger.shared.log("DEBUG", "3")
|
||||||
|
let baseLanguageCode = presentationData.strings.baseLanguageCode
|
||||||
|
SGLogger.shared.log("DEBUG", "3.1 baseLanguageCode \(baseLanguageCode)")
|
||||||
|
SGLocalizationManager.shared.downloadLocale(baseLanguageCode)
|
||||||
|
SGLogger.shared.log("DEBUG", "4")
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
|
SGLogger.shared.log("DEBUG", "5")
|
||||||
let _ = Task {
|
let _ = Task {
|
||||||
|
SGLogger.shared.log("DEBUG", "6")
|
||||||
let primaryContext = await self.getPrimaryContext(anyContext: context.context)
|
let primaryContext = await self.getPrimaryContext(anyContext: context.context)
|
||||||
|
SGLogger.shared.log("DEBUG", "7")
|
||||||
SGLogger.shared.log("SGIAP", "Verifying Status \(primaryContext.sharedContext.immediateSGStatus.status) for: \(primaryContext.account.peerId.id._internalGetInt64Value())")
|
SGLogger.shared.log("SGIAP", "Verifying Status \(primaryContext.sharedContext.immediateSGStatus.status) for: \(primaryContext.account.peerId.id._internalGetInt64Value())")
|
||||||
|
SGLogger.shared.log("DEBUG", "8")
|
||||||
let _ = await self.fetchSGStatus(primaryContext: primaryContext)
|
let _ = await self.fetchSGStatus(primaryContext: primaryContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3398,13 +3408,18 @@ extension AppDelegate {
|
|||||||
SGLogger.shared.log("SGIAP", "Setting new primary user id: \(userId)")
|
SGLogger.shared.log("SGIAP", "Setting new primary user id: \(userId)")
|
||||||
SGSimpleSettings.shared.primaryUserId = stringUserId
|
SGSimpleSettings.shared.primaryUserId = stringUserId
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SGLogger.shared.log("SGIAP", "Status expired")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
NotificationCenter.default.post(name: .SGIAPHelperValidationErrorNotification, object: nil, userInfo: ["error": "PayWall.ValidationError.Expired"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
value.status = newStatus
|
value.status = newStatus
|
||||||
} else {
|
} else {
|
||||||
SGLogger.shared.log("SGIAP", "Status \(value.status) for \(userId) hasn't changed")
|
SGLogger.shared.log("SGIAP", "Status \(value.status) for \(userId) hasn't changed")
|
||||||
if newStatus < 1 {
|
if newStatus < 2 {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
NotificationCenter.default.post(name: .SGIAPHelperValidationErrorNotification, object: nil, userInfo: ["error": "PayWall.ValidationError.Expired"])
|
NotificationCenter.default.post(name: .SGIAPHelperValidationErrorNotification, object: nil, userInfo: ["error": "PayWall.ValidationError.TryAgain"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user