76 行
2.6 KiB
Swift
76 行
2.6 KiB
Swift
|
|
@_exported import XuqmCoreSDK
|
||
|
|
@_exported import XuqmImSDK
|
||
|
|
@_exported import XuqmPushSDK
|
||
|
|
@_exported import XuqmUpdateSDK
|
||
|
|
@_exported import XuqmLicenseSDK
|
||
|
|
@_exported import XuqmFileSDK
|
||
|
|
|
||
|
|
import Foundation
|
||
|
|
|
||
|
|
/// Auto-registers all feature module hooks with XuqmSDK.shared.
|
||
|
|
/// Import `XuqmSDK` to get the full SDK experience (backward compatible).
|
||
|
|
extension XuqmSDK {
|
||
|
|
|
||
|
|
/// Register all module hooks. Called automatically when any module is first used.
|
||
|
|
public func registerModuleHooks() {
|
||
|
|
// License reader hook
|
||
|
|
licenseReader = {
|
||
|
|
guard let file = LicenseFileReader.read() else { return nil }
|
||
|
|
return LicenseFileData(
|
||
|
|
appKey: file.appKey,
|
||
|
|
appName: file.appName,
|
||
|
|
companyName: file.companyName,
|
||
|
|
packageName: file.packageName,
|
||
|
|
iosBundleId: file.iosBundleId,
|
||
|
|
harmonyBundleName: file.harmonyBundleName,
|
||
|
|
baseUrl: file.baseUrl,
|
||
|
|
serverUrl: file.serverUrl,
|
||
|
|
issuedAt: file.issuedAt,
|
||
|
|
expiresAt: file.expiresAt
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Initialize hook — auto-start push if configured
|
||
|
|
onInitialize = { @MainActor config in
|
||
|
|
if config.autoRegisterPush {
|
||
|
|
Task { @MainActor in
|
||
|
|
try? await PushSDK.shared.start()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Login hook — connect IM and register push token
|
||
|
|
onLogin = { @MainActor userId, userSig in
|
||
|
|
try await ImSDK.shared.login(userId, userSig)
|
||
|
|
if let token = XuqmSDK.shared.cachedDeviceToken {
|
||
|
|
try await PushSDK.shared.registerToken(token, userId: userId)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Logout hook — disconnect IM and unregister push
|
||
|
|
onLogout = { @MainActor userId in
|
||
|
|
ImSDK.shared.disconnect()
|
||
|
|
try await PushSDK.shared.unregisterToken(userId: userId)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Device token hook — register with push service
|
||
|
|
onDeviceToken = { @MainActor token, userId in
|
||
|
|
try await PushSDK.shared.registerToken(token, userId: userId)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Convenience initializer that auto-registers module hooks.
|
||
|
|
/// This provides backward compatibility for code that does `import XuqmSDK`.
|
||
|
|
@MainActor
|
||
|
|
public enum XuqmSDKSetup {
|
||
|
|
private static var hooksRegistered = false
|
||
|
|
|
||
|
|
/// Ensure module hooks are registered. Idempotent.
|
||
|
|
public static func ensureHooksRegistered() {
|
||
|
|
guard !hooksRegistered else { return }
|
||
|
|
hooksRegistered = true
|
||
|
|
XuqmSDK.shared.registerModuleHooks()
|
||
|
|
}
|
||
|
|
}
|