Browse Source

上传代码优化

weicu
liwei1dao 1 year ago
parent
commit
85c029f60b
  1. 3
      lib/modules/chat/controllers/chat_controller.dart
  2. 2
      local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt
  3. 41
      local_plugins/spotify_sdk/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifySdkService.kt

3
lib/modules/chat/controllers/chat_controller.dart

@ -112,8 +112,9 @@ class ChatController extends GetxController {
// 获取Agent
final Agent? foundAgent = AgentProvider.getAgentById(agentId);
if (foundAgent == null) {
Logger.error('无法找到Agent: $agentId');
Get.back();
Logger.error('无法找到Agent: $agentId');
return;
}

2
local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt

@ -168,7 +168,7 @@ class MCPSubClient(
private fun processToolsList(toolsResult: ListToolsResult?) {
try {
// 将MCP工具列表转换为ToolUnion列表
tools = toolsResult?.tools?.filter { tool -> config.tools == null || config.tools.contains(tool.name) == true
tools = toolsResult?.tools?.filter { tool -> config.tools.isNullOrEmpty() || config.tools.contains(tool.name)
}?.map { tool ->
// 转换为ToolUnion格式
ToolUnion.ofTool(

41
local_plugins/spotify_sdk/android/src/main/kotlin/de/minimalme/spotify_sdk/SpotifySdkService.kt

@ -55,8 +55,7 @@ class SpotifySdkService(private val context: Context? = null) {
private var spotifyAppRemote: SpotifyAppRemote? = null
private var playerApi: PlayerApi? = null
//-- Method implementations
private fun connectToSpotify(clientId: String?, redirectUrl: String?, result: MethodChannel.Result) {
public fun connectToSpotify(clientId: String?, redirectUrl: String?, result: MethodChannel.Result) {
if (clientId.isNullOrBlank() || redirectUrl.isNullOrBlank()) {
result.error(errorConnecting, "client id or redirectUrl are not set or have invalid format", "")
@ -162,7 +161,7 @@ class SpotifySdkService(private val context: Context? = null) {
}
}
private fun getAccessToken(clientId: String?, redirectUrl: String?, scope: String?, result: MethodChannel.Result) {
public fun getAccessToken(clientId: String?, redirectUrl: String?, scope: String?, result: MethodChannel.Result) {
if (applicationActivity == null) {
throw IllegalStateException("getAccessToken needs a foreground activity")
}
@ -172,8 +171,6 @@ class SpotifySdkService(private val context: Context? = null) {
} else {
//Convert String? scope to Array. Delimiter set as comma ","
val scopeArray = scope?.split(",")?.toTypedArray()
// methodConnectToSpotify.checkAndSetPendingOperation(result)
val builder = AuthorizationRequest.Builder(
clientId,
AuthorizationResponse.Type.TOKEN,
@ -190,20 +187,9 @@ class SpotifySdkService(private val context: Context? = null) {
}
}
private fun disconnectFromSpotify(result: MethodChannel.Result) {
public fun disconnectFromSpotify(result: MethodChannel.Result) {
if (spotifyAppRemote != null && spotifyAppRemote!!.isConnected) {
SpotifyAppRemote.disconnect(spotifyAppRemote)
// emit connection terminated event
// connStatusEventChannel(
// ConnectionStatusChannel.ConnectionEvent(
// false,
// "Successfully disconnected from Spotify.",
// null,
// null
// )
// )
// method success
result.success(true)
} else if (!spotifyAppRemote!!.isConnected) {
result.error(errorDisconnecting, "could not disconnect spotify remote", "you are not connected, no need to disconnect")
@ -212,16 +198,7 @@ class SpotifySdkService(private val context: Context? = null) {
}
}
private fun play(spotifyUri: String?){
// if (playerApi != null && !spotifyUri.isNullOrBlank()) {
// playerApi.play(spotifyUri)
// .setResultCallback { result.success(true) }
// .setErrorCallback { throwable -> result.error(errorPlay, "error when playing uri: $spotifyUri", throwable.toString()) }
// } else if (spotifyUri.isNullOrBlank()) {
// result.error(errorPlay, "spotifyUri has invalid format or is not set", "")
// } else {
// spotifyRemoteAppNotSetError()
// }
public fun play(spotifyUri: String?){
if (playerApi != null && !spotifyUri.isNullOrBlank()) {
playerApi!!.play(spotifyUri)
} else if (spotifyUri.isNullOrBlank()) {
@ -230,14 +207,8 @@ class SpotifySdkService(private val context: Context? = null) {
}
}
private fun pause(){
// if (playerApi != null) {
// playerApi.pause()
// .setResultCallback { result.success(true) }
// .setErrorCallback { throwable -> result.error(errorPause, "error when pausing", throwable.toString()) }
// } else {
// spotifyRemoteAppNotSetError()
// }
public fun pause(){
if (playerApi != null) {
playerApi!!.pause()
.setResultCallback {}

Loading…
Cancel
Save