diff --git a/src/main/scala/com/github/shadowsocks/AppManager.scala b/src/main/scala/com/github/shadowsocks/AppManager.scala index 73056f28..eb64d29d 100644 --- a/src/main/scala/com/github/shadowsocks/AppManager.scala +++ b/src/main/scala/com/github/shadowsocks/AppManager.scala @@ -232,7 +232,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { def reloadApps() = if (!appsLoading.compareAndSet(true, false)) loadAppsAsync() def loadAppsAsync() { if (!appsLoading.compareAndSet(false, true)) return - ThrowableFuture { + Utils.ThrowableFuture { var adapter: AppsAdapter = null do { appsLoading.set(true) diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index 60dff12d..18598513 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -336,7 +336,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { } def prepareStartService() { - ThrowableFuture { + Utils.ThrowableFuture { if (ShadowsocksApplication.isVpnEnabled) { val intent = VpnService.prepare(this) if (intent != null) { @@ -381,7 +381,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { handler.post(() => connectionTestText.setText(R.string.connection_test_testing)) testCount } - ThrowableFuture { + Utils.ThrowableFuture { // Based on: https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/connectivity/NetworkMonitor.java#640 autoDisconnect(new URL("https", "www.google.com", "/generate_204").openConnection() .asInstanceOf[HttpURLConnection]) { conn => @@ -562,7 +562,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { def recovery() { if (serviceStarted) serviceStop() val h = showProgress(R.string.recovering) - ThrowableFuture { + Utils.ThrowableFuture { reset() h.sendEmptyMessage(0) } @@ -570,7 +570,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { def flushDnsCache() { val h = showProgress(R.string.flushing) - ThrowableFuture { + Utils.ThrowableFuture { if (!Utils.toggleAirplaneMode(getBaseContext)) h.post(() => Snackbar.make(findViewById(android.R.id.content), R.string.flush_dnscache_no_root, Snackbar.LENGTH_LONG).show) h.sendEmptyMessage(0) diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala index 339e65c8..5e91267f 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala @@ -359,7 +359,7 @@ class ShadowsocksNatService extends BaseService { changeState(State.CONNECTING) - ThrowableFuture { + Utils.ThrowableFuture { if (config.proxy == "198.199.101.152") { val holder = ShadowsocksApplication.containerHolder try { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index 821de50c..bdacacfa 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -150,7 +150,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { changeState(State.CONNECTING) - ThrowableFuture { + Utils.ThrowableFuture { if (config.proxy == "198.199.101.152") { val holder = ShadowsocksApplication.containerHolder try { diff --git a/src/main/scala/com/github/shadowsocks/package.scala b/src/main/scala/com/github/shadowsocks/package.scala deleted file mode 100644 index a934b4c8..00000000 --- a/src/main/scala/com/github/shadowsocks/package.scala +++ /dev/null @@ -1,17 +0,0 @@ -package com.github - -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future -import scala.util.{Failure, Try} - -/** - * @author Mygod - */ -package object shadowsocks { - private val handleFailure: Try[_] => Unit = { - case Failure(e) => e.printStackTrace() - case _ => - } - - def ThrowableFuture[T](f: => T) = Future(f) onComplete handleFailure -} diff --git a/src/main/scala/com/github/shadowsocks/utils/Utils.scala b/src/main/scala/com/github/shadowsocks/utils/Utils.scala index 1e115cd3..3b294514 100644 --- a/src/main/scala/com/github/shadowsocks/utils/Utils.scala +++ b/src/main/scala/com/github/shadowsocks/utils/Utils.scala @@ -54,6 +54,9 @@ import android.widget.Toast import com.github.shadowsocks.{BuildConfig, ShadowsocksApplication, ShadowsocksRunnerService} import org.xbill.DNS._ +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future +import scala.util.{Failure, Try} object Utils { @@ -237,4 +240,11 @@ object Utils { val intent = new Intent(Action.CLOSE) context.sendBroadcast(intent) } + + private val handleFailure: Try[_] => Unit = { + case Failure(e) => e.printStackTrace() + case _ => + } + + def ThrowableFuture[T](f: => T) = Future(f) onComplete handleFailure }