Update Android icons and enter action
@@ -47,7 +47,7 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".QuickSendTileService"
|
android:name=".QuickSendTileService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@drawable/ic_quick_send_tile"
|
||||||
android:label="文本同步"
|
android:label="文本同步"
|
||||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -221,9 +221,27 @@ class ConnectionService : Service() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sendAction(socket, "replaceAll", text)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sendEnter(): Boolean {
|
||||||
|
Log.d("WTS", "ConnectionService.sendEnter connected=${state.connected}")
|
||||||
|
val socket = currentSocket ?: return false
|
||||||
|
if (!state.connected) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return sendAction(socket, "enter", null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendAction(socket: WebSocket, action: String, text: String?): Boolean {
|
||||||
val payload = JSONObject()
|
val payload = JSONObject()
|
||||||
.put("action", "replaceAll")
|
.put("action", action)
|
||||||
.put("text", text)
|
.apply {
|
||||||
|
if (text != null) {
|
||||||
|
put("text", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
.toString()
|
.toString()
|
||||||
return socket.send(payload)
|
return socket.send(payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ class MainActivity : FlutterActivity() {
|
|||||||
Log.d(tag, "MethodChannel sendText length=${text.length}")
|
Log.d(tag, "MethodChannel sendText length=${text.length}")
|
||||||
result.success(ConnectionService.sendText(text))
|
result.success(ConnectionService.sendText(text))
|
||||||
}
|
}
|
||||||
|
"sendEnter" -> {
|
||||||
|
Log.d(tag, "MethodChannel sendEnter")
|
||||||
|
result.success(ConnectionService.sendEnter())
|
||||||
|
}
|
||||||
"getState" -> {
|
"getState" -> {
|
||||||
Log.d(tag, "MethodChannel getState")
|
Log.d(tag, "MethodChannel getState")
|
||||||
result.success(ConnectionService.stateMap())
|
result.success(ConnectionService.stateMap())
|
||||||
|
|||||||
BIN
android/app/src/main/res/drawable-nodpi/app_icon_source.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
android/app/src/main/res/drawable-nodpi/ic_quick_send_tile.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 34 KiB |
@@ -123,6 +123,11 @@ class NativeConnectionApi {
|
|||||||
return result ?? false;
|
return result ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> sendEnter() async {
|
||||||
|
final result = await _methodChannel.invokeMethod<bool>('sendEnter');
|
||||||
|
return result ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<DiscoveredDevice>> startDiscovery() async {
|
Future<List<DiscoveredDevice>> startDiscovery() async {
|
||||||
try {
|
try {
|
||||||
final result = await _methodChannel.invokeListMethod<dynamic>(
|
final result = await _methodChannel.invokeListMethod<dynamic>(
|
||||||
@@ -341,15 +346,14 @@ class _InputSyncPageState extends State<InputSyncPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
final draft = inputController.text;
|
final draft = inputController.text;
|
||||||
final textToSend = appendEnter ? '$draft\n' : draft;
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
sendButtonState = SendButtonState.sending;
|
sendButtonState = SendButtonState.sending;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final sent = await api.sendText(textToSend);
|
final sent = await api.sendText(draft);
|
||||||
if (!sent) {
|
final enterSent = !sent || !appendEnter ? true : await api.sendEnter();
|
||||||
|
if (!sent || !enterSent) {
|
||||||
_showToast('发送失败,连接已断开');
|
_showToast('发送失败,连接已断开');
|
||||||
setState(() {
|
setState(() {
|
||||||
sendButtonState = SendButtonState.idle;
|
sendButtonState = SendButtonState.idle;
|
||||||
|
|||||||