mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Refactor AppGroups
This commit is contained in:
parent
6cb34077fd
commit
7e999e8c48
17
Swiftgram/SGAppGroupIdentifier/BUILD
Normal file
17
Swiftgram/SGAppGroupIdentifier/BUILD
Normal file
@ -0,0 +1,17 @@
|
||||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
swift_library(
|
||||
name = "SGAppGroupIdentifier",
|
||||
module_name = "SGAppGroupIdentifier",
|
||||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
]),
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
)
|
@ -0,0 +1,28 @@
|
||||
import Foundation
|
||||
|
||||
let fallbackBaseBundleId: String = "app.swiftgram.ios"
|
||||
|
||||
public func sgAppGroupIdentifier() -> String {
|
||||
let baseBundleId: String
|
||||
if let bundleId: String = Bundle.main.bundleIdentifier {
|
||||
if Bundle.main.bundlePath.hasSuffix(".appex") {
|
||||
if let lastDotRange: Range<String.Index> = bundleId.range(of: ".", options: [.backwards]) {
|
||||
baseBundleId = String(bundleId[..<lastDotRange.lowerBound])
|
||||
} else {
|
||||
baseBundleId = fallbackBaseBundleId
|
||||
}
|
||||
} else {
|
||||
baseBundleId = bundleId
|
||||
}
|
||||
} else {
|
||||
baseBundleId = fallbackBaseBundleId
|
||||
}
|
||||
|
||||
let result: String = "group.\(baseBundleId)"
|
||||
|
||||
#if DEBUG
|
||||
print("APP_GROUP_IDENTIFIER: \(result)")
|
||||
#endif
|
||||
|
||||
return result
|
||||
}
|
@ -275,13 +275,15 @@ extension SGIAPManager: SKProductsRequestDelegate {
|
||||
extension SGIAPManager: SKPaymentTransactionObserver {
|
||||
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
||||
SGLogger.shared.log("SGIAP", "paymentQueue transactions \(transactions.count)")
|
||||
var purchaceTransactions: [SKPaymentTransaction] = []
|
||||
for transaction in transactions {
|
||||
SGLogger.shared.log("SGIAP", "Transaction \(transaction.transactionIdentifier ?? "nil") state for product \(transaction.payment.productIdentifier): \(transaction.transactionState.description)")
|
||||
switch transaction.transactionState {
|
||||
case .purchased, .restored:
|
||||
SGLogger.shared.log("SGIAP", "Sending SGIAPHelperPurchaseNotification for \(transaction.transactionIdentifier ?? "nil")")
|
||||
NotificationCenter.default.post(name: .SGIAPHelperPurchaseNotification, object: transaction)
|
||||
purchaceTransactions.append(transaction)
|
||||
break
|
||||
case .purchasing, .deferred:
|
||||
// Ignoring
|
||||
break
|
||||
case .failed:
|
||||
var localizedError: String = ""
|
||||
@ -298,6 +300,11 @@ extension SGIAPManager: SKPaymentTransactionObserver {
|
||||
SKPaymentQueue.default().finishTransaction(transaction)
|
||||
}
|
||||
}
|
||||
|
||||
if !purchaceTransactions.isEmpty {
|
||||
SGLogger.shared.log("SGIAP", "Sending SGIAPHelperPurchaseNotification for \(purchaceTransactions.map({ $0.transactionIdentifier ?? "nil" }).joined(separator: ", "))")
|
||||
NotificationCenter.default.post(name: .SGIAPHelperPurchaseNotification, object: purchaceTransactions)
|
||||
}
|
||||
}
|
||||
|
||||
public func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
|
||||
|
@ -10,6 +10,7 @@ swift_library(
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
"//Swiftgram/SGAppGroupIdentifier:SGAppGroupIdentifier",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import SGAppGroupIdentifier
|
||||
|
||||
|
||||
let appGroupIdentifier = "group.app.swiftgram.ios"
|
||||
let APP_GROUP_IDENTIFIER = sgAppGroupIdentifier()
|
||||
|
||||
public class SGSimpleSettings {
|
||||
|
||||
@ -16,7 +16,7 @@ public class SGSimpleSettings {
|
||||
UserDefaults.standard.register(defaults: SGSimpleSettings.defaultValues)
|
||||
// Just in case group defaults will be nil
|
||||
UserDefaults.standard.register(defaults: SGSimpleSettings.groupDefaultValues)
|
||||
if let groupUserDefaults = UserDefaults(suiteName: appGroupIdentifier) {
|
||||
if let groupUserDefaults = UserDefaults(suiteName: APP_GROUP_IDENTIFIER) {
|
||||
groupUserDefaults.register(defaults: SGSimpleSettings.groupDefaultValues)
|
||||
}
|
||||
}
|
||||
@ -55,7 +55,7 @@ public class SGSimpleSettings {
|
||||
}
|
||||
|
||||
public func synchronizeShared() {
|
||||
if let groupUserDefaults = UserDefaults(suiteName: appGroupIdentifier) {
|
||||
if let groupUserDefaults = UserDefaults(suiteName: APP_GROUP_IDENTIFIER) {
|
||||
groupUserDefaults.synchronize()
|
||||
}
|
||||
}
|
||||
@ -423,9 +423,12 @@ public class SGSimpleSettings {
|
||||
@UserDefault(key: Keys.videoPIPSwipeDirection.rawValue)
|
||||
public var videoPIPSwipeDirection: String
|
||||
|
||||
@UserDefault(key: Keys.legacyNotificationsFix.rawValue, userDefaults: UserDefaults(suiteName: appGroupIdentifier) ?? .standard)
|
||||
@UserDefault(key: Keys.legacyNotificationsFix.rawValue, userDefaults: UserDefaults(suiteName: APP_GROUP_IDENTIFIER) ?? .standard)
|
||||
public var legacyNotificationsFix: Bool
|
||||
|
||||
@UserDefault(key: Keys.legacyNotificationsFix.rawValue, userDefaults: UserDefaults(suiteName: APP_GROUP_IDENTIFIER) ?? .standard)
|
||||
public var status: Int64
|
||||
|
||||
public var b: Bool = true
|
||||
|
||||
@UserDefault(key: Keys.messageFilterKeywords.rawValue)
|
||||
@ -434,10 +437,10 @@ public class SGSimpleSettings {
|
||||
@UserDefault(key: Keys.inputToolbar.rawValue)
|
||||
public var inputToolbar: Bool
|
||||
|
||||
@UserDefault(key: Keys.pinnedMessageNotifications.rawValue, userDefaults: UserDefaults(suiteName: appGroupIdentifier) ?? .standard)
|
||||
@UserDefault(key: Keys.pinnedMessageNotifications.rawValue, userDefaults: UserDefaults(suiteName: APP_GROUP_IDENTIFIER) ?? .standard)
|
||||
public var pinnedMessageNotifications: String
|
||||
|
||||
@UserDefault(key: Keys.mentionsAndRepliesNotifications.rawValue, userDefaults: UserDefaults(suiteName: appGroupIdentifier) ?? .standard)
|
||||
@UserDefault(key: Keys.mentionsAndRepliesNotifications.rawValue, userDefaults: UserDefaults(suiteName: APP_GROUP_IDENTIFIER) ?? .standard)
|
||||
public var mentionsAndRepliesNotifications: String
|
||||
|
||||
@UserDefault(key: Keys.primaryUserId.rawValue)
|
||||
|
@ -1,12 +1,16 @@
|
||||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
sgdeps = [
|
||||
"//Swiftgram/SGAppGroupIdentifier:SGAppGroupIdentifier"
|
||||
]
|
||||
|
||||
swift_library(
|
||||
name = "NotificationServiceExtensionLib",
|
||||
module_name = "NotificationServiceExtensionLib",
|
||||
srcs = glob([
|
||||
"Sources/*.swift",
|
||||
]),
|
||||
deps = [
|
||||
deps = sgdeps + [
|
||||
"//submodules/Postbox:Postbox",
|
||||
"//submodules/TelegramCore:TelegramCore",
|
||||
"//submodules/BuildConfig:BuildConfig",
|
||||
|
@ -1,3 +1,4 @@
|
||||
import SGAppGroupIdentifier
|
||||
import Foundation
|
||||
import UserNotifications
|
||||
import SwiftSignalKit
|
||||
@ -18,7 +19,7 @@ import NotificationsPresentationData
|
||||
import RangeSet
|
||||
import ConvertOpusToAAC
|
||||
|
||||
private let groupUserDefaults: UserDefaults? = UserDefaults(suiteName: "group.app.swiftgram.ios")
|
||||
private let groupUserDefaults: UserDefaults? = UserDefaults(suiteName: sgAppGroupIdentifier())
|
||||
private let LEGACY_NOTIFICATIONS_FIX: Bool = groupUserDefaults?.bool(forKey: "legacyNotificationsFix") ?? false
|
||||
private let PINNED_MESSAGE_ACTION: String = groupUserDefaults?.string(forKey: "pinnedMessageNotifications") ?? "default"
|
||||
private let PINNED_MESSAGE_ACTION_EXCEPTIONS: [String: String] = (groupUserDefaults?.dictionary(forKey: "pinnedMessageNotificationsExceptions") as? [String: String]) ?? [:]
|
||||
|
@ -40,6 +40,10 @@ apple_resource_bundle(
|
||||
],
|
||||
)
|
||||
|
||||
sgdeps = [
|
||||
"//Swiftgram/SGAppGroupIdentifier:SGAppGroupIdentifier"
|
||||
]
|
||||
|
||||
swift_library(
|
||||
name = "TelegramCallsUI",
|
||||
module_name = "TelegramCallsUI",
|
||||
@ -52,7 +56,7 @@ swift_library(
|
||||
data = [
|
||||
":TelegramCallsUIBundle",
|
||||
],
|
||||
deps = [
|
||||
deps = sgdeps + [
|
||||
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
|
||||
"//submodules/Display:Display",
|
||||
"//submodules/TelegramPresentationData:TelegramPresentationData",
|
||||
|
@ -1,3 +1,4 @@
|
||||
import SGAppGroupIdentifier
|
||||
import Foundation
|
||||
import UIKit
|
||||
import CallKit
|
||||
@ -20,7 +21,7 @@ public final class CallKitIntegration {
|
||||
return false
|
||||
#else
|
||||
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
|
||||
return Locale.current.regionCode?.lowercased() != "cn" && !(UserDefaults(suiteName: "group.app.swiftgram.ios")?.bool(forKey: "legacyNotificationsFix") ?? false)
|
||||
return Locale.current.regionCode?.lowercased() != "cn" && !(UserDefaults(suiteName: sgAppGroupIdentifier())?.bool(forKey: "legacyNotificationsFix") ?? false)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user