mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
android update,open and close service
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hbb/server_page.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'dart:io';
|
||||
import 'main.dart';
|
||||
|
||||
typedef F = String Function(String);
|
||||
|
||||
@@ -12,6 +14,7 @@ class Translator {
|
||||
|
||||
class MyTheme {
|
||||
MyTheme._();
|
||||
|
||||
static const Color grayBg = Color(0xFFEEEEEE);
|
||||
static const Color white = Color(0xFFFFFFFF);
|
||||
static const Color accent = Color(0xFF0071FF);
|
||||
@@ -30,6 +33,7 @@ final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
||||
);
|
||||
|
||||
void Function() loadingCancelCallback = null;
|
||||
|
||||
void showLoading(String text, BuildContext context) {
|
||||
if (_hasDialog && context != null) {
|
||||
Navigator.pop(context);
|
||||
@@ -71,6 +75,7 @@ void dismissLoading() {
|
||||
}
|
||||
|
||||
bool _hasDialog = false;
|
||||
|
||||
typedef BuildAlertDailog = Tuple3<Widget, Widget, List<Widget>> Function(
|
||||
void Function(void Function()));
|
||||
|
||||
@@ -107,9 +112,10 @@ void msgbox(String type, String title, String text, BuildContext context,
|
||||
[bool hasCancel]) {
|
||||
var wrap = (String text, void Function() onPressed) => ButtonTheme(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
materialTapTargetSize: MaterialTapTargetSize
|
||||
.shrinkWrap, //limits the touch area to the button area
|
||||
minWidth: 0, //wraps child's width
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
//limits the touch area to the button area
|
||||
minWidth: 0,
|
||||
//wraps child's width
|
||||
height: 0,
|
||||
child: TextButton(
|
||||
style: flatButtonStyle,
|
||||
@@ -165,12 +171,14 @@ class PasswordWidget extends StatefulWidget {
|
||||
|
||||
class _PasswordWidgetState extends State<PasswordWidget> {
|
||||
bool _passwordVisible = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
autofocus: true,
|
||||
controller: widget.controller,
|
||||
obscureText: !_passwordVisible, //This will obscure text dynamically
|
||||
obscureText: !_passwordVisible,
|
||||
//This will obscure text dynamically
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
decoration: InputDecoration(
|
||||
labelText: Translator.call('Password'),
|
||||
@@ -202,3 +210,46 @@ Color str2color(String str, [alpha = 0xFF]) {
|
||||
hash = hash % 16777216;
|
||||
return Color((hash & 0xFF7FFF) | (alpha << 24));
|
||||
}
|
||||
|
||||
toAndroidChannelInit() {
|
||||
toAndroidChannel.setMethodCallHandler((call) async {
|
||||
debugPrint("flutter got android msg");
|
||||
|
||||
try {
|
||||
switch (call.method) {
|
||||
case "try_start_without_auth":
|
||||
{
|
||||
var peerID = call.arguments["peerID"] as String;
|
||||
var name = call.arguments["name"] as String;
|
||||
ServerPage.serverModel.setPeer(false, name: name, id: peerID);
|
||||
showLoginReqAlert(nowCtx, peerID, name);
|
||||
debugPrint("from jvm:try_start_without_auth done");
|
||||
break;
|
||||
}
|
||||
case "start_capture":
|
||||
{
|
||||
var peerID = call.arguments["peerID"] as String;
|
||||
var name = call.arguments["name"] as String;
|
||||
ServerPage.serverModel.setPeer(true, name: name, id: peerID);
|
||||
break;
|
||||
}
|
||||
case "stop_capture":
|
||||
{
|
||||
ServerPage.serverModel.setPeer(false);
|
||||
break;
|
||||
}
|
||||
case "on_permission_changed":
|
||||
{
|
||||
var name = call.arguments["name"] as String;
|
||||
var value = call.arguments["value"] as String == "true";
|
||||
debugPrint("from jvm:on_permission_changed,$name:$value");
|
||||
ServerPage.serverModel.changeStatue(name, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("MethodCallHandler err:$e");
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'dart:async';
|
||||
import 'common.dart';
|
||||
import 'main.dart';
|
||||
import 'model.dart';
|
||||
import 'remote_page.dart';
|
||||
import 'dart:io';
|
||||
@@ -26,6 +26,7 @@ class _HomePageState extends State<HomePage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
nowCtx = context;
|
||||
if (Platform.isAndroid) {
|
||||
Timer(Duration(seconds: 5), () {
|
||||
_updateUrl = FFI.getByName('software_update_url');
|
||||
@@ -55,10 +56,11 @@ class _HomePageState extends State<HomePage> {
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('ID Server')),
|
||||
value: 'id_server'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Share My Screen')),
|
||||
value: 'server'),
|
||||
// TODO only android
|
||||
Platform.isAndroid
|
||||
? PopupMenuItem<String>(
|
||||
child: Text(translate('Share My Screen')),
|
||||
value: 'server')
|
||||
: null,
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('About') + ' RustDesk'),
|
||||
value: 'about'),
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/server_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:firebase_analytics/firebase_analytics.dart';
|
||||
import 'package:firebase_analytics/observer.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'common.dart';
|
||||
import 'model.dart';
|
||||
import 'home_page.dart';
|
||||
|
||||
const toAndroidChannel = MethodChannel("mChannel");
|
||||
BuildContext nowCtx;
|
||||
|
||||
Future<Null> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
toAndroidChannelInit();
|
||||
runApp(App());
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final analytics = FirebaseAnalytics();
|
||||
|
||||
@@ -37,10 +37,15 @@ class FfiModel with ChangeNotifier {
|
||||
bool _direct;
|
||||
|
||||
get permissions => _permissions;
|
||||
|
||||
get initialized => _initialized;
|
||||
|
||||
get display => _display;
|
||||
|
||||
get secure => _secure;
|
||||
|
||||
get direct => _direct;
|
||||
|
||||
get pi => _pi;
|
||||
|
||||
FfiModel() {
|
||||
@@ -245,7 +250,9 @@ class CanvasModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
double get x => _x;
|
||||
|
||||
double get y => _y;
|
||||
|
||||
double get scale => _scale;
|
||||
|
||||
void update(double x, double y, double scale) {
|
||||
@@ -295,7 +302,7 @@ class CanvasModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clear([bool notify=false]) {
|
||||
void clear([bool notify = false]) {
|
||||
_x = 0;
|
||||
_y = 0;
|
||||
_scale = 1.0;
|
||||
@@ -314,10 +321,15 @@ class CursorModel with ChangeNotifier {
|
||||
double _displayOriginY = 0;
|
||||
|
||||
ui.Image get image => _image;
|
||||
|
||||
double get x => _x - _displayOriginX;
|
||||
|
||||
double get y => _y - _displayOriginY;
|
||||
|
||||
Offset get offset => Offset(_x, _y);
|
||||
|
||||
double get hotx => _hotx;
|
||||
|
||||
double get hoty => _hoty;
|
||||
|
||||
// remote physical display coordinate
|
||||
@@ -506,6 +518,61 @@ class CursorModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
class ServerModel with ChangeNotifier {
|
||||
bool _mediaOk;
|
||||
bool _inputOk;
|
||||
|
||||
bool _peerEnabled;
|
||||
String _peerName;
|
||||
String _peerID;
|
||||
|
||||
bool get mediaOk => _mediaOk;
|
||||
|
||||
bool get inputOk => _inputOk;
|
||||
|
||||
bool get peerEnabled => _peerEnabled;
|
||||
|
||||
String get peerName => _peerName;
|
||||
|
||||
String get peerID => _peerID;
|
||||
|
||||
ServerModel() {
|
||||
_mediaOk = false;
|
||||
_inputOk = false;
|
||||
_peerEnabled = false;
|
||||
_peerName = "";
|
||||
_peerID = "";
|
||||
}
|
||||
|
||||
changeStatue(String name, bool value) {
|
||||
switch (name) {
|
||||
case "media":
|
||||
_mediaOk = value;
|
||||
break;
|
||||
case "input":
|
||||
_inputOk = value;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
setPeer(bool enabled, {String name = "", String id = ""}) {
|
||||
_peerEnabled = enabled;
|
||||
if (name != "") _peerName = name;
|
||||
if (id != "") _peerID = id;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
clearPeer() {
|
||||
_peerEnabled = false;
|
||||
_peerName = "";
|
||||
_peerID = "";
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class FFI {
|
||||
static String id = "";
|
||||
static String _dir = '';
|
||||
|
||||
@@ -1,34 +1,57 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/model.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'common.dart';
|
||||
import 'main.dart';
|
||||
|
||||
class ServerPage extends StatefulWidget {
|
||||
@override
|
||||
_ServerPageState createState() => _ServerPageState();
|
||||
}
|
||||
class ServerPage extends StatelessWidget {
|
||||
static final serverModel = ServerModel();
|
||||
|
||||
class _ServerPageState extends State<ServerPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: MyTheme.grayBg,
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: const Text("Share My Screen"),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
ServerInfo(),
|
||||
PermissionChecker(),
|
||||
// TODO: implement build
|
||||
return ChangeNotifierProvider.value(
|
||||
value: serverModel,
|
||||
child: Scaffold(
|
||||
backgroundColor: MyTheme.grayBg,
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: const Text("Share My Screen"),
|
||||
actions: [
|
||||
PopupMenuButton<String>(
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text("修改服务ID"),
|
||||
value: "changeID",
|
||||
enabled: false,
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text("修改服务密码"),
|
||||
value: "changeID",
|
||||
enabled: false,
|
||||
)
|
||||
];
|
||||
},
|
||||
onSelected: (value) =>
|
||||
debugPrint("PopupMenuItem onSelected:$value"))
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
body: SingleChildScrollView(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
ServerInfo(),
|
||||
PermissionChecker(),
|
||||
ConnectionManager(),
|
||||
SizedBox.fromSize(size: Size(0, 15.0)), // Bottom padding
|
||||
],
|
||||
),
|
||||
),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,60 +128,62 @@ class PermissionChecker extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PermissionCheckerState extends State<PermissionChecker> {
|
||||
static const toAndroidChannel = MethodChannel("mChannel");
|
||||
|
||||
var videoOk = false;
|
||||
var inputOk = false;
|
||||
var audioOk = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
nowCtx = context;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serverModel = Provider.of<ServerModel>(context);
|
||||
|
||||
return myCard(Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
cardTitle("权限列表"),
|
||||
PermissionRow("视频权限", videoOk, _toAndroidGetPer),
|
||||
PermissionRow("媒体权限", serverModel.mediaOk, _toAndroidInitService),
|
||||
const Divider(height: 0),
|
||||
PermissionRow("音频权限", videoOk, () => {debugPrint("获取视频权限")}),
|
||||
const Divider(height: 0),
|
||||
PermissionRow("输入权限", inputOk, _toAndroidCheckInput),
|
||||
PermissionRow("输入权限", serverModel.inputOk, _toAndroidCheckInput),
|
||||
const Divider(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
icon: Icon(Icons.play_arrow),
|
||||
onPressed: _toAndroidStartSer,
|
||||
label: Text("Start")),
|
||||
TextButton.icon(
|
||||
serverModel.mediaOk
|
||||
? ElevatedButton.icon(
|
||||
icon: Icon(Icons.stop),
|
||||
onPressed: _toAndroidStopSer,
|
||||
label: Text("Stop")),
|
||||
],
|
||||
)
|
||||
onPressed: _toAndroidStopService,
|
||||
label: Text("Stop"))
|
||||
: ElevatedButton.icon(
|
||||
icon: Icon(Icons.play_arrow),
|
||||
onPressed: _toAndroidInitService,
|
||||
label: Text("Start")),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidGetPer() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("getPer");
|
||||
debugPrint("_toAndroidGetPer:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidStartSer() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("startSer");
|
||||
debugPrint("_toAndroidStartSer:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidStopSer() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("stopSer");
|
||||
debugPrint("_toAndroidStopSer:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidCheckInput() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("checkInput");
|
||||
debugPrint("_toAndroidStopSer:$res");
|
||||
}
|
||||
void showLoginReqAlert(BuildContext context, String peerID, String name) {
|
||||
debugPrint("got try_start_without_auth");
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text("收到连接请求"),
|
||||
content: Text("是否同意来自$name:$peerID的控制?"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text("接受"),
|
||||
onPressed: () {
|
||||
FFI.setByName("login_res", "true");
|
||||
_toAndroidStartCapture();
|
||||
ServerPage.serverModel.setPeer(true);
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
TextButton(
|
||||
child: Text("不接受"),
|
||||
onPressed: () {
|
||||
FFI.setByName("login_res", "false");
|
||||
Navigator.of(context).pop();
|
||||
})
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
class PermissionRow extends StatelessWidget {
|
||||
@@ -183,7 +208,7 @@ class PermissionRow extends StatelessWidget {
|
||||
fontSize: 16.0, color: isOk ? Colors.green : Colors.grey)),
|
||||
])),
|
||||
TextButton(
|
||||
onPressed: onPressed,
|
||||
onPressed: isOk ? null : onPressed,
|
||||
child: const Text(
|
||||
"去开启",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
@@ -193,6 +218,37 @@ class PermissionRow extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class ConnectionManager extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serverModel = Provider.of<ServerModel>(context);
|
||||
var info =
|
||||
"${serverModel.peerName != "" ? serverModel.peerName : "NA"}-${serverModel.peerID != "" ? serverModel.peerID : "NA"}";
|
||||
return serverModel.peerEnabled
|
||||
? myCard(Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
cardTitle("当前连接"),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 5.0),
|
||||
child: Text(info, style: TextStyle(color: Colors.grey)),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.red)),
|
||||
icon: Icon(Icons.close),
|
||||
onPressed: () {
|
||||
FFI.setByName("close_conn");
|
||||
_toAndroidStopCapture();
|
||||
serverModel.setPeer(false);
|
||||
},
|
||||
label: Text("断开连接"))
|
||||
],
|
||||
))
|
||||
: SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
Widget cardTitle(String text) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 5.0),
|
||||
@@ -201,18 +257,47 @@ Widget cardTitle(String text) {
|
||||
style: TextStyle(
|
||||
fontFamily: 'WorkSans',
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 25,
|
||||
fontSize: 22,
|
||||
color: MyTheme.accent80,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Widget myCard(Widget child) {
|
||||
return Card(
|
||||
margin: EdgeInsets.all(15.0),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 30.0),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
return Container(
|
||||
width: double.maxFinite,
|
||||
child: Card(
|
||||
margin: EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 0),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 30.0),
|
||||
child: child,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidInitService() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("init_service");
|
||||
FFI.setByName("start_service");
|
||||
debugPrint("_toAndroidInitService:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidStartCapture() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("start_capture");
|
||||
debugPrint("_toAndroidStartCapture:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidStopCapture() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("stop_capture");
|
||||
debugPrint("_toAndroidStopCapture:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidStopService() async {
|
||||
FFI.setByName("stop_service");
|
||||
bool res = await toAndroidChannel.invokeMethod("stop_service");
|
||||
debugPrint("_toAndroidStopSer:$res");
|
||||
}
|
||||
|
||||
Future<Null> _toAndroidCheckInput() async {
|
||||
bool res = await toAndroidChannel.invokeMethod("check_input");
|
||||
debugPrint("_toAndroidStopSer:$res");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user