From 32828a6ee9cd4dc6ebfcecdd6e1c45e2e41cdb16 Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Mon, 2 Dec 2019 00:21:36 +0800 Subject: [PATCH] fix load profile return nil invalid selected --- core/src/main/golang/server/profile.go | 2 ++ core/src/main/java/com/github/kr328/clash/core/Clash.kt | 7 ++----- .../java/com/github/kr328/clash/service/ClashService.kt | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/golang/server/profile.go b/core/src/main/golang/server/profile.go index 0c45dc0..172ab13 100644 --- a/core/src/main/golang/server/profile.go +++ b/core/src/main/golang/server/profile.go @@ -33,6 +33,8 @@ func handleProfileReload(client *net.UnixConn) { InvalidSelected []string `json:"invalidSelected"` } + response.InvalidSelected = make([]string, 0) + defer func() { buf, _ := json.Marshal(&response) diff --git a/core/src/main/java/com/github/kr328/clash/core/Clash.kt b/core/src/main/java/com/github/kr328/clash/core/Clash.kt index e0dfbf2..abfe09b 100644 --- a/core/src/main/java/com/github/kr328/clash/core/Clash.kt +++ b/core/src/main/java/com/github/kr328/clash/core/Clash.kt @@ -2,8 +2,6 @@ package com.github.kr328.clash.core import android.content.Context import android.net.LocalSocket -import android.util.Log -import com.github.kr328.clash.core.Constants.TAG import com.github.kr328.clash.core.event.BandwidthEvent import com.github.kr328.clash.core.event.LogEvent import com.github.kr328.clash.core.event.ProcessEvent @@ -11,9 +9,9 @@ import com.github.kr328.clash.core.event.SpeedEvent import com.github.kr328.clash.core.model.LoadProfilePacket import com.github.kr328.clash.core.model.RawProxyPacket import com.github.kr328.clash.core.model.SetProxyPacket +import com.github.kr328.clash.core.utils.Log import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration -import org.json.JSONObject import java.io.File import java.io.FileDescriptor import java.io.IOException @@ -53,8 +51,7 @@ class Clash( LoadProfilePacket.Request(file.absolutePath, selected))) val result = Json(JsonConfiguration.Stable) - .parse(LoadProfilePacket.Response.serializer(), - input.readString()) + .parse(LoadProfilePacket.Response.serializer(), input.readString()) if (result.error.isNotEmpty()) { throw IOException(result.error) diff --git a/service/src/main/java/com/github/kr328/clash/service/ClashService.kt b/service/src/main/java/com/github/kr328/clash/service/ClashService.kt index c789962..be7c61d 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ClashService.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ClashService.kt @@ -244,7 +244,7 @@ class ClashService : Service(), IClashEventObserver, ClashEventService.Master, profileService.removeCurrentProfileProxy(remove) notification.setProfile(active.name) - } catch (e: IOException) { + } catch (e: Exception) { clash.process.stop() Log.w("Load profile failure", e) }