mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-02 17:07:41 +08:00
新增:主动控制
增加远程WOL
功能(用于远程唤醒同一个局域网其他设备) #190
This commit is contained in:
parent
c53c3de118
commit
230957b731
@ -114,13 +114,6 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
|
||||
msgMap["sign"] = HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString())
|
||||
}
|
||||
|
||||
val ip = binding!!.etIp.text.toString()
|
||||
val ipRegex = getString(R.string.ip_regex).toRegex()
|
||||
if (!ipRegex.matches(ip)) {
|
||||
XToastUtils.error(ResUtils.getString(R.string.ip_error))
|
||||
return
|
||||
}
|
||||
|
||||
val mac = binding!!.etMac.text.toString()
|
||||
val macRegex = getString(R.string.mac_regex).toRegex()
|
||||
if (!macRegex.matches(mac)) {
|
||||
@ -128,6 +121,13 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
|
||||
return
|
||||
}
|
||||
|
||||
val ip = binding!!.etIp.text.toString()
|
||||
val ipRegex = getString(R.string.ip_regex).toRegex()
|
||||
if (!TextUtils.isEmpty(ip) && !ipRegex.matches(ip)) {
|
||||
XToastUtils.error(ResUtils.getString(R.string.ip_error))
|
||||
return
|
||||
}
|
||||
|
||||
val dataMap: MutableMap<String, Any> = mutableMapOf()
|
||||
dataMap["ip"] = ip
|
||||
dataMap["mac"] = mac
|
||||
@ -156,7 +156,7 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
|
||||
if (resp.code == 200) {
|
||||
XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
|
||||
//添加到历史记录
|
||||
wolHistory[ip] = mac
|
||||
wolHistory[mac] = ip
|
||||
HttpServerUtils.wolHistory = Gson().toJson(wolHistory)
|
||||
} else {
|
||||
XToastUtils.error(ResUtils.getString(R.string.request_failed) + resp.msg)
|
||||
|
@ -5,6 +5,7 @@ import android.os.StrictMode.ThreadPolicy
|
||||
import android.util.Log
|
||||
import com.idormy.sms.forwarder.server.model.BaseRequest
|
||||
import com.idormy.sms.forwarder.server.model.WolData
|
||||
import com.xuexiang.xrouter.utils.TextUtils
|
||||
import com.yanzhenjie.andserver.annotation.*
|
||||
import java.net.DatagramPacket
|
||||
import java.net.DatagramSocket
|
||||
@ -38,8 +39,12 @@ class WolController {
|
||||
System.arraycopy(macBytes, 0, bytes, i, macBytes.size)
|
||||
i += macBytes.size
|
||||
}
|
||||
val address: InetAddress = InetAddress.getByName(wolData.ip)
|
||||
val packet = DatagramPacket(bytes, bytes.size, address, 9)
|
||||
val packet = if (TextUtils.isEmpty(wolData.ip)) {
|
||||
val address: InetAddress = InetAddress.getByName(wolData.ip)
|
||||
DatagramPacket(bytes, bytes.size, address, 9)
|
||||
} else {
|
||||
DatagramPacket(bytes, bytes.size)
|
||||
}
|
||||
socket.send(packet)
|
||||
Log.d(TAG, "Wake-on-LAN packet sent.")
|
||||
} catch (e: Exception) {
|
||||
|
@ -4,8 +4,8 @@ import com.google.gson.annotations.SerializedName
|
||||
import java.io.Serializable
|
||||
|
||||
data class WolData(
|
||||
@SerializedName("ip")
|
||||
var ip: String,
|
||||
@SerializedName("mac")
|
||||
var mac: String,
|
||||
@SerializedName("ip")
|
||||
var ip: String = "",
|
||||
) : Serializable
|
@ -36,17 +36,17 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/ip" />
|
||||
android:text="@string/mac" />
|
||||
|
||||
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
|
||||
android:id="@+id/et_ip"
|
||||
android:id="@+id/et_mac"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/ip_hint"
|
||||
android:hint="@string/mac_hint"
|
||||
android:singleLine="true"
|
||||
app:met_clearButton="true"
|
||||
app:met_errorMessage="@string/ip_error"
|
||||
app:met_regexp="@string/ip_regex"
|
||||
app:met_errorMessage="@string/mac_error"
|
||||
app:met_regexp="@string/mac_regex"
|
||||
app:met_validateOnFocusLost="true" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -60,17 +60,17 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/mac" />
|
||||
android:text="@string/ip" />
|
||||
|
||||
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
|
||||
android:id="@+id/et_mac"
|
||||
android:id="@+id/et_ip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/mac_hint"
|
||||
android:hint="@string/ip_hint"
|
||||
android:singleLine="true"
|
||||
app:met_clearButton="true"
|
||||
app:met_errorMessage="@string/mac_error"
|
||||
app:met_regexp="@string/mac_regex"
|
||||
app:met_errorMessage="@string/ip_error"
|
||||
app:met_regexp="@string/ip_regex"
|
||||
app:met_validateOnFocusLost="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user