Commit 5b3d472d authored by Mygod's avatar Mygod

Refine code style

parent 56fc89f1
......@@ -92,22 +92,22 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
GlobalScope.launch(Dispatchers.Main) { onFatal(e) }
} finally {
abortChannel.close()
if (!running) return // process already exited, nothing to be done
if (Build.VERSION.SDK_INT < 24) {
try {
Os.kill(pid.get(process) as Int, OsConstants.SIGTERM)
} catch (e: ErrnoException) {
if (e.errno != OsConstants.ESRCH) throw e
}
if (withTimeoutOrNull(500) { exitChannel.receive() } != null) return
}
process.destroy() // kill the process
if (Build.VERSION.SDK_INT >= 26) {
if (withTimeoutOrNull(1000) { exitChannel.receive() } != null) return
process.destroyForcibly() // Force to kill the process if it's still alive
}
if (!running) return // process already exited, nothing to be done
if (Build.VERSION.SDK_INT < 24) {
try {
Os.kill(pid.get(process) as Int, OsConstants.SIGTERM)
} catch (e: ErrnoException) {
if (e.errno != OsConstants.ESRCH) throw e
}
exitChannel.receive()
if (withTimeoutOrNull(500) { exitChannel.receive() } != null) return
}
process.destroy() // kill the process
if (Build.VERSION.SDK_INT >= 26) {
if (withTimeoutOrNull(1000) { exitChannel.receive() } != null) return
process.destroyForcibly() // Force to kill the process if it's still alive
}
exitChannel.receive()
}
}
......
......@@ -64,7 +64,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
withTimeout(30_000) {
withContext(Dispatchers.IO) {
conn.outputStream.bufferedWriter().use {
it.write("sig=" + String(Base64.encode(mdg.digest(), Base64.DEFAULT)))
it.write("sig=" + Base64.encodeToString(mdg.digest(), Base64.DEFAULT))
}
conn.inputStream.bufferedReader().readText()
}
......
......@@ -238,7 +238,7 @@ class Profile : Serializable {
val builder = Uri.Builder()
.scheme("ss")
.encodedAuthority("%s@%s:%d".format(Locale.ENGLISH,
Base64.encodeToString("%s:%s".format(Locale.ENGLISH, method, password).toByteArray(),
Base64.encodeToString("$method:$password".toByteArray(),
Base64.NO_PADDING or Base64.NO_WRAP or Base64.URL_SAFE),
if (host.contains(':')) "[$host]" else host, remotePort))
val configuration = PluginConfiguration(plugin ?: "")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment