Commit c6958474 authored by Mygod's avatar Mygod

Remove package object

parent 4a1f6fea
...@@ -232,7 +232,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener { ...@@ -232,7 +232,7 @@ class AppManager extends AppCompatActivity with OnMenuItemClickListener {
def reloadApps() = if (!appsLoading.compareAndSet(true, false)) loadAppsAsync() def reloadApps() = if (!appsLoading.compareAndSet(true, false)) loadAppsAsync()
def loadAppsAsync() { def loadAppsAsync() {
if (!appsLoading.compareAndSet(false, true)) return if (!appsLoading.compareAndSet(false, true)) return
ThrowableFuture { Utils.ThrowableFuture {
var adapter: AppsAdapter = null var adapter: AppsAdapter = null
do { do {
appsLoading.set(true) appsLoading.set(true)
......
...@@ -336,7 +336,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -336,7 +336,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
} }
def prepareStartService() { def prepareStartService() {
ThrowableFuture { Utils.ThrowableFuture {
if (ShadowsocksApplication.isVpnEnabled) { if (ShadowsocksApplication.isVpnEnabled) {
val intent = VpnService.prepare(this) val intent = VpnService.prepare(this)
if (intent != null) { if (intent != null) {
...@@ -381,7 +381,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -381,7 +381,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
handler.post(() => connectionTestText.setText(R.string.connection_test_testing)) handler.post(() => connectionTestText.setText(R.string.connection_test_testing))
testCount testCount
} }
ThrowableFuture { Utils.ThrowableFuture {
// Based on: https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/connectivity/NetworkMonitor.java#640 // 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() autoDisconnect(new URL("https", "www.google.com", "/generate_204").openConnection()
.asInstanceOf[HttpURLConnection]) { conn => .asInstanceOf[HttpURLConnection]) { conn =>
...@@ -562,7 +562,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -562,7 +562,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
def recovery() { def recovery() {
if (serviceStarted) serviceStop() if (serviceStarted) serviceStop()
val h = showProgress(R.string.recovering) val h = showProgress(R.string.recovering)
ThrowableFuture { Utils.ThrowableFuture {
reset() reset()
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
} }
...@@ -570,7 +570,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -570,7 +570,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
def flushDnsCache() { def flushDnsCache() {
val h = showProgress(R.string.flushing) val h = showProgress(R.string.flushing)
ThrowableFuture { Utils.ThrowableFuture {
if (!Utils.toggleAirplaneMode(getBaseContext)) h.post(() => Snackbar.make(findViewById(android.R.id.content), if (!Utils.toggleAirplaneMode(getBaseContext)) h.post(() => Snackbar.make(findViewById(android.R.id.content),
R.string.flush_dnscache_no_root, Snackbar.LENGTH_LONG).show) R.string.flush_dnscache_no_root, Snackbar.LENGTH_LONG).show)
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
......
...@@ -359,7 +359,7 @@ class ShadowsocksNatService extends BaseService { ...@@ -359,7 +359,7 @@ class ShadowsocksNatService extends BaseService {
changeState(State.CONNECTING) changeState(State.CONNECTING)
ThrowableFuture { Utils.ThrowableFuture {
if (config.proxy == "198.199.101.152") { if (config.proxy == "198.199.101.152") {
val holder = ShadowsocksApplication.containerHolder val holder = ShadowsocksApplication.containerHolder
try { try {
......
...@@ -150,7 +150,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -150,7 +150,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
changeState(State.CONNECTING) changeState(State.CONNECTING)
ThrowableFuture { Utils.ThrowableFuture {
if (config.proxy == "198.199.101.152") { if (config.proxy == "198.199.101.152") {
val holder = ShadowsocksApplication.containerHolder val holder = ShadowsocksApplication.containerHolder
try { try {
......
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
}
...@@ -54,6 +54,9 @@ import android.widget.Toast ...@@ -54,6 +54,9 @@ import android.widget.Toast
import com.github.shadowsocks.{BuildConfig, ShadowsocksApplication, ShadowsocksRunnerService} import com.github.shadowsocks.{BuildConfig, ShadowsocksApplication, ShadowsocksRunnerService}
import org.xbill.DNS._ import org.xbill.DNS._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.util.{Failure, Try}
object Utils { object Utils {
...@@ -237,4 +240,11 @@ object Utils { ...@@ -237,4 +240,11 @@ object Utils {
val intent = new Intent(Action.CLOSE) val intent = new Intent(Action.CLOSE)
context.sendBroadcast(intent) context.sendBroadcast(intent)
} }
private val handleFailure: Try[_] => Unit = {
case Failure(e) => e.printStackTrace()
case _ =>
}
def ThrowableFuture[T](f: => T) = Future(f) onComplete handleFailure
} }
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