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

fix #279

parent 1424e056
......@@ -49,7 +49,7 @@
<string name="stopping">正在关闭...</string>
<string name="vpn_error">后台服务启动失败:%s</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="proxy_empty">代理服务器地址不能为空</string>
<string name="crash_alert">检测到意外退出,状态已被重置。</string>
......
......@@ -65,7 +65,7 @@
<!-- alert category -->
<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="proxy_empty">Proxy should not be empty</string>
<string name="crash_alert">An unexpected exit detected, the context has been reset.
......
......@@ -366,19 +366,29 @@ class Shadowsocks
def isTextEmpty(s: String, msg: String): Boolean = {
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
}
false
}
def cancelStart() {
handler.postDelayed(new Runnable {
override def run() {
clearDialog()
changeSwitch(checked = false)
}
}, 1000)
clearDialog()
changeSwitch(checked = false)
}
def isReady(): Boolean = {
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() {
......@@ -392,9 +402,7 @@ class Shadowsocks
onActivityResult(Shadowsocks.REQUEST_CONNECT, Activity.RESULT_OK, null)
}
} else {
if (!serviceStart) {
cancelStart()
}
serviceStart()
}
}
}
......@@ -403,7 +411,10 @@ class Shadowsocks
if (compoundButton eq switchButton) {
checked match {
case true =>
prepareStartService()
if (isReady)
prepareStartService()
else
changeSwitch(checked = false)
case false =>
serviceStop()
}
......@@ -889,9 +900,7 @@ class Shadowsocks
resultCode match {
case Activity.RESULT_OK =>
prepared = true
if (!serviceStart) {
cancelStart()
}
serviceStart()
case _ =>
cancelStart()
Log.e(Shadowsocks.TAG, "Failed to start VpnService")
......@@ -925,33 +934,34 @@ class Shadowsocks
try {
val port: Int = Integer.valueOf(text)
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
}
} catch {
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
}
true
}
/** Called when connect button is clicked. */
def serviceStart: Boolean = {
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
def serviceStart() {
bgService.start(ConfigUtils.load(settings))
if (isVpnEnabled) {
changeSwitch(checked = false)
}
true
}
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