2026-05-23 01:20:57 +08:00
|
|
|
@_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() {
|
2026-06-02 17:15:49 +08:00
|
|
|
// Note: licenseReader hook removed — autoInitialize now reads config.xuqm directly via ConfigFileReader.
|
2026-05-23 01:20:57 +08:00
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
}
|
|
|
|
|
}
|