diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift index ab4ed49d3..76ca62770 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift @@ -887,7 +887,7 @@ private class AddVolumeHandler: FunctionHandler { object: volumeInfo ) - return "{\"broadcast\": false,\"result\": \"音量增加请求已发送\"}" + return "{\"broadcast\": true,\"result\": \"音量增加请求已发送\"}" } } @@ -903,7 +903,7 @@ private class ReduceVolumeHandler: FunctionHandler { object: volumeInfo ) - return "{\"broadcast\": false,\"result\": \"音量降低请求已发送\"}" + return "{\"broadcast\": true,\"result\": \"音量降低请求已发送\"}" } } @@ -919,7 +919,7 @@ private class MuteVolumeHandler: FunctionHandler { object: volumeInfo ) - return "{\"broadcast\": false,\"result\": \"静音请求已发送\"}" + return "{\"broadcast\": true,\"result\": \"静音请求已发送\"}" } } @@ -935,6 +935,6 @@ private class MaxVolumeHandler: FunctionHandler { object: volumeInfo ) - return "{\"broadcast\": false,\"result\": \"最大音量请求已发送\"}" + return "{\"broadcast\": true,\"result\": \"最大音量请求已发送\"}" } } diff --git a/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift b/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift index 081961674..89692b7b0 100644 --- a/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift +++ b/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift @@ -228,32 +228,13 @@ import QPlayAutoSDK return } - print("QPlayAutoManager: App已注册,开始连接重试机制") - // Add retry mechanism for socket errors - connectWithRetry(forceLogin: forceLogin, retryCount: 3) - } - - private func connectWithRetry(forceLogin: Bool, retryCount: Int) { - print("QPlayAutoManager: 连接重试,剩余次数: \(retryCount), forceLogin: \(forceLogin)") - - guard retryCount > 0 else { - print("QPlayAutoManager: ❌ 连接失败,所有重试次数已用完") - print("QPlayAutoManager: 最终状态 - isConnected: \(isConnected), isLoginOK: \(isLoginOK)") - - // 只有在所有重试都失败且确实有待处理回调时才清理 - if !loginCompletionHandlers.isEmpty { - print("QPlayAutoManager: 清理登录回调队列") - notifyLoginCompletion(false) - } - return - } - + print("QPlayAutoManager: App已注册,开始连接") let startTime = Date() print("QPlayAutoManager: 调用 QPlayAutoSDK.connectAndForceLogin(\(forceLogin))") QPlayAutoSDK.connectAndForceLogin(forceLogin) - // 增加超时时间,特别是强制登录时 + + // 设置超时检查 let timeoutInterval: TimeInterval = forceLogin ? 45.0 : 10.0 - // If connection fails due to socket error, retry after cleanup DispatchQueue.main.asyncAfter(deadline: .now() + timeoutInterval) { let endTime = Date() let duration = endTime.timeIntervalSince(startTime) @@ -262,10 +243,14 @@ import QPlayAutoSDK print("QPlayAutoManager: 连接状态检查 - isConnected: \(self.isConnected)") if !self.isConnected { - print("QPlayAutoManager: ⚠️ 连接失败,准备重试 (剩余 \(retryCount - 1) 次)") - print("QPlayAutoManager: 执行清理操作") - QPlayAutoSDK.stop() - self.connectWithRetry(forceLogin: forceLogin, retryCount: retryCount - 1) + print("QPlayAutoManager: ❌ 连接超时失败") + print("QPlayAutoManager: 最终状态 - isConnected: \(self.isConnected), isLoginOK: \(self.isLoginOK)") + + // 清理登录回调队列 + if !self.loginCompletionHandlers.isEmpty { + print("QPlayAutoManager: 清理登录回调队列") + self.notifyLoginCompletion(false) + } } else { print("QPlayAutoManager: ✅ 连接成功") if forceLogin { @@ -382,28 +367,29 @@ import QPlayAutoSDK operation() } else { // 未连接,先连接 - print("QPlayAutoManager: 未连接,正在尝试连接...") + print("QPlayAutoManager: 未连接,尝试连接...") connect(forceLogin: false) - // 使用延迟检查连接状态 + + // 超时检查 DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { [weak self] in guard let self = self else { return } if self.isConnected { print("QPlayAutoManager: 连接成功,执行操作") operation() } else { - print("QPlayAutoManager: 连接失败,无法执行操作") + print("QPlayAutoManager: 连接超时失败,无法执行操作") onFailure?(.connectionFailed) } } } } else { // 未登录,先登录 - print("QPlayAutoManager: 未登录,正在尝试登录...") + print("QPlayAutoManager: 未登录,尝试登录...") performLogin { [weak self] success in guard let self = self else { return } if success { - print("QPlayAutoManager: 登录成功,检查连接状态") - self.ensureLoginAndExecute(operation, onFailure: onFailure) + print("QPlayAutoManager: 登录成功,执行操作") + operation() } else { print("QPlayAutoManager: 登录失败,无法执行操作") onFailure?(.loginFailed) @@ -413,49 +399,21 @@ import QPlayAutoSDK } private func performLogin(completion: @escaping (Bool) -> Void) { - // 如果正在登录中,将回调添加到队列 loginCompletionHandlers.append(completion) - // 如果已经有登录请求在处理,直接返回 - if loginCompletionHandlers.count > 1 { - print("QPlayAutoManager: 登录请求已在队列中,当前队列长度: \(loginCompletionHandlers.count)") - return - } - - // 首先尝试使用保存的token进行reconnect。 暂时reconnect接口无法使用先屏蔽自动登陆逻辑 -// if hasValidStoredToken() { -// let tokenInfo = getStoredTokenInfo() -// print("QPlayAutoManager: 检测到有效token,开始热启动连接") -// print("QPlayAutoManager: Token信息 - OpenID: \(tokenInfo?["openId"] as? String ?? "未知")") -// print("QPlayAutoManager: Token信息 - 登录时间: \(tokenInfo?["loginTime"] as? Date ?? Date())") -// print("QPlayAutoManager: 当前连接状态 - isConnected: \(isConnected), isConnecting: \(isConnecting)") -// print("QPlayAutoManager: 当前登录状态 - isLoginOK: \(isLoginOK)") -// -// reconnect(timeout: 10.0) { [weak self] success, responseDict in -// if success { -// print("QPlayAutoManager: ✅ 热启动连接成功") -// print("QPlayAutoManager: 连接响应数据: \(responseDict ?? [:])") -// self?.notifyLoginCompletion(true) -// } else { -// print("QPlayAutoManager: ❌ 热启动连接失败") -// print("QPlayAutoManager: 失败响应数据: \(responseDict ?? [:])") -// print("QPlayAutoManager: 连接状态检查 - isConnected: \(self?.isConnected ?? false)") -// print("QPlayAutoManager: QQ音乐安装状态: \(self?.isQQMusicInstalled ?? false)") -// print("QPlayAutoManager: 开始执行强制登录流程") -// self?.forceLogin() -// } -// } -// } else { - print("QPlayAutoManager: ❌ 没有有效token,直接进行强制登录") - let tokenInfo = getStoredTokenInfo() - if tokenInfo == nil { - print("QPlayAutoManager: 原因:本地未存储任何token信息") - } else { - print("QPlayAutoManager: 原因:token已过期或无效") - print("QPlayAutoManager: 存储的token信息: \(tokenInfo!)") + if hasValidStoredToken() { + // 尝试热启动连接 + reconnect(timeout: 10.0) { [weak self] success, responseDict in + if success { + self?.notifyLoginCompletion(true) + } else { + self?.forceLogin() + } } + } else { + print("QPlayAutoManager: ❌ 没有有效token,直接进行强制登录") forceLogin() -// } + } } private func forceLogin() { @@ -467,7 +425,7 @@ import QPlayAutoSDK print(" - 当前登录状态: \(isLoginOK)") // 强制登录,会跳转到QQ音乐 - connect(forceLogin: false) + connect(forceLogin: true) // 设置超时监控(仅记录,不清理回调) DispatchQueue.main.asyncAfter(deadline: .now() + 60.0) { [weak self] in @@ -889,18 +847,12 @@ extension QPlayAutoManager: QPlayAutoSDKDelegate { } else { // 登录失败时清除可能无效的token clearStoredToken() - print("QPlayAutoManager: ❌ 登录失败,但不立即清理回调(等待重试或最终失败)") - // 注意:这里不立即调用 notifyLoginCompletion(false) - // 让重试机制来决定是否最终失败 - // 如果有等待的回调且不在重试过程中,则通知失败 + print("QPlayAutoManager: ❌ 登录失败") + + // 如果有等待的回调,立即通知失败 if !loginCompletionHandlers.isEmpty { - // 给一个短暂的延迟,让重试机制有机会处理 - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { - if !self.loginCompletionHandlers.isEmpty && !self.isLoginOK { - print("QPlayAutoManager: 登录失败,清理回调队列") - self.notifyLoginCompletion(false) - } - } + print("QPlayAutoManager: 登录失败,清理回调队列") + notifyLoginCompletion(false) } }