Commit 33ed5c65 authored by Max Lv's avatar Max Lv

fix #279

parent 1424e056
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
<string name="stopping">正在关闭...</string> <string name="stopping">正在关闭...</string>
<string name="vpn_error">后台服务启动失败:%s</string> <string name="vpn_error">后台服务启动失败:%s</string>
<string name="ok_iknow">确定</string> <string name="ok_iknow">确定</string>
<string name="port_alert">端口号应大于1024</string> <string name="port_alert">本地端口号应大于1024</string>
<string name="port_empty">端口号不能为空</string> <string name="port_empty">端口号不能为空</string>
<string name="proxy_empty">代理服务器地址不能为空</string> <string name="proxy_empty">代理服务器地址不能为空</string>
<string name="crash_alert">检测到意外退出,状态已被重置。</string> <string name="crash_alert">检测到意外退出,状态已被重置。</string>
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<!-- alert category --> <!-- alert category -->
<string name="ok_iknow">OK</string> <string name="ok_iknow">OK</string>
<string name="port_alert">The port number should be greater than 1024</string> <string name="port_alert">The local port number should be greater than 1024</string>
<string name="port_empty">Port should not be empty</string> <string name="port_empty">Port should not be empty</string>
<string name="proxy_empty">Proxy should not be empty</string> <string name="proxy_empty">Proxy should not be empty</string>
<string name="crash_alert">An unexpected exit detected, the context has been reset. <string name="crash_alert">An unexpected exit detected, the context has been reset.
......
...@@ -366,19 +366,29 @@ class Shadowsocks ...@@ -366,19 +366,29 @@ class Shadowsocks
def isTextEmpty(s: String, msg: String): Boolean = { def isTextEmpty(s: String, msg: String): Boolean = {
if (s == null || s.length <= 0) { if (s == null || s.length <= 0) {
new SnackBar.Builder(this).withMessage(msg).withStyle(SnackBar.Style.ALERT).show() new SnackBar.Builder(this)
.withMessage(msg)
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
return true return true
} }
false false
} }
def cancelStart() { def cancelStart() {
handler.postDelayed(new Runnable { clearDialog()
override def run() { changeSwitch(checked = false)
clearDialog() }
changeSwitch(checked = false)
} def isReady(): Boolean = {
}, 1000) if (!checkText(Key.proxy)) return false
if (!checkText(Key.sitekey)) return false
if (!checkNumber(Key.localPort, low = false)) return false
if (!checkNumber(Key.remotePort, low = true)) return false
if (bgService == null) return false
true
} }
def prepareStartService() { def prepareStartService() {
...@@ -392,9 +402,7 @@ class Shadowsocks ...@@ -392,9 +402,7 @@ class Shadowsocks
onActivityResult(Shadowsocks.REQUEST_CONNECT, Activity.RESULT_OK, null) onActivityResult(Shadowsocks.REQUEST_CONNECT, Activity.RESULT_OK, null)
} }
} else { } else {
if (!serviceStart) { serviceStart()
cancelStart()
}
} }
} }
} }
...@@ -403,7 +411,10 @@ class Shadowsocks ...@@ -403,7 +411,10 @@ class Shadowsocks
if (compoundButton eq switchButton) { if (compoundButton eq switchButton) {
checked match { checked match {
case true => case true =>
prepareStartService() if (isReady)
prepareStartService()
else
changeSwitch(checked = false)
case false => case false =>
serviceStop() serviceStop()
} }
...@@ -889,9 +900,7 @@ class Shadowsocks ...@@ -889,9 +900,7 @@ class Shadowsocks
resultCode match { resultCode match {
case Activity.RESULT_OK => case Activity.RESULT_OK =>
prepared = true prepared = true
if (!serviceStart) { serviceStart()
cancelStart()
}
case _ => case _ =>
cancelStart() cancelStart()
Log.e(Shadowsocks.TAG, "Failed to start VpnService") Log.e(Shadowsocks.TAG, "Failed to start VpnService")
...@@ -925,33 +934,34 @@ class Shadowsocks ...@@ -925,33 +934,34 @@ class Shadowsocks
try { try {
val port: Int = Integer.valueOf(text) val port: Int = Integer.valueOf(text)
if (!low && port <= 1024) { if (!low && port <= 1024) {
new SnackBar.Builder(this).withMessageId(R.string.port_alert).withStyle(SnackBar.Style.ALERT).show() new SnackBar.Builder(this)
.withMessageId(R.string.port_alert)
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
return false return false
} }
} catch { } catch {
case ex: Exception => case ex: Exception =>
new SnackBar.Builder(this).withMessageId(R.string.port_alert).withStyle(SnackBar.Style.ALERT).show() new SnackBar.Builder(this)
.withMessageId(R.string.port_alert)
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
return false return false
} }
true true
} }
/** Called when connect button is clicked. */ /** Called when connect button is clicked. */
def serviceStart: Boolean = { def serviceStart() {
if (!checkText(Key.proxy)) return false
if (!checkText(Key.sitekey)) return false
if (!checkNumber(Key.localPort, low = false)) return false
if (!checkNumber(Key.remotePort, low = true)) return false
if (bgService == null) return false
bgService.start(ConfigUtils.load(settings)) bgService.start(ConfigUtils.load(settings))
if (isVpnEnabled) { if (isVpnEnabled) {
changeSwitch(checked = false) changeSwitch(checked = false)
} }
true
} }
private def showAbout() { private def showAbout() {
......
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