add android server chat and multi chat;update android server page
This commit is contained in:
parent
99b27b1fe4
commit
6ce7018f07
@ -46,7 +46,9 @@ class MainActivity : FlutterActivity() {
|
|||||||
when (call.method) {
|
when (call.method) {
|
||||||
"init_service" -> {
|
"init_service" -> {
|
||||||
Log.d(logTag, "event from flutter,getPer")
|
Log.d(logTag, "event from flutter,getPer")
|
||||||
|
if(mainService?.isReady == false){
|
||||||
getMediaProjection()
|
getMediaProjection()
|
||||||
|
}
|
||||||
result.success(true)
|
result.success(true)
|
||||||
}
|
}
|
||||||
"start_capture" -> {
|
"start_capture" -> {
|
||||||
|
@ -28,6 +28,8 @@ class App extends StatelessWidget {
|
|||||||
ChangeNotifierProvider.value(value: FFI.imageModel),
|
ChangeNotifierProvider.value(value: FFI.imageModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.cursorModel),
|
ChangeNotifierProvider.value(value: FFI.cursorModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.canvasModel),
|
ChangeNotifierProvider.value(value: FFI.canvasModel),
|
||||||
|
ChangeNotifierProvider.value(value: FFI.serverModel),
|
||||||
|
ChangeNotifierProvider.value(value: FFI.chatModel),
|
||||||
ChangeNotifierProvider.value(value: FFI.fileModel),
|
ChangeNotifierProvider.value(value: FFI.fileModel),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:dash_chat/dash_chat.dart';
|
import 'package:dash_chat/dash_chat.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/pages/chat_page.dart';
|
import 'package:flutter_hbb/pages/chat_page.dart';
|
||||||
@ -6,38 +8,64 @@ import 'model.dart';
|
|||||||
import 'native_model.dart';
|
import 'native_model.dart';
|
||||||
|
|
||||||
class ChatModel with ChangeNotifier {
|
class ChatModel with ChangeNotifier {
|
||||||
final List<ChatMessage> _messages = [];
|
// -1作为客户端模式的id,客户端模式下此id唯一
|
||||||
|
// 其它正整数的id,来自被控服务器模式下的其他客户端的id,每个客户端有不同的id
|
||||||
|
// 注意 此id和peer_id不同,服务端模式下的id等同于conn的顺序累加id
|
||||||
|
static final clientModeID = -1;
|
||||||
|
|
||||||
|
final Map<int, List<ChatMessage>> _messages = Map()..[clientModeID] = [];
|
||||||
|
|
||||||
final ChatUser me = ChatUser(
|
final ChatUser me = ChatUser(
|
||||||
name:"me",
|
uid:"",
|
||||||
|
name: "me",
|
||||||
|
customProperties: Map()..["id"] = clientModeID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var _currentID = clientModeID;
|
||||||
|
|
||||||
get messages => _messages;
|
get messages => _messages;
|
||||||
|
|
||||||
receive(String text){
|
get currentID => _currentID;
|
||||||
|
|
||||||
|
receive(int id, String text) {
|
||||||
if (text.isEmpty) return;
|
if (text.isEmpty) return;
|
||||||
// first message show overlay icon
|
// first message show overlay icon
|
||||||
if (iconOverlayEntry == null){
|
if (iconOverlayEntry == null) {
|
||||||
showChatIconOverlay();
|
showChatIconOverlay();
|
||||||
}
|
}
|
||||||
_messages.add(ChatMessage(text: text, user: ChatUser(
|
if(!_messages.containsKey(id)){
|
||||||
name:FFI.ffiModel.pi.username,
|
_messages[id] = [];
|
||||||
|
}
|
||||||
|
// TODO peer info
|
||||||
|
_messages[id]?.add(ChatMessage(
|
||||||
|
text: text,
|
||||||
|
user: ChatUser(
|
||||||
|
name: FFI.ffiModel.pi.username,
|
||||||
uid: FFI.getId(),
|
uid: FFI.getId(),
|
||||||
)));
|
)));
|
||||||
|
_currentID = id;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
send(ChatMessage message){
|
send(ChatMessage message) {
|
||||||
_messages.add(message);
|
if (message.text != null && message.text!.isNotEmpty) {
|
||||||
if(message.text != null && message.text!.isNotEmpty){
|
_messages[_currentID]?.add(message);
|
||||||
PlatformFFI.setByName("chat",message.text!);
|
if (_currentID == clientModeID) {
|
||||||
|
PlatformFFI.setByName("chat_client_mode", message.text!);
|
||||||
|
} else {
|
||||||
|
final msg = Map()
|
||||||
|
..["id"] = _currentID
|
||||||
|
..["text"] = message.text!;
|
||||||
|
PlatformFFI.setByName("chat_server_mode", jsonEncode(msg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
release(){
|
release() {
|
||||||
hideChatIconOverlay();
|
hideChatIconOverlay();
|
||||||
hideChatWindowOverlay();
|
hideChatWindowOverlay();
|
||||||
|
_messages.forEach((key, value) => value.clear());
|
||||||
_messages.clear();
|
_messages.clear();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -129,8 +129,10 @@ class FfiModel with ChangeNotifier {
|
|||||||
Clipboard.setData(ClipboardData(text: evt['content']));
|
Clipboard.setData(ClipboardData(text: evt['content']));
|
||||||
} else if (name == 'permission') {
|
} else if (name == 'permission') {
|
||||||
FFI.ffiModel.updatePermission(evt);
|
FFI.ffiModel.updatePermission(evt);
|
||||||
} else if (name == 'chat') {
|
} else if (name == 'chat_client_mode') {
|
||||||
FFI.chatModel.receive(evt['text'] ?? "");
|
FFI.chatModel.receive(ChatModel.clientModeID,evt['text'] ?? "");
|
||||||
|
} else if (name == 'chat_server_mode') {
|
||||||
|
FFI.chatModel.receive(int.parse(evt['id'] as String),evt['text'] ?? "");
|
||||||
} else if (name == 'file_dir') {
|
} else if (name == 'file_dir') {
|
||||||
FFI.fileModel.receiveFileDir(evt);
|
FFI.fileModel.receiveFileDir(evt);
|
||||||
} else if (name == 'job_progress') {
|
} else if (name == 'job_progress') {
|
||||||
|
@ -24,6 +24,7 @@ class PlatformFFI {
|
|||||||
static Pointer<RgbaFrame>? _lastRgbaFrame;
|
static Pointer<RgbaFrame>? _lastRgbaFrame;
|
||||||
static String _dir = '';
|
static String _dir = '';
|
||||||
static String _homeDir = '';
|
static String _homeDir = '';
|
||||||
|
static int? _androidVersion;
|
||||||
static F2? _getByName;
|
static F2? _getByName;
|
||||||
static F3? _setByName;
|
static F3? _setByName;
|
||||||
static F4? _freeRgba;
|
static F4? _freeRgba;
|
||||||
@ -48,6 +49,8 @@ class PlatformFFI {
|
|||||||
return packageInfo.version;
|
return packageInfo.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int? get androidVersion => _androidVersion;
|
||||||
|
|
||||||
static String getByName(String name, [String arg = '']) {
|
static String getByName(String name, [String arg = '']) {
|
||||||
if (_getByName == null) return '';
|
if (_getByName == null) return '';
|
||||||
var a = name.toNativeUtf8();
|
var a = name.toNativeUtf8();
|
||||||
@ -94,6 +97,7 @@ class PlatformFFI {
|
|||||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||||
name = '${androidInfo.brand}-${androidInfo.model}';
|
name = '${androidInfo.brand}-${androidInfo.model}';
|
||||||
id = androidInfo.id.hashCode.toString();
|
id = androidInfo.id.hashCode.toString();
|
||||||
|
_androidVersion = androidInfo.version.sdkInt;
|
||||||
} else {
|
} else {
|
||||||
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
||||||
name = iosInfo.utsname.machine;
|
name = iosInfo.utsname.machine;
|
||||||
|
@ -1,29 +1,144 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../pages/server_page.dart';
|
import '../pages/server_page.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
|
|
||||||
|
final _emptyIdShow = translate("connecting_status");
|
||||||
|
|
||||||
class ServerModel with ChangeNotifier {
|
class ServerModel with ChangeNotifier {
|
||||||
|
Timer? _interval;
|
||||||
|
bool _isStart = false;
|
||||||
bool _mediaOk = false;
|
bool _mediaOk = false;
|
||||||
bool _inputOk = false;
|
bool _inputOk = false;
|
||||||
|
late bool _fileOk;
|
||||||
|
final _serverId = TextEditingController(text: _emptyIdShow);
|
||||||
|
final _serverPasswd = TextEditingController(text: "");
|
||||||
|
|
||||||
List<Client> _clients = [];
|
List<Client> _clients = [];
|
||||||
|
|
||||||
|
bool get isStart => _isStart;
|
||||||
|
|
||||||
bool get mediaOk => _mediaOk;
|
bool get mediaOk => _mediaOk;
|
||||||
|
|
||||||
bool get inputOk => _inputOk;
|
bool get inputOk => _inputOk;
|
||||||
|
|
||||||
|
bool get fileOk => _fileOk;
|
||||||
|
|
||||||
|
TextEditingController get serverId => _serverId;
|
||||||
|
|
||||||
|
TextEditingController get serverPasswd => _serverPasswd;
|
||||||
|
|
||||||
List<Client> get clients => _clients;
|
List<Client> get clients => _clients;
|
||||||
|
|
||||||
ServerModel();
|
ServerModel() {
|
||||||
|
()async{
|
||||||
|
await Future.delayed(Duration(seconds: 2));
|
||||||
|
final file = FFI.getByName('option', 'enable-file-transfer');
|
||||||
|
debugPrint("got file in option:$file");
|
||||||
|
if (file.isEmpty) {
|
||||||
|
_fileOk = false;
|
||||||
|
Map<String, String> res = Map()
|
||||||
|
..["name"] = "enable-file-transfer"
|
||||||
|
..["value"] = "N";
|
||||||
|
FFI.setByName('option', jsonEncode(res)); // 重新设置默认值
|
||||||
|
} else {
|
||||||
|
if (file == "Y") {
|
||||||
|
_fileOk = true;
|
||||||
|
} else {
|
||||||
|
_fileOk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleFile() {
|
||||||
|
_fileOk = !_fileOk;
|
||||||
|
Map<String, String> res = Map()
|
||||||
|
..["name"] = "enable-file-transfer"
|
||||||
|
..["value"] = _fileOk ? 'Y' : 'N';
|
||||||
|
debugPrint("save option:$res");
|
||||||
|
FFI.setByName('option', jsonEncode(res));
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Null> startService() async {
|
||||||
|
_isStart = true;
|
||||||
|
notifyListeners();
|
||||||
|
FFI.setByName("ensure_init_event_queue");
|
||||||
|
_interval = Timer.periodic(Duration(milliseconds: 30), (timer) {
|
||||||
|
FFI.ffiModel.update("", (_, __) {});
|
||||||
|
});
|
||||||
|
await FFI.invokeMethod("init_service");
|
||||||
|
FFI.setByName("start_service");
|
||||||
|
getIDPasswd();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Null> stopService() async {
|
||||||
|
_isStart = false;
|
||||||
|
release();
|
||||||
|
FFI.serverModel.closeAll();
|
||||||
|
await FFI.invokeMethod("stop_service");
|
||||||
|
FFI.setByName("stop_service");
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Null> initInput() async {
|
||||||
|
await FFI.invokeMethod("init_input");
|
||||||
|
}
|
||||||
|
|
||||||
|
getIDPasswd() async {
|
||||||
|
if (_serverId.text != _emptyIdShow && _serverPasswd.text != "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var count = 0;
|
||||||
|
const maxCount = 10;
|
||||||
|
while (count < maxCount) {
|
||||||
|
await Future.delayed(Duration(seconds: 1));
|
||||||
|
final id = FFI.getByName("server_id");
|
||||||
|
final passwd = FFI.getByName("server_password");
|
||||||
|
if (id.isEmpty) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
_serverId.text = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passwd.isEmpty) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
_serverPasswd.text = passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
debugPrint(
|
||||||
|
"fetch id & passwd again at $count:id:${_serverId.text},passwd:${_serverPasswd.text}");
|
||||||
|
count++;
|
||||||
|
if (_serverId.text != _emptyIdShow && _serverPasswd.text.isNotEmpty) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
release() {
|
||||||
|
_interval?.cancel();
|
||||||
|
_interval = null;
|
||||||
|
}
|
||||||
|
|
||||||
changeStatue(String name, bool value) {
|
changeStatue(String name, bool value) {
|
||||||
|
debugPrint("changeStatue value $value");
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "media":
|
case "media":
|
||||||
_mediaOk = value;
|
_mediaOk = value;
|
||||||
|
debugPrint("value $value,_isStart:$_isStart");
|
||||||
|
if(value && !_isStart){
|
||||||
|
startService();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "input":
|
case "input":
|
||||||
_inputOk = value;
|
_inputOk = value;
|
||||||
|
//TODO change option
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -36,16 +151,18 @@ class ServerModel with ChangeNotifier {
|
|||||||
debugPrint("getByName clients_state string:$res");
|
debugPrint("getByName clients_state string:$res");
|
||||||
try {
|
try {
|
||||||
final List clientsJson = jsonDecode(res);
|
final List clientsJson = jsonDecode(res);
|
||||||
_clients = clientsJson.map((clientJson) => Client.fromJson(jsonDecode(res))).toList();
|
_clients = clientsJson
|
||||||
|
.map((clientJson) => Client.fromJson(jsonDecode(res)))
|
||||||
|
.toList();
|
||||||
debugPrint("updateClientState:${_clients.toString()}");
|
debugPrint("updateClientState:${_clients.toString()}");
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
loginRequest(Map<String, dynamic> evt){
|
loginRequest(Map<String, dynamic> evt) {
|
||||||
try{
|
try {
|
||||||
final client = Client.fromJson(jsonDecode(evt["client"]));
|
final client = Client.fromJson(jsonDecode(evt["client"]));
|
||||||
final Map<String,dynamic> response = Map();
|
final Map<String, dynamic> response = Map();
|
||||||
response["id"] = client.id;
|
response["id"] = client.id;
|
||||||
DialogManager.show((setState, close) => CustomAlertDialog(
|
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||||
title: Text("Control Request"),
|
title: Text("Control Request"),
|
||||||
@ -73,39 +190,38 @@ class ServerModel with ChangeNotifier {
|
|||||||
response["res"] = true;
|
response["res"] = true;
|
||||||
FFI.setByName("login_res", jsonEncode(response));
|
FFI.setByName("login_res", jsonEncode(response));
|
||||||
if (!client.isFileTransfer) {
|
if (!client.isFileTransfer) {
|
||||||
bool res = await FFI.invokeMethod("start_capture"); // to Android service
|
bool res = await FFI.invokeMethod(
|
||||||
|
"start_capture"); // to Android service
|
||||||
debugPrint("_toAndroidStartCapture:$res");
|
debugPrint("_toAndroidStartCapture:$res");
|
||||||
}
|
}
|
||||||
_clients.add(client);
|
_clients.add(client);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
close();
|
close();
|
||||||
}),
|
}),
|
||||||
|
|
||||||
]));
|
]));
|
||||||
}catch (e){
|
} catch (e) {
|
||||||
debugPrint("loginRequest failed,error:$e");
|
debugPrint("loginRequest failed,error:$e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onClientLogin(Map<String, dynamic> evt){
|
void onClientLogin(Map<String, dynamic> evt) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void onClientRemove(Map<String, dynamic> evt) {
|
void onClientRemove(Map<String, dynamic> evt) {
|
||||||
try{
|
try {
|
||||||
final id = int.parse(evt['id'] as String);
|
final id = int.parse(evt['id'] as String);
|
||||||
Client client = _clients.singleWhere((c) => c.id == id);
|
Client client = _clients.singleWhere((c) => c.id == id);
|
||||||
_clients.remove(client);
|
_clients.remove(client);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
debugPrint("onClientRemove failed,error:$e");
|
debugPrint("onClientRemove failed,error:$e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeAll(){
|
closeAll() {
|
||||||
_clients.forEach((client) {
|
_clients.forEach((client) {
|
||||||
FFI.setByName("close_conn",client.id.toString());
|
FFI.setByName("close_conn", client.id.toString());
|
||||||
});
|
});
|
||||||
|
_clients = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,4 +252,3 @@ class Client {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,7 @@ class ChatPage extends StatelessWidget implements PageShape {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider.value(
|
return Container(
|
||||||
value: FFI.chatModel,
|
|
||||||
child: Container(
|
|
||||||
color: MyTheme.grayBg,
|
color: MyTheme.grayBg,
|
||||||
child: Consumer<ChatModel>(builder: (context, chatModel, child) {
|
child: Consumer<ChatModel>(builder: (context, chatModel, child) {
|
||||||
return DashChat(
|
return DashChat(
|
||||||
@ -38,9 +36,9 @@ class ChatPage extends StatelessWidget implements PageShape {
|
|||||||
chatModel.send(chatMsg);
|
chatModel.send(chatMsg);
|
||||||
},
|
},
|
||||||
user: chatModel.me,
|
user: chatModel.me,
|
||||||
messages: chatModel.messages,
|
messages: chatModel.messages[chatModel.currentID],
|
||||||
);
|
);
|
||||||
})));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,11 @@ class _HomePageState extends State<HomePage> {
|
|||||||
selectedItemColor: MyTheme.accent,
|
selectedItemColor: MyTheme.accent,
|
||||||
unselectedItemColor: MyTheme.darkGray,
|
unselectedItemColor: MyTheme.darkGray,
|
||||||
onTap: (index) => setState(() {
|
onTap: (index) => setState(() {
|
||||||
|
// close chat overlay when go chat page
|
||||||
|
if(index == 1 && _selectedIndex!=index){
|
||||||
|
hideChatIconOverlay();
|
||||||
|
hideChatWindowOverlay();
|
||||||
|
}
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
@ -456,7 +456,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
final keyboard = FFI.ffiModel.permissions['keyboard'] != false;
|
final keyboard = FFI.ffiModel.permissions['keyboard'] != false;
|
||||||
var paints = <Widget>[ImagePaint()];
|
var paints = <Widget>[ImagePaint()];
|
||||||
if (keyboard ||
|
if (keyboard ||
|
||||||
FFI.getByName('toggle-option', 'show-remote-cursor') == 'true') {
|
FFI.getByName('toggle_option', 'show-remote-cursor') == 'true') {
|
||||||
paints.add(CursorPaint());
|
paints.add(CursorPaint());
|
||||||
}
|
}
|
||||||
return MouseRegion(
|
return MouseRegion(
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import 'dart:async';
|
import 'package:device_info/device_info.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/models/model.dart';
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
|
import '../models/native_model.dart';
|
||||||
import '../models/server_model.dart';
|
import '../models/server_model.dart';
|
||||||
import 'home_page.dart';
|
import 'home_page.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
@ -38,9 +39,8 @@ class ServerPage extends StatelessWidget implements PageShape {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
checkService();
|
checkService();
|
||||||
return ChangeNotifierProvider.value(
|
return Consumer<ServerModel>(
|
||||||
value: FFI.serverModel,
|
builder: (context, serverModel, child) => SingleChildScrollView(
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -52,15 +52,13 @@ class ServerPage extends StatelessWidget implements PageShape {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkService() {
|
void checkService() {
|
||||||
// 检测当前服务状态,若已存在服务则异步更新数据回来
|
// 检测当前服务状态,若已存在服务则异步更新数据回来
|
||||||
FFI.invokeMethod("check_service"); // jvm
|
FFI.invokeMethod("check_service"); // jvm
|
||||||
FFI.serverModel.updateClientState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServerInfo extends StatefulWidget {
|
class ServerInfo extends StatefulWidget {
|
||||||
@ -69,41 +67,14 @@ class ServerInfo extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ServerInfoState extends State<ServerInfo> {
|
class _ServerInfoState extends State<ServerInfo> {
|
||||||
|
final model = FFI.serverModel;
|
||||||
var _passwdShow = false;
|
var _passwdShow = false;
|
||||||
Timer? _interval;
|
|
||||||
|
|
||||||
// TODO set ID / PASSWORD
|
|
||||||
var _serverId = TextEditingController(text: "");
|
|
||||||
var _serverPasswd = TextEditingController(text: "");
|
|
||||||
var _emptyIdShow = translate("connecting_status");
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
var id = FFI.getByName("server_id");
|
|
||||||
|
|
||||||
// TODO 需要重新优化开启监听 开启监听服务后再开始pop_event
|
|
||||||
FFI.setByName("ensure_init_event_queue");
|
|
||||||
_interval = Timer.periodic(Duration(milliseconds: 30),
|
|
||||||
(timer) {
|
|
||||||
FFI.ffiModel.update("", (_, __) {});});
|
|
||||||
|
|
||||||
_serverId.text = id == "" ? _emptyIdShow : id;
|
|
||||||
_serverPasswd.text = FFI.getByName("server_password");
|
|
||||||
if (_serverId.text == _emptyIdShow || _serverPasswd.text == "") {
|
|
||||||
fetchConfigAgain();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_interval?.cancel();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return myCard(Column(
|
return model.isStart
|
||||||
|
? PaddingCard(
|
||||||
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
@ -112,12 +83,12 @@ class _ServerInfoState extends State<ServerInfo> {
|
|||||||
fontSize: 25.0,
|
fontSize: 25.0,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: MyTheme.accent),
|
color: MyTheme.accent),
|
||||||
controller: _serverId,
|
controller: model.serverId,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.perm_identity),
|
icon: const Icon(Icons.perm_identity),
|
||||||
labelText: translate("ID"),
|
labelText: translate("ID"),
|
||||||
labelStyle:
|
labelStyle: TextStyle(
|
||||||
TextStyle(fontWeight: FontWeight.bold, color: MyTheme.accent50),
|
fontWeight: FontWeight.bold, color: MyTheme.accent50),
|
||||||
),
|
),
|
||||||
onSaved: (String? value) {},
|
onSaved: (String? value) {},
|
||||||
),
|
),
|
||||||
@ -128,7 +99,7 @@ class _ServerInfoState extends State<ServerInfo> {
|
|||||||
fontSize: 25.0,
|
fontSize: 25.0,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: MyTheme.accent),
|
color: MyTheme.accent),
|
||||||
controller: _serverPasswd,
|
controller: model.serverPasswd,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.lock),
|
icon: const Icon(Icons.lock),
|
||||||
labelText: translate("Password"),
|
labelText: translate("Password"),
|
||||||
@ -144,27 +115,37 @@ class _ServerInfoState extends State<ServerInfo> {
|
|||||||
onSaved: (String? value) {},
|
onSaved: (String? value) {},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
))
|
||||||
|
: PaddingCard(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.warning_amber_sharp,
|
||||||
|
color: Colors.redAccent, size: 24),
|
||||||
|
SizedBox(width: 10),
|
||||||
|
Text(
|
||||||
|
"屏幕共享尚未开启",
|
||||||
|
style: TextStyle(
|
||||||
|
fontFamily: 'WorkSans',
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 18,
|
||||||
|
color: MyTheme.accent80,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
SizedBox(height: 5),
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
"点击[启动服务]或打开Screen Capture 开启共享手机屏幕",
|
||||||
|
style: TextStyle(fontSize: 12, color: MyTheme.darkGray),
|
||||||
|
))
|
||||||
|
],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchConfigAgain() async {
|
|
||||||
FFI.setByName("start_service");
|
|
||||||
var count = 0;
|
|
||||||
const maxCount = 10;
|
|
||||||
while (count < maxCount) {
|
|
||||||
if (_serverId.text != _emptyIdShow && _serverPasswd.text != "") {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
await Future.delayed(Duration(seconds: 2));
|
|
||||||
var id = FFI.getByName("server_id");
|
|
||||||
_serverId.text = id == "" ? _emptyIdShow : id;
|
|
||||||
_serverPasswd.text = FFI.getByName("server_password");
|
|
||||||
debugPrint(
|
|
||||||
"fetch id & passwd again at $count:id:${_serverId.text},passwd:${_serverPasswd.text}");
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
FFI.setByName("stop_service");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PermissionChecker extends StatefulWidget {
|
class PermissionChecker extends StatefulWidget {
|
||||||
@ -176,27 +157,32 @@ class _PermissionCheckerState extends State<PermissionChecker> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serverModel = Provider.of<ServerModel>(context);
|
final serverModel = Provider.of<ServerModel>(context);
|
||||||
|
final androidVersion = PlatformFFI.androidVersion ?? 0;
|
||||||
return myCard(Column(
|
final hasAudioPermission = androidVersion>=33;
|
||||||
|
return PaddingCard(
|
||||||
|
title: translate("Configuration Permissions"),
|
||||||
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
cardTitle(translate("Configuration Permissions")),
|
PermissionRow(translate("Screen Capture"), serverModel.mediaOk,
|
||||||
PermissionRow(
|
serverModel.startService),
|
||||||
translate("Media"), serverModel.mediaOk, _toAndroidInitService),
|
PermissionRow(translate("Mouse Control"), serverModel.inputOk,
|
||||||
const Divider(height: 0),
|
showInputWarnAlert),
|
||||||
PermissionRow(
|
PermissionRow(translate("File Transfer"), serverModel.fileOk,
|
||||||
translate("Input"), serverModel.inputOk, showInputWarnAlert),
|
serverModel.toggleFile),
|
||||||
const Divider(),
|
hasAudioPermission?PermissionRow(translate("Audio Capture"), serverModel.inputOk,
|
||||||
|
showInputWarnAlert):Text("* 当前安卓版本不支持音频捕获",style: TextStyle(color: MyTheme.darkGray),),
|
||||||
|
SizedBox(height: 8),
|
||||||
serverModel.mediaOk
|
serverModel.mediaOk
|
||||||
? ElevatedButton.icon(
|
? ElevatedButton.icon(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor: MaterialStateProperty.all(Colors.red)),
|
backgroundColor: MaterialStateProperty.all(Colors.red)),
|
||||||
icon: Icon(Icons.stop),
|
icon: Icon(Icons.stop),
|
||||||
onPressed: _toAndroidStopService,
|
onPressed: serverModel.stopService,
|
||||||
label: Text(translate("Stop service")))
|
label: Text(translate("Stop service")))
|
||||||
: ElevatedButton.icon(
|
: ElevatedButton.icon(
|
||||||
icon: Icon(Icons.play_arrow),
|
icon: Icon(Icons.play_arrow),
|
||||||
onPressed: _toAndroidInitService,
|
onPressed: serverModel.startService,
|
||||||
label: Text(translate("Start Service"))),
|
label: Text(translate("Start Service"))),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
@ -218,7 +204,7 @@ class PermissionRow extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 70,
|
width: 140,
|
||||||
child: Text(name,
|
child: Text(name,
|
||||||
style: TextStyle(fontSize: 16.0, color: MyTheme.accent50))),
|
style: TextStyle(fontSize: 16.0, color: MyTheme.accent50))),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@ -231,11 +217,12 @@ class PermissionRow extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: isOk ? null : onPressed,
|
onPressed: onPressed,
|
||||||
child: Text(
|
child: Text(
|
||||||
translate("OPEN"),
|
translate(isOk ?"CLOSE":"OPEN"),
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
)),
|
)),
|
||||||
|
const Divider(height: 0)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -246,95 +233,86 @@ class ConnectionManager extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serverModel = Provider.of<ServerModel>(context);
|
final serverModel = Provider.of<ServerModel>(context);
|
||||||
return Column(
|
return Column(
|
||||||
children: serverModel.clients.map((client) =>
|
children: serverModel.clients
|
||||||
myCard(Column(
|
.map((client) => PaddingCard(
|
||||||
|
title: translate("Connection"),
|
||||||
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
cardTitle(translate("Connection")),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 5.0),
|
padding: EdgeInsets.symmetric(vertical: 5.0),
|
||||||
child: clientInfo(client),
|
child: clientInfo(client),
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor: MaterialStateProperty.all(Colors.red)),
|
backgroundColor:
|
||||||
|
MaterialStateProperty.all(Colors.red)),
|
||||||
icon: Icon(Icons.close),
|
icon: Icon(Icons.close),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
FFI.setByName("close_conn",client.id.toString());
|
FFI.setByName("close_conn", client.id.toString());
|
||||||
},
|
},
|
||||||
label: Text(translate("Close")))
|
label: Text(translate("Close")))
|
||||||
],
|
],
|
||||||
))
|
)))
|
||||||
).toList()
|
.toList());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget cardTitle(String text) {
|
class PaddingCard extends StatelessWidget {
|
||||||
return Padding(
|
PaddingCard({required this.child, this.title});
|
||||||
|
|
||||||
|
final String? title;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final children = [child];
|
||||||
|
if (title != null) {
|
||||||
|
children.insert(
|
||||||
|
0,
|
||||||
|
Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 5.0),
|
padding: EdgeInsets.symmetric(vertical: 5.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
text,
|
title!,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontFamily: 'WorkSans',
|
fontFamily: 'WorkSans',
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
color: MyTheme.accent80,
|
color: MyTheme.accent80,
|
||||||
),
|
),
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget myCard(Widget child) {
|
|
||||||
return Container(
|
return Container(
|
||||||
width: double.maxFinite,
|
width: double.maxFinite,
|
||||||
child: Card(
|
child: Card(
|
||||||
margin: EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 0),
|
margin: EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 0),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 30.0),
|
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 30.0),
|
||||||
child: child,
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: children,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget clientInfo(Client client) {
|
Widget clientInfo(Client client) {
|
||||||
return Row(
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start
|
||||||
|
,children: [
|
||||||
|
Row(
|
||||||
children: [
|
children: [
|
||||||
CircleAvatar(child: Text(client.name[0]), backgroundColor: MyTheme.border),
|
CircleAvatar(
|
||||||
|
child: Text(client.name[0]), backgroundColor: MyTheme.border),
|
||||||
SizedBox(width: 12),
|
SizedBox(width: 12),
|
||||||
Text(client.name, style: TextStyle(color: MyTheme.idColor)),
|
Text(client.name, style: TextStyle(color: MyTheme.idColor)),
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Text(client.peerId, style: TextStyle(color: MyTheme.idColor))
|
Text(client.peerId, style: TextStyle(color: MyTheme.idColor))
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
}
|
Text("类型:${client.isFileTransfer?"管理文件":"屏幕控制"}" ,style: TextStyle(color: MyTheme.darkGray))
|
||||||
|
]);
|
||||||
Future<Null> _toAndroidInitService() async {
|
|
||||||
bool res = await FFI.invokeMethod("init_service");
|
|
||||||
FFI.setByName("start_service");
|
|
||||||
debugPrint("_toAndroidInitService:$res");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Future<Null> _toAndroidStartCapture() async {
|
|
||||||
// bool res = await FFI.invokeMethod("start_capture");
|
|
||||||
// debugPrint("_toAndroidStartCapture:$res");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Future<Null> _toAndroidStopCapture() async {
|
|
||||||
// bool res = await FFI.invokeMethod("stop_capture");
|
|
||||||
// debugPrint("_toAndroidStopCapture:$res");
|
|
||||||
// }
|
|
||||||
|
|
||||||
Future<Null> _toAndroidStopService() async {
|
|
||||||
FFI.serverModel.closeAll();
|
|
||||||
|
|
||||||
bool res = await FFI.invokeMethod("stop_service");
|
|
||||||
FFI.setByName("stop_service");
|
|
||||||
debugPrint("_toAndroidStopSer:$res");
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Null> _toAndroidInitInput() async {
|
|
||||||
bool res = await FFI.invokeMethod("init_input");
|
|
||||||
debugPrint("_toAndroidInitInput:$res");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showInputWarnAlert() async {
|
showInputWarnAlert() async {
|
||||||
@ -347,7 +325,6 @@ showInputWarnAlert() async {
|
|||||||
DialogManager.register(alertContext);
|
DialogManager.register(alertContext);
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text("获取输入权限引导"),
|
title: Text("获取输入权限引导"),
|
||||||
// content: Text("请在接下来的系统设置页面 \n进入 [服务] 配置页面\n将[RustDesk Input]服务开启"),
|
|
||||||
content: Text.rich(TextSpan(style: TextStyle(), children: [
|
content: Text.rich(TextSpan(style: TextStyle(), children: [
|
||||||
TextSpan(text: "请在接下来的系统设置页\n进入"),
|
TextSpan(text: "请在接下来的系统设置页\n进入"),
|
||||||
TextSpan(text: " [服务] ", style: TextStyle(color: MyTheme.accent)),
|
TextSpan(text: " [服务] ", style: TextStyle(color: MyTheme.accent)),
|
||||||
@ -366,7 +343,7 @@ showInputWarnAlert() async {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
child: Text(translate("Go System Setting")),
|
child: Text(translate("Go System Setting")),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_toAndroidInitInput();
|
FFI.serverModel.initInput();
|
||||||
DialogManager.reset();
|
DialogManager.reset();
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -380,27 +357,12 @@ void toAndroidChannelInit() {
|
|||||||
debugPrint("flutter got android msg,$method,$arguments");
|
debugPrint("flutter got android msg,$method,$arguments");
|
||||||
try {
|
try {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
// case "try_start_without_auth":
|
|
||||||
// {
|
|
||||||
// FFI.serverModel.updateClientState();
|
|
||||||
// debugPrint(
|
|
||||||
// "pre show loginAlert:${FFI.serverModel.isFileTransfer.toString()}");
|
|
||||||
// showLoginReqAlert(FFI.serverModel.peerID, FFI.serverModel.peerName);
|
|
||||||
// debugPrint("from jvm:try_start_without_auth done");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
case "start_capture":
|
case "start_capture":
|
||||||
{
|
{
|
||||||
DialogManager.reset();
|
DialogManager.reset();
|
||||||
FFI.serverModel.updateClientState();
|
FFI.serverModel.updateClientState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// case "stop_capture":
|
|
||||||
// {
|
|
||||||
// DialogManager.reset();
|
|
||||||
// FFI.serverModel.setPeer(false);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
case "on_permission_changed":
|
case "on_permission_changed":
|
||||||
{
|
{
|
||||||
var name = arguments["name"] as String;
|
var name = arguments["name"] as String;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user