Merge pull request #1426 from fufesou/flutter_desktop_new_remote_menu_2
Flutter desktop new remote menu 2
This commit is contained in:
commit
06541be459
2
flutter/.gitignore
vendored
2
flutter/.gitignore
vendored
@ -48,7 +48,7 @@ lib/generated_bridge.dart
|
||||
lib/generated_bridge.freezed.dart
|
||||
|
||||
# Flutter Generated Files
|
||||
**/flutter/GeneratedPluginRegistrant.swift
|
||||
**/GeneratedPluginRegistrant.swift
|
||||
**/flutter/generated_plugin_registrant.cc
|
||||
**/flutter/generated_plugin_registrant.h
|
||||
**/flutter/generated_plugins.cmake
|
||||
|
@ -427,7 +427,45 @@ class CustomAlertDialog extends StatelessWidget {
|
||||
void msgBox(
|
||||
String type, String title, String text, OverlayDialogManager dialogManager,
|
||||
{bool? hasCancel}) {
|
||||
var wrap = (String text, void Function() onPressed) => ButtonTheme(
|
||||
dialogManager.dismissAll();
|
||||
List<Widget> buttons = [];
|
||||
if (type != "connecting" && type != "success" && !type.contains("nook")) {
|
||||
buttons.insert(
|
||||
0,
|
||||
msgBoxButton(translate('OK'), () {
|
||||
dialogManager.dismissAll();
|
||||
// https://github.com/fufesou/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
|
||||
if (!type.contains("custom")) {
|
||||
closeConnection();
|
||||
}
|
||||
}));
|
||||
}
|
||||
hasCancel ??= !type.contains("error") &&
|
||||
!type.contains("nocancel") &&
|
||||
type != "restarting";
|
||||
if (hasCancel) {
|
||||
buttons.insert(
|
||||
0,
|
||||
msgBoxButton(translate('Cancel'), () {
|
||||
dialogManager.dismissAll();
|
||||
}));
|
||||
}
|
||||
// TODO: test this button
|
||||
if (type.contains("hasclose")) {
|
||||
buttons.insert(
|
||||
0,
|
||||
msgBoxButton(translate('Close'), () {
|
||||
dialogManager.dismissAll();
|
||||
}));
|
||||
}
|
||||
dialogManager.show((setState, close) => CustomAlertDialog(
|
||||
title: _msgBoxTitle(title),
|
||||
content: Text(translate(text), style: TextStyle(fontSize: 15)),
|
||||
actions: buttons));
|
||||
}
|
||||
|
||||
Widget msgBoxButton(String text, void Function() onPressed) {
|
||||
return ButtonTheme(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
//limits the touch area to the button area
|
||||
@ -439,44 +477,16 @@ void msgBox(
|
||||
onPressed: onPressed,
|
||||
child:
|
||||
Text(translate(text), style: TextStyle(color: MyTheme.accent))));
|
||||
}
|
||||
|
||||
Widget _msgBoxTitle(String title) => Text(translate(title), style: TextStyle(fontSize: 21));
|
||||
|
||||
void msgBoxCommon(OverlayDialogManager dialogManager, String title,
|
||||
Widget content, List<Widget> buttons) {
|
||||
dialogManager.dismissAll();
|
||||
List<Widget> buttons = [];
|
||||
if (type != "connecting" && type != "success" && type.indexOf("nook") < 0) {
|
||||
buttons.insert(
|
||||
0,
|
||||
wrap(translate('OK'), () {
|
||||
dialogManager.dismissAll();
|
||||
// https://github.com/fufesou/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
|
||||
if (type.indexOf("custom") < 0) {
|
||||
closeConnection();
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (hasCancel == null) {
|
||||
// hasCancel = type != 'error';
|
||||
hasCancel = type.indexOf("error") < 0 &&
|
||||
type.indexOf("nocancel") < 0 &&
|
||||
type != "restarting";
|
||||
}
|
||||
if (hasCancel) {
|
||||
buttons.insert(
|
||||
0,
|
||||
wrap(translate('Cancel'), () {
|
||||
dialogManager.dismissAll();
|
||||
}));
|
||||
}
|
||||
// TODO: test this button
|
||||
if (type.indexOf("hasclose") >= 0) {
|
||||
buttons.insert(
|
||||
0,
|
||||
wrap(translate('Close'), () {
|
||||
dialogManager.dismissAll();
|
||||
}));
|
||||
}
|
||||
dialogManager.show((setState, close) => CustomAlertDialog(
|
||||
title: Text(translate(title), style: TextStyle(fontSize: 21)),
|
||||
content: Text(translate(text), style: TextStyle(fontSize: 15)),
|
||||
title: _msgBoxTitle(title),
|
||||
content: content,
|
||||
actions: buttons));
|
||||
}
|
||||
|
||||
@ -495,13 +505,13 @@ const G = M * K;
|
||||
|
||||
String readableFileSize(double size) {
|
||||
if (size < K) {
|
||||
return size.toStringAsFixed(2) + " B";
|
||||
return "${size.toStringAsFixed(2)} B";
|
||||
} else if (size < M) {
|
||||
return (size / K).toStringAsFixed(2) + " KB";
|
||||
return "${(size / K).toStringAsFixed(2)} KB";
|
||||
} else if (size < G) {
|
||||
return (size / M).toStringAsFixed(2) + " MB";
|
||||
return "${(size / M).toStringAsFixed(2)} MB";
|
||||
} else {
|
||||
return (size / G).toStringAsFixed(2) + " GB";
|
||||
return "${(size / G).toStringAsFixed(2)} GB";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,10 @@ const String kAppTypeDesktopPortForward = "port forward";
|
||||
const String kTabLabelHomePage = "Home";
|
||||
const String kTabLabelSettingPage = "Settings";
|
||||
|
||||
const int kDefaultDisplayWidth = 1280;
|
||||
const int kDefaultDisplayHeight = 720;
|
||||
const int kMobileDefaultDisplayWidth = 720;
|
||||
const int kMobileDefaultDisplayHeight = 1280;
|
||||
|
||||
const int kDesktopDefaultDisplayWidth = 1080;
|
||||
const int kDesktopDefaultDisplayHeight = 720;
|
||||
|
||||
const kInvalidValueStr = "InvalidValueStr";
|
||||
|
@ -33,7 +33,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
final _idController = TextEditingController();
|
||||
|
||||
/// Update url. If it's not null, means an update is available.
|
||||
var _updateUrl = '';
|
||||
final _updateUrl = '';
|
||||
|
||||
Timer? _updateTimer;
|
||||
|
||||
@ -92,7 +92,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Offstage();
|
||||
return const Offstage();
|
||||
}
|
||||
}),
|
||||
],
|
||||
@ -110,7 +110,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
/// Callback for the connect button.
|
||||
/// Connects to the selected peer.
|
||||
void onConnect({bool isFileTransfer = false}) {
|
||||
var id = _idController.text.trim();
|
||||
final id = _idController.text.trim();
|
||||
connect(id, isFileTransfer: isFileTransfer);
|
||||
}
|
||||
|
||||
@ -120,9 +120,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
if (id == '') return;
|
||||
id = id.replaceAll(' ', '');
|
||||
if (isFileTransfer) {
|
||||
await rustDeskWinManager.new_file_transfer(id);
|
||||
await rustDeskWinManager.newFileTransfer(id);
|
||||
} else {
|
||||
await rustDeskWinManager.new_remote_desktop(id);
|
||||
await rustDeskWinManager.newRemoteDesktop(id);
|
||||
}
|
||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||
if (!currentFocus.hasPrimaryFocus) {
|
||||
|
@ -61,6 +61,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
final args = jsonDecode(call.arguments);
|
||||
final id = args['id'];
|
||||
window_on_top(windowId());
|
||||
ConnectionTypeState.init(id);
|
||||
tabController.add(TabInfo(
|
||||
key: id,
|
||||
label: id,
|
||||
@ -108,7 +109,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
},
|
||||
tabBuilder: (key, icon, label, themeConf) => Obx(() {
|
||||
final connectionType = ConnectionTypeState.find(key);
|
||||
if (!ConnectionTypeState.find(key).isValid()) {
|
||||
if (!connectionType.isValid()) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
|
@ -689,11 +689,11 @@ class ImagePaint extends StatelessWidget {
|
||||
width: c.getDisplayWidth() * s,
|
||||
height: c.getDisplayHeight() * s,
|
||||
child: CustomPaint(
|
||||
painter: new ImagePainter(image: m.image, x: 0, y: 0, scale: s),
|
||||
painter: ImagePainter(image: m.image, x: 0, y: 0, scale: s),
|
||||
));
|
||||
return Center(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (_notification) {
|
||||
onNotification: (notification) {
|
||||
final percentX = _horizontal.position.extentBefore /
|
||||
(_horizontal.position.extentBefore +
|
||||
_horizontal.position.extentInside +
|
||||
@ -716,8 +716,8 @@ class ImagePaint extends StatelessWidget {
|
||||
width: c.size.width,
|
||||
height: c.size.height,
|
||||
child: CustomPaint(
|
||||
painter: new ImagePainter(
|
||||
image: m.image, x: c.x / s, y: c.y / s, scale: s),
|
||||
painter:
|
||||
ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
|
||||
));
|
||||
return _buildListener(imageWidget);
|
||||
}
|
||||
@ -771,7 +771,7 @@ class CursorPaint extends StatelessWidget {
|
||||
// final adjust = m.adjustForKeyboard();
|
||||
var s = c.scale;
|
||||
return CustomPaint(
|
||||
painter: new ImagePainter(
|
||||
painter: ImagePainter(
|
||||
image: m.image,
|
||||
x: m.x * s - m.hotx + c.x,
|
||||
y: m.y * s - m.hoty + c.y,
|
||||
@ -796,15 +796,16 @@ class ImagePainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
if (image == null) return;
|
||||
if (x.isNaN || y.isNaN) return;
|
||||
canvas.scale(scale, scale);
|
||||
// https://github.com/flutter/flutter/issues/76187#issuecomment-784628161
|
||||
// https://api.flutter-io.cn/flutter/dart-ui/FilterQuality.html
|
||||
var paint = new Paint();
|
||||
var paint = Paint();
|
||||
paint.filterQuality = FilterQuality.medium;
|
||||
if (scale > 10.00000) {
|
||||
paint.filterQuality = FilterQuality.high;
|
||||
}
|
||||
canvas.drawImage(image!, new Offset(x, y), paint);
|
||||
canvas.drawImage(image!, Offset(x, y), paint);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -21,18 +21,16 @@ final peerSearchTextController =
|
||||
TextEditingController(text: peerSearchText.value);
|
||||
|
||||
class _PeerWidget extends StatefulWidget {
|
||||
late final _peers;
|
||||
late final OffstageFunc _offstageFunc;
|
||||
late final PeerCardWidgetFunc _peerCardWidgetFunc;
|
||||
final Peers peers;
|
||||
final OffstageFunc offstageFunc;
|
||||
final PeerCardWidgetFunc peerCardWidgetFunc;
|
||||
|
||||
_PeerWidget(Peers peers, OffstageFunc offstageFunc,
|
||||
PeerCardWidgetFunc peerCardWidgetFunc,
|
||||
{Key? key})
|
||||
: super(key: key) {
|
||||
_peers = peers;
|
||||
_offstageFunc = offstageFunc;
|
||||
_peerCardWidgetFunc = peerCardWidgetFunc;
|
||||
}
|
||||
const _PeerWidget(
|
||||
{required this.peers,
|
||||
required this.offstageFunc,
|
||||
required this.peerCardWidgetFunc,
|
||||
Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_PeerWidgetState createState() => _PeerWidgetState();
|
||||
@ -42,9 +40,9 @@ class _PeerWidget extends StatefulWidget {
|
||||
class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
||||
static const int _maxQueryCount = 3;
|
||||
|
||||
var _curPeers = Set<String>();
|
||||
final _curPeers = <String>{};
|
||||
var _lastChangeTime = DateTime.now();
|
||||
var _lastQueryPeers = Set<String>();
|
||||
var _lastQueryPeers = <String>{};
|
||||
var _lastQueryTime = DateTime.now().subtract(Duration(hours: 1));
|
||||
var _queryCoun = 0;
|
||||
var _exit = false;
|
||||
@ -78,65 +76,62 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final space = 12.0;
|
||||
const space = 12.0;
|
||||
return ChangeNotifierProvider<Peers>(
|
||||
create: (context) => super.widget._peers,
|
||||
create: (context) => widget.peers,
|
||||
child: Consumer<Peers>(
|
||||
builder: (context, peers, child) => peers.peers.isEmpty
|
||||
? Center(
|
||||
child: Text(translate("Empty")),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: ObxValue<RxString>((searchText) {
|
||||
return FutureBuilder<List<Peer>>(
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final peers = snapshot.data!;
|
||||
final cards = <Widget>[];
|
||||
for (final peer in peers) {
|
||||
cards.add(Offstage(
|
||||
key: ValueKey("off${peer.id}"),
|
||||
offstage: super.widget._offstageFunc(peer),
|
||||
child: Obx(
|
||||
() => SizedBox(
|
||||
width: 220,
|
||||
height:
|
||||
peerCardUiType.value == PeerUiType.grid
|
||||
? 140
|
||||
: 42,
|
||||
child: VisibilityDetector(
|
||||
key: ValueKey(peer.id),
|
||||
onVisibilityChanged: (info) {
|
||||
final peerId =
|
||||
(info.key as ValueKey).value;
|
||||
if (info.visibleFraction > 0.00001) {
|
||||
_curPeers.add(peerId);
|
||||
} else {
|
||||
_curPeers.remove(peerId);
|
||||
}
|
||||
_lastChangeTime = DateTime.now();
|
||||
},
|
||||
child: super
|
||||
.widget
|
||||
._peerCardWidgetFunc(peer),
|
||||
),
|
||||
builder: (context, peers, child) => peers.peers.isEmpty
|
||||
? Center(
|
||||
child: Text(translate("Empty")),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: ObxValue<RxString>((searchText) {
|
||||
return FutureBuilder<List<Peer>>(
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final peers = snapshot.data!;
|
||||
final cards = <Widget>[];
|
||||
for (final peer in peers) {
|
||||
cards.add(Offstage(
|
||||
key: ValueKey("off${peer.id}"),
|
||||
offstage: widget.offstageFunc(peer),
|
||||
child: Obx(
|
||||
() => SizedBox(
|
||||
width: 220,
|
||||
height:
|
||||
peerCardUiType.value == PeerUiType.grid
|
||||
? 140
|
||||
: 42,
|
||||
child: VisibilityDetector(
|
||||
key: ValueKey(peer.id),
|
||||
onVisibilityChanged: (info) {
|
||||
final peerId =
|
||||
(info.key as ValueKey).value;
|
||||
if (info.visibleFraction > 0.00001) {
|
||||
_curPeers.add(peerId);
|
||||
} else {
|
||||
_curPeers.remove(peerId);
|
||||
}
|
||||
_lastChangeTime = DateTime.now();
|
||||
},
|
||||
child: widget.peerCardWidgetFunc(peer),
|
||||
),
|
||||
)));
|
||||
}
|
||||
return Wrap(
|
||||
spacing: space,
|
||||
runSpacing: space,
|
||||
children: cards);
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
),
|
||||
)));
|
||||
}
|
||||
},
|
||||
future: matchPeers(searchText.value, peers.peers),
|
||||
);
|
||||
}, peerSearchText),
|
||||
)),
|
||||
return Wrap(
|
||||
spacing: space, runSpacing: space, children: cards);
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
},
|
||||
future: matchPeers(searchText.value, peers.peers),
|
||||
);
|
||||
}, peerSearchText),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -175,31 +170,42 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
||||
}
|
||||
|
||||
abstract class BasePeerWidget extends StatelessWidget {
|
||||
late final _name;
|
||||
late final _loadEvent;
|
||||
late final OffstageFunc _offstageFunc;
|
||||
late final PeerCardWidgetFunc _peerCardWidgetFunc;
|
||||
late final List<Peer> _initPeers;
|
||||
final String name;
|
||||
final String loadEvent;
|
||||
final OffstageFunc offstageFunc;
|
||||
final PeerCardWidgetFunc peerCardWidgetFunc;
|
||||
final List<Peer> initPeers;
|
||||
|
||||
BasePeerWidget({Key? key}) : super(key: key) {}
|
||||
const BasePeerWidget({
|
||||
Key? key,
|
||||
required this.name,
|
||||
required this.loadEvent,
|
||||
required this.offstageFunc,
|
||||
required this.peerCardWidgetFunc,
|
||||
required this.initPeers,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _PeerWidget(Peers(_name, _loadEvent, _initPeers), _offstageFunc,
|
||||
_peerCardWidgetFunc);
|
||||
return _PeerWidget(
|
||||
peers: Peers(name: name, loadEvent: loadEvent, peers: initPeers),
|
||||
offstageFunc: offstageFunc,
|
||||
peerCardWidgetFunc: peerCardWidgetFunc);
|
||||
}
|
||||
}
|
||||
|
||||
class RecentPeerWidget extends BasePeerWidget {
|
||||
RecentPeerWidget({Key? key}) : super(key: key) {
|
||||
super._name = "recent peer";
|
||||
super._loadEvent = "load_recent_peers";
|
||||
super._offstageFunc = (Peer _peer) => false;
|
||||
super._peerCardWidgetFunc = (Peer peer) => RecentPeerCard(
|
||||
peer: peer,
|
||||
RecentPeerWidget({Key? key})
|
||||
: super(
|
||||
key: key,
|
||||
name: 'recent peer',
|
||||
loadEvent: 'load_recent_peers',
|
||||
offstageFunc: (Peer peer) => false,
|
||||
peerCardWidgetFunc: (Peer peer) => RecentPeerCard(
|
||||
peer: peer,
|
||||
),
|
||||
initPeers: [],
|
||||
);
|
||||
super._initPeers = [];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -210,13 +216,17 @@ class RecentPeerWidget extends BasePeerWidget {
|
||||
}
|
||||
|
||||
class FavoritePeerWidget extends BasePeerWidget {
|
||||
FavoritePeerWidget({Key? key}) : super(key: key) {
|
||||
super._name = "favorite peer";
|
||||
super._loadEvent = "load_fav_peers";
|
||||
super._offstageFunc = (Peer _peer) => false;
|
||||
super._peerCardWidgetFunc = (Peer peer) => FavoritePeerCard(peer: peer);
|
||||
super._initPeers = [];
|
||||
}
|
||||
FavoritePeerWidget({Key? key})
|
||||
: super(
|
||||
key: key,
|
||||
name: 'favorite peer',
|
||||
loadEvent: 'load_fav_peers',
|
||||
offstageFunc: (Peer peer) => false,
|
||||
peerCardWidgetFunc: (Peer peer) => FavoritePeerCard(
|
||||
peer: peer,
|
||||
),
|
||||
initPeers: [],
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -227,13 +237,17 @@ class FavoritePeerWidget extends BasePeerWidget {
|
||||
}
|
||||
|
||||
class DiscoveredPeerWidget extends BasePeerWidget {
|
||||
DiscoveredPeerWidget({Key? key}) : super(key: key) {
|
||||
super._name = "discovered peer";
|
||||
super._loadEvent = "load_lan_peers";
|
||||
super._offstageFunc = (Peer _peer) => false;
|
||||
super._peerCardWidgetFunc = (Peer peer) => DiscoveredPeerCard(peer: peer);
|
||||
super._initPeers = [];
|
||||
}
|
||||
DiscoveredPeerWidget({Key? key})
|
||||
: super(
|
||||
key: key,
|
||||
name: 'discovered peer',
|
||||
loadEvent: 'load_lan_peers',
|
||||
offstageFunc: (Peer peer) => false,
|
||||
peerCardWidgetFunc: (Peer peer) => DiscoveredPeerCard(
|
||||
peer: peer,
|
||||
),
|
||||
initPeers: [],
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -244,21 +258,26 @@ class DiscoveredPeerWidget extends BasePeerWidget {
|
||||
}
|
||||
|
||||
class AddressBookPeerWidget extends BasePeerWidget {
|
||||
AddressBookPeerWidget({Key? key}) : super(key: key) {
|
||||
super._name = "address book peer";
|
||||
super._offstageFunc =
|
||||
(Peer peer) => !_hitTag(gFFI.abModel.selectedTags, peer.tags);
|
||||
super._peerCardWidgetFunc = (Peer peer) => AddressBookPeerCard(peer: peer);
|
||||
super._initPeers = _loadPeers();
|
||||
}
|
||||
AddressBookPeerWidget({Key? key})
|
||||
: super(
|
||||
key: key,
|
||||
name: 'address book peer',
|
||||
loadEvent: 'load_address_book_peers',
|
||||
offstageFunc: (Peer peer) =>
|
||||
!_hitTag(gFFI.abModel.selectedTags, peer.tags),
|
||||
peerCardWidgetFunc: (Peer peer) => DiscoveredPeerCard(
|
||||
peer: peer,
|
||||
),
|
||||
initPeers: _loadPeers(),
|
||||
);
|
||||
|
||||
List<Peer> _loadPeers() {
|
||||
static List<Peer> _loadPeers() {
|
||||
return gFFI.abModel.peers.map((e) {
|
||||
return Peer.fromJson(e['id'], e);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
bool _hitTag(List<dynamic> selectedTags, List<dynamic> idents) {
|
||||
static bool _hitTag(List<dynamic> selectedTags, List<dynamic> idents) {
|
||||
if (selectedTags.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
|
@ -8,10 +8,18 @@ import '../../common.dart';
|
||||
import '../../models/model.dart';
|
||||
import '../../models/peer_model.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
import './material_mod_popup_menu.dart' as mod_menu;
|
||||
import './popup_menu.dart';
|
||||
|
||||
typedef PopupMenuItemsFunc = Future<List<PopupMenuItem<String>>> Function();
|
||||
class _PopupMenuTheme {
|
||||
static const Color commonColor = MyTheme.accent;
|
||||
// kMinInteractiveDimension
|
||||
static const double height = 25.0;
|
||||
static const double dividerHeight = 12.0;
|
||||
}
|
||||
|
||||
enum PeerType { recent, fav, discovered, ab }
|
||||
typedef PopupMenuEntryBuilder = Future<List<mod_menu.PopupMenuEntry<String>>>
|
||||
Function(BuildContext);
|
||||
|
||||
enum PeerUiType { grid, list }
|
||||
|
||||
@ -19,14 +27,16 @@ final peerCardUiType = PeerUiType.grid.obs;
|
||||
|
||||
class _PeerCard extends StatefulWidget {
|
||||
final Peer peer;
|
||||
final PopupMenuItemsFunc popupMenuItemsFunc;
|
||||
final PeerType type;
|
||||
final RxString alias;
|
||||
final Function(BuildContext, String) connect;
|
||||
final PopupMenuEntryBuilder popupMenuEntryBuilder;
|
||||
|
||||
_PeerCard(
|
||||
{required this.peer,
|
||||
required this.popupMenuItemsFunc,
|
||||
Key? key,
|
||||
required this.type})
|
||||
required this.alias,
|
||||
required this.connect,
|
||||
required this.popupMenuEntryBuilder,
|
||||
Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@ -36,7 +46,6 @@ class _PeerCard extends StatefulWidget {
|
||||
/// State for the connection page.
|
||||
class _PeerCardState extends State<_PeerCard>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
var _menuPos = RelativeRect.fill;
|
||||
final double _cardRadis = 20;
|
||||
final double _borderWidth = 2;
|
||||
final RxBool _iconMoreHover = false.obs;
|
||||
@ -66,7 +75,7 @@ class _PeerCardState extends State<_PeerCard>
|
||||
: null);
|
||||
},
|
||||
child: GestureDetector(
|
||||
onDoubleTap: () => _connect(peer.id),
|
||||
onDoubleTap: () => widget.connect(context, peer.id),
|
||||
child: Obx(() => peerCardUiType.value == PeerUiType.grid
|
||||
? _buildPeerCard(context, peer, deco)
|
||||
: _buildPeerTile(context, peer, deco))),
|
||||
@ -185,46 +194,28 @@ class _PeerCardState extends State<_PeerCard>
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child:
|
||||
_getPlatformImage('${peer.platform}', 60),
|
||||
child: _getPlatformImage(peer.platform, 60),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: FutureBuilder<String>(
|
||||
future: bind.mainGetPeerOption(
|
||||
id: peer.id, key: 'alias'),
|
||||
builder: (_, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final name = snapshot.data!.isEmpty
|
||||
? '${peer.username}@${peer.hostname}'
|
||||
: snapshot.data!;
|
||||
return Tooltip(
|
||||
message: name,
|
||||
waitDuration: Duration(seconds: 1),
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// alias has not arrived
|
||||
return Center(
|
||||
child: Text(
|
||||
'${peer.username}@${peer.hostname}',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
));
|
||||
}
|
||||
},
|
||||
),
|
||||
child: Obx(() {
|
||||
final name = widget.alias.value.isEmpty
|
||||
? '${peer.username}@${peer.hostname}'
|
||||
: widget.alias.value;
|
||||
return Tooltip(
|
||||
message: name,
|
||||
waitDuration: Duration(seconds: 1),
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -248,7 +239,7 @@ class _PeerCardState extends State<_PeerCard>
|
||||
backgroundColor: peer.online
|
||||
? Colors.green
|
||||
: Colors.yellow)),
|
||||
Text('${peer.id}')
|
||||
Text(peer.id)
|
||||
]).paddingSymmetric(vertical: 8),
|
||||
_actionMore(peer),
|
||||
],
|
||||
@ -262,32 +253,93 @@ class _PeerCardState extends State<_PeerCard>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _actionMore(Peer peer) => Listener(
|
||||
onPointerDown: (e) {
|
||||
final x = e.position.dx;
|
||||
final y = e.position.dy;
|
||||
_menuPos = RelativeRect.fromLTRB(x, y, x, y);
|
||||
},
|
||||
onPointerUp: (_) => _showPeerMenu(context, peer.id),
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => _iconMoreHover.value = true,
|
||||
onExit: (_) => _iconMoreHover.value = false,
|
||||
child: CircleAvatar(
|
||||
radius: 14,
|
||||
backgroundColor: _iconMoreHover.value
|
||||
? MyTheme.color(context).grayBg!
|
||||
: MyTheme.color(context).bg!,
|
||||
child: Icon(Icons.more_vert,
|
||||
size: 18,
|
||||
color: _iconMoreHover.value
|
||||
? MyTheme.color(context).text
|
||||
: MyTheme.color(context).lightText))));
|
||||
Widget _actionMore(Peer peer) {
|
||||
return FutureBuilder(
|
||||
future: widget.popupMenuEntryBuilder(context),
|
||||
initialData: const <mod_menu.PopupMenuEntry<String>>[],
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<List<mod_menu.PopupMenuEntry<String>>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Listener(
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => _iconMoreHover.value = true,
|
||||
onExit: (_) => _iconMoreHover.value = false,
|
||||
child: CircleAvatar(
|
||||
radius: 14,
|
||||
backgroundColor: _iconMoreHover.value
|
||||
? MyTheme.color(context).grayBg!
|
||||
: MyTheme.color(context).bg!,
|
||||
child: mod_menu.PopupMenuButton(
|
||||
padding: EdgeInsets.zero,
|
||||
icon: Icon(Icons.more_vert,
|
||||
size: 18,
|
||||
color: _iconMoreHover.value
|
||||
? MyTheme.color(context).text
|
||||
: MyTheme.color(context).lightText),
|
||||
position: mod_menu.PopupMenuPosition.under,
|
||||
itemBuilder: (BuildContext context) => snapshot.data!,
|
||||
))));
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Get the image for the current [platform].
|
||||
Widget _getPlatformImage(String platform, double size) {
|
||||
platform = platform.toLowerCase();
|
||||
if (platform == 'mac os') {
|
||||
platform = 'mac';
|
||||
} else if (platform != 'linux' && platform != 'android') {
|
||||
platform = 'win';
|
||||
}
|
||||
return Image.asset('assets/$platform.png', height: size, width: size);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
abstract class BasePeerCard extends StatelessWidget {
|
||||
final RxString alias = ''.obs;
|
||||
final Peer peer;
|
||||
|
||||
BasePeerCard({required this.peer, Key? key}) : super(key: key) {
|
||||
bind
|
||||
.mainGetPeerOption(id: peer.id, key: 'alias')
|
||||
.then((value) => alias.value = value);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _PeerCard(
|
||||
peer: peer,
|
||||
alias: alias,
|
||||
connect: (BuildContext context, String id) => _connect(context, id),
|
||||
popupMenuEntryBuilder: _buildPopupMenuEntry,
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<mod_menu.PopupMenuEntry<String>>> _buildPopupMenuEntry(
|
||||
BuildContext context) async =>
|
||||
(await _buildMenuItems(context))
|
||||
.map((e) => e.build(
|
||||
context,
|
||||
const MenuConfig(
|
||||
commonColor: _PopupMenuTheme.commonColor,
|
||||
height: _PopupMenuTheme.height,
|
||||
dividerHeight: _PopupMenuTheme.dividerHeight)))
|
||||
.expand((i) => i)
|
||||
.toList();
|
||||
|
||||
@protected
|
||||
Future<List<MenuEntryBase<String>>> _buildMenuItems(BuildContext context);
|
||||
|
||||
/// Connect to a peer with [id].
|
||||
/// If [isFileTransfer], starts a session only for file transfer.
|
||||
/// If [isTcpTunneling], starts a session only for tcp tunneling.
|
||||
/// If [isRDP], starts a session only for rdp.
|
||||
void _connect(String id,
|
||||
void _connect(BuildContext context, String id,
|
||||
{bool isFileTransfer = false,
|
||||
bool isTcpTunneling = false,
|
||||
bool isRDP = false}) async {
|
||||
@ -296,11 +348,11 @@ class _PeerCardState extends State<_PeerCard>
|
||||
assert(!(isFileTransfer && isTcpTunneling && isRDP),
|
||||
"more than one connect type");
|
||||
if (isFileTransfer) {
|
||||
await rustDeskWinManager.new_file_transfer(id);
|
||||
await rustDeskWinManager.newFileTransfer(id);
|
||||
} else if (isTcpTunneling || isRDP) {
|
||||
await rustDeskWinManager.new_port_forward(id, isRDP);
|
||||
await rustDeskWinManager.newPortForward(id, isRDP);
|
||||
} else {
|
||||
await rustDeskWinManager.new_remote_desktop(id);
|
||||
await rustDeskWinManager.newRemoteDesktop(id);
|
||||
}
|
||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||
if (!currentFocus.hasPrimaryFocus) {
|
||||
@ -308,105 +360,377 @@ class _PeerCardState extends State<_PeerCard>
|
||||
}
|
||||
}
|
||||
|
||||
/// Show the peer menu and handle user's choice.
|
||||
/// User might remove the peer or send a file to the peer.
|
||||
void _showPeerMenu(BuildContext context, String id) async {
|
||||
var value = await showMenu(
|
||||
context: context,
|
||||
position: _menuPos,
|
||||
items: await super.widget.popupMenuItemsFunc(),
|
||||
elevation: 8,
|
||||
);
|
||||
if (value == 'connect') {
|
||||
_connect(id);
|
||||
} else if (value == 'file') {
|
||||
_connect(id, isFileTransfer: true);
|
||||
} else if (value == 'tcp-tunnel') {
|
||||
_connect(id, isTcpTunneling: true);
|
||||
} else if (value == 'RDP') {
|
||||
_connect(id, isRDP: true);
|
||||
} else if (value == 'remove') {
|
||||
await bind.mainRemovePeer(id: id);
|
||||
removePreference(id);
|
||||
Get.forceAppUpdate(); // TODO use inner model / state
|
||||
} else if (value == 'add-fav') {
|
||||
final favs = (await bind.mainGetFav()).toList();
|
||||
if (favs.indexOf(id) < 0) {
|
||||
favs.add(id);
|
||||
bind.mainStoreFav(favs: favs);
|
||||
}
|
||||
} else if (value == 'remove-fav') {
|
||||
final favs = (await bind.mainGetFav()).toList();
|
||||
if (favs.remove(id)) {
|
||||
bind.mainStoreFav(favs: favs);
|
||||
Get.forceAppUpdate(); // TODO use inner model / state
|
||||
}
|
||||
} else if (value == 'ab-delete') {
|
||||
gFFI.abModel.deletePeer(id);
|
||||
await gFFI.abModel.updateAb();
|
||||
setState(() {});
|
||||
} else if (value == 'ab-edit-tag') {
|
||||
_abEditTag(id);
|
||||
} else if (value == 'rename') {
|
||||
_rename(id);
|
||||
} else if (value == 'unremember-password') {
|
||||
await bind.mainForgetPassword(id: id);
|
||||
} else if (value == 'force-always-relay') {
|
||||
String value;
|
||||
String oldValue =
|
||||
await bind.mainGetPeerOption(id: id, key: 'force-always-relay');
|
||||
if (oldValue.isEmpty) {
|
||||
value = 'Y';
|
||||
} else {
|
||||
value = '';
|
||||
}
|
||||
await bind.mainSetPeerOption(
|
||||
id: id, key: 'force-always-relay', value: value);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildTag(String tagName, RxList<dynamic> rxTags,
|
||||
{Function()? onTap}) {
|
||||
return ContextMenuArea(
|
||||
width: 100,
|
||||
builder: (context) => [
|
||||
ListTile(
|
||||
title: Text(translate("Delete")),
|
||||
onTap: () {
|
||||
gFFI.abModel.deleteTag(tagName);
|
||||
gFFI.abModel.updateAb();
|
||||
Future.delayed(Duration.zero, () => Get.back());
|
||||
},
|
||||
)
|
||||
],
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Obx(
|
||||
() => Container(
|
||||
decoration: BoxDecoration(
|
||||
color: rxTags.contains(tagName) ? Colors.blue : null,
|
||||
border: Border.all(color: MyTheme.darkGray),
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
margin: EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
||||
padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
||||
child: Text(
|
||||
tagName,
|
||||
style: TextStyle(
|
||||
color: rxTags.contains(tagName) ? MyTheme.white : null),
|
||||
),
|
||||
),
|
||||
),
|
||||
MenuEntryBase<String> _connectCommonAction(
|
||||
BuildContext context, String id, String title,
|
||||
{bool isFileTransfer = false,
|
||||
bool isTcpTunneling = false,
|
||||
bool isRDP = false}) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate(title),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
_connect(
|
||||
context,
|
||||
peer.id,
|
||||
isFileTransfer: isFileTransfer,
|
||||
isTcpTunneling: isTcpTunneling,
|
||||
isRDP: isRDP,
|
||||
);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// Get the image for the current [platform].
|
||||
Widget _getPlatformImage(String platform, double size) {
|
||||
platform = platform.toLowerCase();
|
||||
if (platform == 'mac os')
|
||||
platform = 'mac';
|
||||
else if (platform != 'linux' && platform != 'android') platform = 'win';
|
||||
return Image.asset('assets/$platform.png', height: size, width: size);
|
||||
@protected
|
||||
MenuEntryBase<String> _connectAction(BuildContext context, String id) {
|
||||
return _connectCommonAction(context, id, 'Connect');
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _transferFileAction(BuildContext context, String id) {
|
||||
return _connectCommonAction(
|
||||
context,
|
||||
id,
|
||||
'Transfer File',
|
||||
isFileTransfer: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _tcpTunnelingAction(BuildContext context, String id) {
|
||||
return _connectCommonAction(
|
||||
context,
|
||||
id,
|
||||
'TCP Tunneling',
|
||||
isTcpTunneling: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _rdpAction(BuildContext context, String id) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Row(
|
||||
children: [
|
||||
Text(
|
||||
translate('RDP'),
|
||||
style: style,
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () => _rdpDialog(id),
|
||||
)
|
||||
],
|
||||
),
|
||||
proc: () {
|
||||
_connect(context, id, isRDP: true);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
Future<MenuEntryBase<String>> _forceAlwaysRelayAction(String id) async {
|
||||
const option = 'force-always-relay';
|
||||
return MenuEntrySwitch<String>(
|
||||
text: translate('Always connect via relay'),
|
||||
getter: () async {
|
||||
return (await bind.mainGetPeerOption(id: id, key: option)).isNotEmpty;
|
||||
},
|
||||
setter: (bool v) async {
|
||||
String value;
|
||||
String oldValue = await bind.mainGetPeerOption(id: id, key: option);
|
||||
if (oldValue.isEmpty) {
|
||||
value = 'Y';
|
||||
} else {
|
||||
value = '';
|
||||
}
|
||||
await bind.mainSetPeerOption(id: id, key: option, value: value);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _renameAction(String id, bool isAddressBook) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Rename'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
_rename(id, isAddressBook);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _removeAction(
|
||||
String id, Future<void> Function() reloadFunc) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Remove'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
() async {
|
||||
await bind.mainRemovePeer(id: id);
|
||||
removePreference(id);
|
||||
await reloadFunc();
|
||||
// Get.forceAppUpdate(); // TODO use inner model / state
|
||||
}();
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _unrememberPasswordAction(String id) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Unremember Password'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
bind.mainForgetPassword(id: id);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _addFavAction(String id) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Add to Favorites'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
() async {
|
||||
final favs = (await bind.mainGetFav()).toList();
|
||||
if (!favs.contains(id)) {
|
||||
favs.add(id);
|
||||
bind.mainStoreFav(favs: favs);
|
||||
}
|
||||
}();
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _rmFavAction(String id) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Remove from Favorites'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
() async {
|
||||
final favs = (await bind.mainGetFav()).toList();
|
||||
if (favs.remove(id)) {
|
||||
bind.mainStoreFav(favs: favs);
|
||||
Get.forceAppUpdate(); // TODO use inner model / state
|
||||
}
|
||||
}();
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
void _rename(String id, bool isAddressBook) async {
|
||||
RxBool isInProgress = false.obs;
|
||||
var name = await bind.mainGetPeerOption(id: id, key: 'alias');
|
||||
var controller = TextEditingController(text: name);
|
||||
if (isAddressBook) {
|
||||
final peer = gFFI.abModel.peers.firstWhere((p) => id == p['id']);
|
||||
if (peer == null) {
|
||||
// this should not happen
|
||||
} else {
|
||||
name = peer['alias'] ?? '';
|
||||
}
|
||||
}
|
||||
gFFI.dialogManager.show((setState, close) {
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate('Rename')),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Form(
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(border: OutlineInputBorder()),
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() => Offstage(
|
||||
offstage: isInProgress.isFalse,
|
||||
child: LinearProgressIndicator())),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
close();
|
||||
},
|
||||
child: Text(translate("Cancel"))),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
isInProgress.value = true;
|
||||
name = controller.text;
|
||||
await bind.mainSetPeerOption(id: id, key: 'alias', value: name);
|
||||
if (isAddressBook) {
|
||||
gFFI.abModel.setPeerOption(id, 'alias', name);
|
||||
await gFFI.abModel.updateAb();
|
||||
}
|
||||
alias.value =
|
||||
await bind.mainGetPeerOption(id: peer.id, key: 'alias');
|
||||
close();
|
||||
isInProgress.value = false;
|
||||
},
|
||||
child: Text(translate("OK"))),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class RecentPeerCard extends BasePeerCard {
|
||||
RecentPeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key);
|
||||
|
||||
@override
|
||||
Future<List<MenuEntryBase<String>>> _buildMenuItems(
|
||||
BuildContext context) async {
|
||||
final List<MenuEntryBase<String>> menuItems = [
|
||||
_connectAction(context, peer.id),
|
||||
_transferFileAction(context, peer.id),
|
||||
_tcpTunnelingAction(context, peer.id),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
menuItems.add(_rdpAction(context, peer.id));
|
||||
}
|
||||
menuItems.add(await _forceAlwaysRelayAction(peer.id));
|
||||
menuItems.add(_renameAction(peer.id, false));
|
||||
menuItems.add(_removeAction(peer.id, () async {
|
||||
await bind.mainLoadRecentPeers();
|
||||
}));
|
||||
menuItems.add(_unrememberPasswordAction(peer.id));
|
||||
menuItems.add(_addFavAction(peer.id));
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
|
||||
class FavoritePeerCard extends BasePeerCard {
|
||||
FavoritePeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key);
|
||||
|
||||
@override
|
||||
Future<List<MenuEntryBase<String>>> _buildMenuItems(
|
||||
BuildContext context) async {
|
||||
final List<MenuEntryBase<String>> menuItems = [
|
||||
_connectAction(context, peer.id),
|
||||
_transferFileAction(context, peer.id),
|
||||
_tcpTunnelingAction(context, peer.id),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
menuItems.add(_rdpAction(context, peer.id));
|
||||
}
|
||||
menuItems.add(await _forceAlwaysRelayAction(peer.id));
|
||||
menuItems.add(_renameAction(peer.id, false));
|
||||
menuItems.add(_removeAction(peer.id, () async {
|
||||
await bind.mainLoadFavPeers();
|
||||
}));
|
||||
menuItems.add(_unrememberPasswordAction(peer.id));
|
||||
menuItems.add(_rmFavAction(peer.id));
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
|
||||
class DiscoveredPeerCard extends BasePeerCard {
|
||||
DiscoveredPeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key);
|
||||
|
||||
@override
|
||||
Future<List<MenuEntryBase<String>>> _buildMenuItems(
|
||||
BuildContext context) async {
|
||||
final List<MenuEntryBase<String>> menuItems = [
|
||||
_connectAction(context, peer.id),
|
||||
_transferFileAction(context, peer.id),
|
||||
_tcpTunnelingAction(context, peer.id),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
menuItems.add(_rdpAction(context, peer.id));
|
||||
}
|
||||
menuItems.add(await _forceAlwaysRelayAction(peer.id));
|
||||
menuItems.add(_renameAction(peer.id, false));
|
||||
menuItems.add(_removeAction(peer.id, () async {
|
||||
await bind.mainLoadLanPeers();
|
||||
}));
|
||||
menuItems.add(_unrememberPasswordAction(peer.id));
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
|
||||
class AddressBookPeerCard extends BasePeerCard {
|
||||
AddressBookPeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key);
|
||||
|
||||
@override
|
||||
Future<List<MenuEntryBase<String>>> _buildMenuItems(
|
||||
BuildContext context) async {
|
||||
final List<MenuEntryBase<String>> menuItems = [
|
||||
_connectAction(context, peer.id),
|
||||
_transferFileAction(context, peer.id),
|
||||
_tcpTunnelingAction(context, peer.id),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
menuItems.add(_rdpAction(context, peer.id));
|
||||
}
|
||||
menuItems.add(await _forceAlwaysRelayAction(peer.id));
|
||||
menuItems.add(_renameAction(peer.id, false));
|
||||
menuItems.add(_removeAction(peer.id, () async {}));
|
||||
menuItems.add(_unrememberPasswordAction(peer.id));
|
||||
menuItems.add(_addFavAction(peer.id));
|
||||
menuItems.add(_editTagAction(peer.id));
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
@protected
|
||||
@override
|
||||
MenuEntryBase<String> _removeAction(
|
||||
String id, Future<void> Function() reloadFunc) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Remove'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
() async {
|
||||
gFFI.abModel.deletePeer(id);
|
||||
await gFFI.abModel.updateAb();
|
||||
}();
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
MenuEntryBase<String> _editTagAction(String id) {
|
||||
return MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
translate('Edit Tag'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
_abEditTag(id);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
);
|
||||
}
|
||||
|
||||
void _abEditTag(String id) {
|
||||
@ -459,205 +783,40 @@ class _PeerCardState extends State<_PeerCard>
|
||||
});
|
||||
}
|
||||
|
||||
void _rename(String id) async {
|
||||
var isInProgress = false;
|
||||
var name = await bind.mainGetPeerOption(id: id, key: 'alias');
|
||||
var controller = TextEditingController(text: name);
|
||||
if (widget.type == PeerType.ab) {
|
||||
final peer = gFFI.abModel.peers.firstWhere((p) => id == p['id']);
|
||||
if (peer == null) {
|
||||
// this should not happen
|
||||
} else {
|
||||
name = peer['alias'] ?? "";
|
||||
}
|
||||
}
|
||||
gFFI.dialogManager.show((setState, close) {
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Rename")),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Form(
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(border: OutlineInputBorder()),
|
||||
),
|
||||
),
|
||||
Widget _buildTag(String tagName, RxList<dynamic> rxTags,
|
||||
{Function()? onTap}) {
|
||||
return ContextMenuArea(
|
||||
width: 100,
|
||||
builder: (context) => [
|
||||
ListTile(
|
||||
title: Text(translate("Delete")),
|
||||
onTap: () {
|
||||
gFFI.abModel.deleteTag(tagName);
|
||||
gFFI.abModel.updateAb();
|
||||
Future.delayed(Duration.zero, () => Get.back());
|
||||
},
|
||||
)
|
||||
],
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Obx(
|
||||
() => Container(
|
||||
decoration: BoxDecoration(
|
||||
color: rxTags.contains(tagName) ? Colors.blue : null,
|
||||
border: Border.all(color: MyTheme.darkGray),
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
margin: EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
||||
padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
||||
child: Text(
|
||||
tagName,
|
||||
style: TextStyle(
|
||||
color: rxTags.contains(tagName) ? MyTheme.white : null),
|
||||
),
|
||||
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
close();
|
||||
},
|
||||
child: Text(translate("Cancel"))),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
isInProgress = true;
|
||||
});
|
||||
name = controller.text;
|
||||
await bind.mainSetPeerOption(id: id, key: 'alias', value: name);
|
||||
if (widget.type == PeerType.ab) {
|
||||
gFFI.abModel.setPeerOption(id, 'alias', name);
|
||||
await gFFI.abModel.updateAb();
|
||||
} else {
|
||||
Future.delayed(Duration.zero, () {
|
||||
this.setState(() {});
|
||||
});
|
||||
}
|
||||
close();
|
||||
setState(() {
|
||||
isInProgress = false;
|
||||
});
|
||||
},
|
||||
child: Text(translate("OK"))),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
abstract class BasePeerCard extends StatelessWidget {
|
||||
final Peer peer;
|
||||
final PeerType type;
|
||||
|
||||
BasePeerCard({required this.peer, required this.type, Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _PeerCard(
|
||||
peer: peer,
|
||||
popupMenuItemsFunc: _getPopupMenuItems,
|
||||
type: type,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems();
|
||||
}
|
||||
|
||||
class RecentPeerCard extends BasePeerCard {
|
||||
RecentPeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key, type: PeerType.recent);
|
||||
|
||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||
var items = [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Connect')), value: 'connect'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Transfer File')), value: 'file'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
||||
await _forceAlwaysRelayMenuItem(peer.id),
|
||||
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
||||
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Unremember Password')),
|
||||
value: 'unremember-password'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
items.insert(3, _rdpMenuItem(peer.id));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
class FavoritePeerCard extends BasePeerCard {
|
||||
FavoritePeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key, type: PeerType.fav);
|
||||
|
||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||
var items = [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Connect')), value: 'connect'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Transfer File')), value: 'file'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
||||
await _forceAlwaysRelayMenuItem(peer.id),
|
||||
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
||||
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Unremember Password')),
|
||||
value: 'unremember-password'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Remove from Favorites')), value: 'remove-fav'),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
items.insert(3, _rdpMenuItem(peer.id));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
class DiscoveredPeerCard extends BasePeerCard {
|
||||
DiscoveredPeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key, type: PeerType.discovered);
|
||||
|
||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||
var items = [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Connect')), value: 'connect'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Transfer File')), value: 'file'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
||||
await _forceAlwaysRelayMenuItem(peer.id),
|
||||
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
||||
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Unremember Password')),
|
||||
value: 'unremember-password'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
items.insert(3, _rdpMenuItem(peer.id));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
class AddressBookPeerCard extends BasePeerCard {
|
||||
AddressBookPeerCard({required Peer peer, Key? key})
|
||||
: super(peer: peer, key: key, type: PeerType.ab);
|
||||
|
||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||
var items = [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Connect')), value: 'connect'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Transfer File')), value: 'file'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
||||
await _forceAlwaysRelayMenuItem(peer.id),
|
||||
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Remove')), value: 'ab-delete'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Unremember Password')),
|
||||
value: 'unremember-password'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Edit Tag')), value: 'ab-edit-tag'),
|
||||
];
|
||||
if (peer.platform == 'Windows') {
|
||||
items.insert(3, _rdpMenuItem(peer.id));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
Future<PopupMenuItem<String>> _forceAlwaysRelayMenuItem(String id) async {
|
||||
|
@ -2,7 +2,6 @@ import 'dart:core';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
import './material_mod_popup_menu.dart' as mod_menu;
|
||||
|
||||
@ -97,6 +96,9 @@ class MenuConfig {
|
||||
}
|
||||
|
||||
abstract class MenuEntryBase<T> {
|
||||
bool dismissOnClicked;
|
||||
|
||||
MenuEntryBase({this.dismissOnClicked = false});
|
||||
List<mod_menu.PopupMenuEntry<T>> build(BuildContext context, MenuConfig conf);
|
||||
}
|
||||
|
||||
@ -112,9 +114,19 @@ class MenuEntryDivider<T> extends MenuEntryBase<T> {
|
||||
}
|
||||
}
|
||||
|
||||
typedef RadioOptionsGetter = List<Tuple2<String, String>> Function();
|
||||
class MenuEntryRadioOption {
|
||||
String text;
|
||||
String value;
|
||||
bool dismissOnClicked;
|
||||
|
||||
MenuEntryRadioOption(
|
||||
{required this.text, required this.value, this.dismissOnClicked = false});
|
||||
}
|
||||
|
||||
typedef RadioOptionsGetter = List<MenuEntryRadioOption> Function();
|
||||
typedef RadioCurOptionGetter = Future<String> Function();
|
||||
typedef RadioOptionSetter = Future<void> Function(String);
|
||||
typedef RadioOptionSetter = Future<void> Function(
|
||||
String oldValue, String newValue);
|
||||
|
||||
class MenuEntryRadioUtils<T> {}
|
||||
|
||||
@ -129,24 +141,28 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
|
||||
{required this.text,
|
||||
required this.optionsGetter,
|
||||
required this.curOptionGetter,
|
||||
required this.optionSetter}) {
|
||||
required this.optionSetter,
|
||||
dismissOnClicked = false})
|
||||
: super(dismissOnClicked: dismissOnClicked) {
|
||||
() async {
|
||||
_curOption.value = await curOptionGetter();
|
||||
}();
|
||||
}
|
||||
|
||||
List<Tuple2<String, String>> get options => optionsGetter();
|
||||
List<MenuEntryRadioOption> get options => optionsGetter();
|
||||
RxString get curOption => _curOption;
|
||||
setOption(String option) async {
|
||||
await optionSetter(option);
|
||||
final opt = await curOptionGetter();
|
||||
if (_curOption.value != opt) {
|
||||
_curOption.value = opt;
|
||||
await optionSetter(_curOption.value, option);
|
||||
if (_curOption.value != option) {
|
||||
final opt = await curOptionGetter();
|
||||
if (_curOption.value != opt) {
|
||||
_curOption.value = opt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod_menu.PopupMenuEntry<T> _buildMenuItem(
|
||||
BuildContext context, MenuConfig conf, Tuple2<String, String> opt) {
|
||||
BuildContext context, MenuConfig conf, MenuEntryRadioOption opt) {
|
||||
return mod_menu.PopupMenuItem(
|
||||
padding: EdgeInsets.zero,
|
||||
height: conf.height,
|
||||
@ -157,7 +173,7 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
opt.item1,
|
||||
opt.text,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: MenuConfig.fontSize,
|
||||
@ -169,7 +185,7 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
|
||||
child: SizedBox(
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
child: Obx(() => opt.item2 == curOption.value
|
||||
child: Obx(() => opt.value == curOption.value
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: conf.commonColor,
|
||||
@ -180,9 +196,10 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (opt.item2 != curOption.value) {
|
||||
setOption(opt.item2);
|
||||
if (opt.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
setOption(opt.value);
|
||||
},
|
||||
),
|
||||
);
|
||||
@ -206,24 +223,28 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
|
||||
{required this.text,
|
||||
required this.optionsGetter,
|
||||
required this.curOptionGetter,
|
||||
required this.optionSetter}) {
|
||||
required this.optionSetter,
|
||||
dismissOnClicked = false})
|
||||
: super(dismissOnClicked: dismissOnClicked) {
|
||||
() async {
|
||||
_curOption.value = await curOptionGetter();
|
||||
}();
|
||||
}
|
||||
|
||||
List<Tuple2<String, String>> get options => optionsGetter();
|
||||
List<MenuEntryRadioOption> get options => optionsGetter();
|
||||
RxString get curOption => _curOption;
|
||||
setOption(String option) async {
|
||||
await optionSetter(option);
|
||||
final opt = await curOptionGetter();
|
||||
if (_curOption.value != opt) {
|
||||
_curOption.value = opt;
|
||||
await optionSetter(_curOption.value, option);
|
||||
if (_curOption.value != option) {
|
||||
final opt = await curOptionGetter();
|
||||
if (_curOption.value != opt) {
|
||||
_curOption.value = opt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod_menu.PopupMenuEntry<T> _buildSecondMenu(
|
||||
BuildContext context, MenuConfig conf, Tuple2<String, String> opt) {
|
||||
BuildContext context, MenuConfig conf, MenuEntryRadioOption opt) {
|
||||
return mod_menu.PopupMenuItem(
|
||||
padding: EdgeInsets.zero,
|
||||
height: conf.height,
|
||||
@ -234,7 +255,7 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
opt.item1,
|
||||
opt.text,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: MenuConfig.fontSize,
|
||||
@ -246,7 +267,7 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
|
||||
child: SizedBox(
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
child: Obx(() => opt.item2 == curOption.value
|
||||
child: Obx(() => opt.value == curOption.value
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: conf.commonColor,
|
||||
@ -257,9 +278,10 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (opt.item2 != curOption.value) {
|
||||
setOption(opt.item2);
|
||||
if (opt.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
setOption(opt.value);
|
||||
},
|
||||
),
|
||||
);
|
||||
@ -303,7 +325,8 @@ typedef SwitchSetter = Future<void> Function(bool);
|
||||
abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
|
||||
final String text;
|
||||
|
||||
MenuEntrySwitchBase({required this.text});
|
||||
MenuEntrySwitchBase({required this.text, required dismissOnClicked})
|
||||
: super(dismissOnClicked: dismissOnClicked);
|
||||
|
||||
RxBool get curOption;
|
||||
Future<void> setOption(bool option);
|
||||
@ -315,29 +338,40 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
|
||||
mod_menu.PopupMenuItem(
|
||||
padding: EdgeInsets.zero,
|
||||
height: conf.height,
|
||||
child: Obx(
|
||||
() => SwitchListTile(
|
||||
value: curOption.value,
|
||||
onChanged: (v) {
|
||||
setOption(v);
|
||||
},
|
||||
title: Container(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
constraints: BoxConstraints(minHeight: conf.height),
|
||||
child: Text(
|
||||
child: TextButton(
|
||||
child: Container(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
height: conf.height,
|
||||
child: Row(children: [
|
||||
// const SizedBox(width: MenuConfig.midPadding),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: MenuConfig.fontSize,
|
||||
fontWeight: FontWeight.normal),
|
||||
)),
|
||||
dense: true,
|
||||
visualDensity: const VisualDensity(
|
||||
horizontal: VisualDensity.minimumDensity,
|
||||
vertical: VisualDensity.minimumDensity,
|
||||
),
|
||||
contentPadding: const EdgeInsets.only(left: 8.0),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Obx(() => Switch(
|
||||
value: curOption.value,
|
||||
onChanged: (v) {
|
||||
if (super.dismissOnClicked &&
|
||||
Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
setOption(v);
|
||||
},
|
||||
)),
|
||||
))
|
||||
])),
|
||||
onPressed: () {
|
||||
if (super.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
setOption(!curOption.value);
|
||||
},
|
||||
),
|
||||
)
|
||||
];
|
||||
@ -350,8 +384,11 @@ class MenuEntrySwitch<T> extends MenuEntrySwitchBase<T> {
|
||||
final RxBool _curOption = false.obs;
|
||||
|
||||
MenuEntrySwitch(
|
||||
{required String text, required this.getter, required this.setter})
|
||||
: super(text: text) {
|
||||
{required String text,
|
||||
required this.getter,
|
||||
required this.setter,
|
||||
dismissOnClicked = false})
|
||||
: super(text: text, dismissOnClicked: dismissOnClicked) {
|
||||
() async {
|
||||
_curOption.value = await getter();
|
||||
}();
|
||||
@ -377,8 +414,11 @@ class MenuEntrySwitch2<T> extends MenuEntrySwitchBase<T> {
|
||||
final SwitchSetter setter;
|
||||
|
||||
MenuEntrySwitch2(
|
||||
{required String text, required this.getter, required this.setter})
|
||||
: super(text: text);
|
||||
{required String text,
|
||||
required this.getter,
|
||||
required this.setter,
|
||||
dismissOnClicked = false})
|
||||
: super(text: text, dismissOnClicked: dismissOnClicked);
|
||||
|
||||
@override
|
||||
RxBool get curOption => getter();
|
||||
@ -392,10 +432,7 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
|
||||
final String text;
|
||||
final List<MenuEntryBase<T>> entries;
|
||||
|
||||
MenuEntrySubMenu({
|
||||
required this.text,
|
||||
required this.entries,
|
||||
});
|
||||
MenuEntrySubMenu({required this.text, required this.entries});
|
||||
|
||||
@override
|
||||
List<mod_menu.PopupMenuEntry<T>> build(
|
||||
@ -436,10 +473,11 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
|
||||
final Widget Function(TextStyle? style) childBuilder;
|
||||
Function() proc;
|
||||
|
||||
MenuEntryButton({
|
||||
required this.childBuilder,
|
||||
required this.proc,
|
||||
});
|
||||
MenuEntryButton(
|
||||
{required this.childBuilder,
|
||||
required this.proc,
|
||||
dismissOnClicked = false})
|
||||
: super(dismissOnClicked: dismissOnClicked);
|
||||
|
||||
@override
|
||||
List<mod_menu.PopupMenuEntry<T>> build(
|
||||
@ -459,6 +497,9 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
|
||||
fontWeight: FontWeight.normal),
|
||||
)),
|
||||
onPressed: () {
|
||||
if (super.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
proc();
|
||||
},
|
||||
),
|
||||
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:rxdart/rxdart.dart' as rxdart;
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../mobile/widgets/dialog.dart';
|
||||
@ -16,7 +16,7 @@ import './material_mod_popup_menu.dart' as mod_menu;
|
||||
class _MenubarTheme {
|
||||
static const Color commonColor = MyTheme.accent;
|
||||
// kMinInteractiveDimension
|
||||
static const double height = 24.0;
|
||||
static const double height = 25.0;
|
||||
static const double dividerHeight = 12.0;
|
||||
}
|
||||
|
||||
@ -290,9 +290,9 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
bind.sessionRefresh(id: widget.id);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
}
|
||||
displayMenu.add(MenuEntryButton<String>(
|
||||
@ -301,9 +301,9 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
showSetOSPassword(widget.id, false, widget.ffi.dialogManager);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
|
||||
if (!isWebDesktop) {
|
||||
@ -314,7 +314,6 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
() async {
|
||||
ClipboardData? data =
|
||||
await Clipboard.getData(Clipboard.kTextPlain);
|
||||
@ -323,6 +322,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
}
|
||||
}();
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
}
|
||||
|
||||
@ -332,9 +332,9 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
widget.ffi.cursorModel.reset();
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
}
|
||||
|
||||
@ -346,9 +346,9 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
bind.sessionCtrlAltDel(id: widget.id);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
}
|
||||
|
||||
@ -358,9 +358,9 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
bind.sessionLockScreen(id: widget.id);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
|
||||
if (pi.platform == 'Windows') {
|
||||
@ -371,13 +371,13 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
)),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
RxBool blockInput = BlockInputState.find(widget.id);
|
||||
bind.sessionToggleOption(
|
||||
id: widget.id,
|
||||
value: '${blockInput.value ? "un" : ""}block-input');
|
||||
blockInput.value = !blockInput.value;
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -392,9 +392,9 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
Navigator.pop(context);
|
||||
showRestartRemoteDevice(pi, widget.id, gFFI.dialogManager);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
));
|
||||
}
|
||||
|
||||
@ -406,45 +406,54 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
MenuEntryRadios<String>(
|
||||
text: translate('Ratio'),
|
||||
optionsGetter: () => [
|
||||
Tuple2<String, String>(translate('Original'), 'original'),
|
||||
Tuple2<String, String>(translate('Shrink'), 'shrink'),
|
||||
Tuple2<String, String>(translate('Stretch'), 'stretch'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Scale original'), value: 'original'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Scale adaptive'), value: 'adaptive'),
|
||||
],
|
||||
curOptionGetter: () async {
|
||||
return await bind.sessionGetOption(
|
||||
id: widget.id, arg: 'view-style') ??
|
||||
'';
|
||||
'adaptive';
|
||||
},
|
||||
optionSetter: (String v) async {
|
||||
optionSetter: (String oldValue, String newValue) async {
|
||||
await bind.sessionPeerOption(
|
||||
id: widget.id, name: "view-style", value: v);
|
||||
id: widget.id, name: "view-style", value: newValue);
|
||||
widget.ffi.canvasModel.updateViewStyle();
|
||||
}),
|
||||
MenuEntryDivider<String>(),
|
||||
MenuEntryRadios<String>(
|
||||
text: translate('Scroll Style'),
|
||||
optionsGetter: () => [
|
||||
Tuple2<String, String>(translate('ScrollAuto'), 'scrollauto'),
|
||||
Tuple2<String, String>(translate('Scrollbar'), 'scrollbar'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('ScrollAuto'), value: 'scrollauto'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Scrollbar'), value: 'scrollbar'),
|
||||
],
|
||||
curOptionGetter: () async {
|
||||
return await bind.sessionGetOption(
|
||||
id: widget.id, arg: 'scroll-style') ??
|
||||
'';
|
||||
},
|
||||
optionSetter: (String v) async {
|
||||
optionSetter: (String oldValue, String newValue) async {
|
||||
await bind.sessionPeerOption(
|
||||
id: widget.id, name: "scroll-style", value: v);
|
||||
id: widget.id, name: "scroll-style", value: newValue);
|
||||
widget.ffi.canvasModel.updateScrollStyle();
|
||||
}),
|
||||
MenuEntryDivider<String>(),
|
||||
MenuEntryRadios<String>(
|
||||
text: translate('Image Quality'),
|
||||
optionsGetter: () => [
|
||||
Tuple2<String, String>(translate('Good image quality'), 'best'),
|
||||
Tuple2<String, String>(translate('Balanced'), 'balanced'),
|
||||
Tuple2<String, String>(
|
||||
translate('Optimize reaction time'), 'low'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Good image quality'), value: 'best'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Balanced'), value: 'balanced'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Optimize reaction time'), value: 'low'),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Custom'),
|
||||
value: 'custom',
|
||||
dismissOnClicked: true),
|
||||
],
|
||||
curOptionGetter: () async {
|
||||
String quality =
|
||||
@ -452,8 +461,46 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
if (quality == '') quality = 'balanced';
|
||||
return quality;
|
||||
},
|
||||
optionSetter: (String v) async {
|
||||
await bind.sessionSetImageQuality(id: widget.id, value: v);
|
||||
optionSetter: (String oldValue, String newValue) async {
|
||||
if (oldValue != newValue) {
|
||||
await bind.sessionSetImageQuality(id: widget.id, value: newValue);
|
||||
}
|
||||
|
||||
if (newValue == 'custom') {
|
||||
final btnCancel = msgBoxButton(translate('Close'), () {
|
||||
widget.ffi.dialogManager.dismissAll();
|
||||
});
|
||||
final quality =
|
||||
await bind.sessionGetCustomImageQuality(id: widget.id);
|
||||
final double initValue = quality != null && quality.isNotEmpty
|
||||
? quality[0].toDouble()
|
||||
: 50.0;
|
||||
final RxDouble sliderValue = RxDouble(initValue);
|
||||
final rxReplay = rxdart.ReplaySubject<double>();
|
||||
rxReplay
|
||||
.throttleTime(const Duration(milliseconds: 1000),
|
||||
trailing: true, leading: false)
|
||||
.listen((double v) {
|
||||
() async {
|
||||
await bind.sessionSetCustomImageQuality(
|
||||
id: widget.id, value: v.toInt());
|
||||
}();
|
||||
});
|
||||
final slider = Obx(() {
|
||||
return Slider(
|
||||
value: sliderValue.value,
|
||||
max: 100,
|
||||
divisions: 100,
|
||||
label: sliderValue.value.round().toString(),
|
||||
onChanged: (double value) {
|
||||
sliderValue.value = value;
|
||||
rxReplay.add(value);
|
||||
},
|
||||
);
|
||||
});
|
||||
msgBoxCommon(widget.ffi.dialogManager, 'Custom Image Quality',
|
||||
slider, [btnCancel]);
|
||||
}
|
||||
}),
|
||||
MenuEntryDivider<String>(),
|
||||
MenuEntrySwitch<String>(
|
||||
|
@ -7,6 +7,7 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/generated_bridge.dart';
|
||||
import 'package:flutter_hbb/models/ab_model.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
@ -300,6 +301,9 @@ class FfiModel with ChangeNotifier {
|
||||
|
||||
/// Handle the peer info event based on [evt].
|
||||
void handlePeerInfo(Map<String, dynamic> evt, String peerId) async {
|
||||
// recent peer updated by handle_peer_info(ui_session_interface.rs) --> handle_peer_info(client.rs) --> save_config(client.rs)
|
||||
bind.mainLoadRecentPeers();
|
||||
|
||||
parent.target?.dialogManager.dismissAll();
|
||||
_pi.version = evt['version'];
|
||||
_pi.username = evt['username'];
|
||||
@ -497,39 +501,11 @@ class CanvasModel with ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
|
||||
final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720);
|
||||
final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280);
|
||||
|
||||
// Closure to perform shrink operation.
|
||||
final shrinkOp = () {
|
||||
final s = s1 < s2 ? s1 : s2;
|
||||
if (s < 1) {
|
||||
_scale = s;
|
||||
}
|
||||
};
|
||||
// Closure to perform stretch operation.
|
||||
final stretchOp = () {
|
||||
final s = s1 < s2 ? s1 : s2;
|
||||
if (s > 1) {
|
||||
_scale = s;
|
||||
}
|
||||
};
|
||||
// Closure to perform default operation(set the scale to 1.0).
|
||||
final defaultOp = () {
|
||||
_scale = 1.0;
|
||||
};
|
||||
|
||||
// // On desktop, shrink is the default behavior.
|
||||
// if (isDesktop) {
|
||||
// shrinkOp();
|
||||
// } else {
|
||||
defaultOp();
|
||||
// }
|
||||
|
||||
if (style == 'shrink') {
|
||||
shrinkOp();
|
||||
} else if (style == 'stretch') {
|
||||
stretchOp();
|
||||
_scale = 1.0;
|
||||
if (style == 'adaptive') {
|
||||
final s1 = size.width / getDisplayWidth();
|
||||
final s2 = size.height / getDisplayHeight();
|
||||
_scale = s1 < s2 ? s1 : s2;
|
||||
}
|
||||
|
||||
_x = (size.width - getDisplayWidth() * _scale) / 2;
|
||||
@ -557,11 +533,17 @@ class CanvasModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
int getDisplayWidth() {
|
||||
return parent.target?.ffiModel.display.width ?? 1080;
|
||||
final defaultWidth = (isDesktop || isWebDesktop)
|
||||
? kDesktopDefaultDisplayWidth
|
||||
: kMobileDefaultDisplayWidth;
|
||||
return parent.target?.ffiModel.display.width ?? defaultWidth;
|
||||
}
|
||||
|
||||
int getDisplayHeight() {
|
||||
return parent.target?.ffiModel.display.height ?? 720;
|
||||
final defaultHeight = (isDesktop || isWebDesktop)
|
||||
? kDesktopDefaultDisplayHeight
|
||||
: kMobileDefaultDisplayHeight;
|
||||
return parent.target?.ffiModel.display.height ?? defaultHeight;
|
||||
}
|
||||
|
||||
Size get size {
|
||||
@ -577,9 +559,19 @@ class CanvasModel with ChangeNotifier {
|
||||
var dxOffset = 0;
|
||||
var dyOffset = 0;
|
||||
if (dw > size.width) {
|
||||
final X_debugNanOrInfinite = x - dw * (x / size.width) - _x;
|
||||
if (X_debugNanOrInfinite.isInfinite || X_debugNanOrInfinite.isNaN) {
|
||||
debugPrint(
|
||||
'REMOVE ME ============================ X_debugNanOrInfinite $x,$dw,$_scale,${size.width},$_x');
|
||||
}
|
||||
dxOffset = (x - dw * (x / size.width) - _x).toInt();
|
||||
}
|
||||
if (dh > size.height) {
|
||||
final Y_debugNanOrInfinite = y - dh * (y / size.height) - _y;
|
||||
if (Y_debugNanOrInfinite.isInfinite || Y_debugNanOrInfinite.isNaN) {
|
||||
debugPrint(
|
||||
'REMOVE ME ============================ Y_debugNanOrInfinite $y,$dh,$_scale,${size.height},$_y');
|
||||
}
|
||||
dyOffset = (y - dh * (y / size.height) - _y).toInt();
|
||||
}
|
||||
_x += dxOffset;
|
||||
@ -947,16 +939,16 @@ class FFI {
|
||||
late final QualityMonitorModel qualityMonitorModel; // session
|
||||
|
||||
FFI() {
|
||||
this.imageModel = ImageModel(WeakReference(this));
|
||||
this.ffiModel = FfiModel(WeakReference(this));
|
||||
this.cursorModel = CursorModel(WeakReference(this));
|
||||
this.canvasModel = CanvasModel(WeakReference(this));
|
||||
this.serverModel = ServerModel(WeakReference(this)); // use global FFI
|
||||
this.chatModel = ChatModel(WeakReference(this));
|
||||
this.fileModel = FileModel(WeakReference(this));
|
||||
this.abModel = AbModel(WeakReference(this));
|
||||
this.userModel = UserModel(WeakReference(this));
|
||||
this.qualityMonitorModel = QualityMonitorModel(WeakReference(this));
|
||||
imageModel = ImageModel(WeakReference(this));
|
||||
ffiModel = FfiModel(WeakReference(this));
|
||||
cursorModel = CursorModel(WeakReference(this));
|
||||
canvasModel = CanvasModel(WeakReference(this));
|
||||
serverModel = ServerModel(WeakReference(this)); // use global FFI
|
||||
chatModel = ChatModel(WeakReference(this));
|
||||
fileModel = FileModel(WeakReference(this));
|
||||
abModel = AbModel(WeakReference(this));
|
||||
userModel = UserModel(WeakReference(this));
|
||||
qualityMonitorModel = QualityMonitorModel(WeakReference(this));
|
||||
}
|
||||
|
||||
/// Send a mouse tap event(down and up).
|
||||
@ -1260,20 +1252,20 @@ class PeerInfo {
|
||||
Future<void> savePreference(String id, double xCursor, double yCursor,
|
||||
double xCanvas, double yCanvas, double scale, int currentDisplay) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final p = Map<String, dynamic>();
|
||||
final p = <String, dynamic>{};
|
||||
p['xCursor'] = xCursor;
|
||||
p['yCursor'] = yCursor;
|
||||
p['xCanvas'] = xCanvas;
|
||||
p['yCanvas'] = yCanvas;
|
||||
p['scale'] = scale;
|
||||
p['currentDisplay'] = currentDisplay;
|
||||
prefs.setString('peer' + id, json.encode(p));
|
||||
prefs.setString('peer$id', json.encode(p));
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getPreference(String id) async {
|
||||
if (!isWebDesktop) return null;
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var p = prefs.getString('peer' + id);
|
||||
var p = prefs.getString('peer$id');
|
||||
if (p == null) return null;
|
||||
Map<String, dynamic> m = json.decode(p);
|
||||
return m;
|
||||
@ -1281,7 +1273,7 @@ Future<Map<String, dynamic>?> getPreference(String id) async {
|
||||
|
||||
void removePreference(String id) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.remove('peer' + id);
|
||||
prefs.remove('peer$id');
|
||||
}
|
||||
|
||||
void initializeCursorAndCanvas(FFI ffi) async {
|
||||
|
@ -30,7 +30,7 @@ class PlatformFFI {
|
||||
String _dir = '';
|
||||
String _homeDir = '';
|
||||
F2? _translate;
|
||||
var _eventHandlers = Map<String, Map<String, HandleEvent>>();
|
||||
final _eventHandlers = Map<String, Map<String, HandleEvent>>();
|
||||
late RustdeskImpl _ffiBind;
|
||||
late String _appType;
|
||||
void Function(Map<String, dynamic>)? _eventCallback;
|
||||
@ -50,27 +50,27 @@ class PlatformFFI {
|
||||
}
|
||||
|
||||
bool registerEventHandler(
|
||||
String event_name, String handler_name, HandleEvent handler) {
|
||||
debugPrint('registerEventHandler $event_name $handler_name');
|
||||
var handlers = _eventHandlers[event_name];
|
||||
String eventName, String handlerName, HandleEvent handler) {
|
||||
debugPrint('registerEventHandler $eventName $handlerName');
|
||||
var handlers = _eventHandlers[eventName];
|
||||
if (handlers == null) {
|
||||
_eventHandlers[event_name] = {handler_name: handler};
|
||||
_eventHandlers[eventName] = {handlerName: handler};
|
||||
return true;
|
||||
} else {
|
||||
if (handlers.containsKey(handler_name)) {
|
||||
if (handlers.containsKey(handlerName)) {
|
||||
return false;
|
||||
} else {
|
||||
handlers[handler_name] = handler;
|
||||
handlers[handlerName] = handler;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unregisterEventHandler(String event_name, String handler_name) {
|
||||
debugPrint('unregisterEventHandler $event_name $handler_name');
|
||||
var handlers = _eventHandlers[event_name];
|
||||
void unregisterEventHandler(String eventName, String handlerName) {
|
||||
debugPrint('unregisterEventHandler $eventName $handlerName');
|
||||
var handlers = _eventHandlers[eventName];
|
||||
if (handlers != null) {
|
||||
handlers.remove(handler_name);
|
||||
handlers.remove(handlerName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,8 @@ class Peer {
|
||||
final List<dynamic> tags;
|
||||
bool online = false;
|
||||
|
||||
Peer.fromJson(String id, Map<String, dynamic> json)
|
||||
: id = id,
|
||||
username = json['username'] ?? '',
|
||||
Peer.fromJson(this.id, Map<String, dynamic> json)
|
||||
: username = json['username'] ?? '',
|
||||
hostname = json['hostname'] ?? '',
|
||||
platform = json['platform'] ?? '',
|
||||
tags = json['tags'] ?? [];
|
||||
@ -35,57 +34,52 @@ class Peer {
|
||||
}
|
||||
|
||||
class Peers extends ChangeNotifier {
|
||||
late String _name;
|
||||
late List<Peer> _peers;
|
||||
late final _loadEvent;
|
||||
final String name;
|
||||
final String loadEvent;
|
||||
List<Peer> peers;
|
||||
static const _cbQueryOnlines = 'callback_query_onlines';
|
||||
|
||||
Peers(String name, String loadEvent, List<Peer> _initPeers) {
|
||||
_name = name;
|
||||
_loadEvent = loadEvent;
|
||||
_peers = _initPeers;
|
||||
platformFFI.registerEventHandler(_cbQueryOnlines, _name, (evt) {
|
||||
Peers({required this.name, required this.peers, required this.loadEvent}) {
|
||||
platformFFI.registerEventHandler(_cbQueryOnlines, name, (evt) {
|
||||
_updateOnlineState(evt);
|
||||
});
|
||||
platformFFI.registerEventHandler(_loadEvent, _name, (evt) {
|
||||
platformFFI.registerEventHandler(loadEvent, name, (evt) {
|
||||
_updatePeers(evt);
|
||||
});
|
||||
}
|
||||
|
||||
List<Peer> get peers => _peers;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
platformFFI.unregisterEventHandler(_cbQueryOnlines, _name);
|
||||
platformFFI.unregisterEventHandler(_loadEvent, _name);
|
||||
platformFFI.unregisterEventHandler(_cbQueryOnlines, name);
|
||||
platformFFI.unregisterEventHandler(loadEvent, name);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Peer getByIndex(int index) {
|
||||
if (index < _peers.length) {
|
||||
return _peers[index];
|
||||
if (index < peers.length) {
|
||||
return peers[index];
|
||||
} else {
|
||||
return Peer.loading();
|
||||
}
|
||||
}
|
||||
|
||||
int getPeersCount() {
|
||||
return _peers.length;
|
||||
return peers.length;
|
||||
}
|
||||
|
||||
void _updateOnlineState(Map<String, dynamic> evt) {
|
||||
evt['onlines'].split(',').forEach((online) {
|
||||
for (var i = 0; i < _peers.length; i++) {
|
||||
if (_peers[i].id == online) {
|
||||
_peers[i].online = true;
|
||||
for (var i = 0; i < peers.length; i++) {
|
||||
if (peers[i].id == online) {
|
||||
peers[i].online = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
evt['offlines'].split(',').forEach((offline) {
|
||||
for (var i = 0; i < _peers.length; i++) {
|
||||
if (_peers[i].id == offline) {
|
||||
_peers[i].online = false;
|
||||
for (var i = 0; i < peers.length; i++) {
|
||||
if (peers[i].id == offline) {
|
||||
peers[i].online = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -95,19 +89,19 @@ class Peers extends ChangeNotifier {
|
||||
|
||||
void _updatePeers(Map<String, dynamic> evt) {
|
||||
final onlineStates = _getOnlineStates();
|
||||
_peers = _decodePeers(evt['peers']);
|
||||
_peers.forEach((peer) {
|
||||
peers = _decodePeers(evt['peers']);
|
||||
for (var peer in peers) {
|
||||
final state = onlineStates[peer.id];
|
||||
peer.online = state != null && state != false;
|
||||
});
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Map<String, bool> _getOnlineStates() {
|
||||
var onlineStates = new Map<String, bool>();
|
||||
_peers.forEach((peer) {
|
||||
var onlineStates = <String, bool>{};
|
||||
for (var peer in peers) {
|
||||
onlineStates[peer.id] = peer.online;
|
||||
});
|
||||
}
|
||||
return onlineStates;
|
||||
}
|
||||
|
||||
@ -121,7 +115,7 @@ class Peers extends ChangeNotifier {
|
||||
Peer.fromJson(s[0] as String, s[1] as Map<String, dynamic>))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print('peers(): $e');
|
||||
debugPrint('peers(): $e');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -37,9 +36,9 @@ class RustDeskMultiWindowManager {
|
||||
int? _fileTransferWindowId;
|
||||
int? _portForwardWindowId;
|
||||
|
||||
Future<dynamic> new_remote_desktop(String remote_id) async {
|
||||
Future<dynamic> newRemoteDesktop(String remoteId) async {
|
||||
final msg =
|
||||
jsonEncode({"type": WindowType.RemoteDesktop.index, "id": remote_id});
|
||||
jsonEncode({"type": WindowType.RemoteDesktop.index, "id": remoteId});
|
||||
|
||||
try {
|
||||
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||
@ -63,9 +62,9 @@ class RustDeskMultiWindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> new_file_transfer(String remote_id) async {
|
||||
Future<dynamic> newFileTransfer(String remoteId) async {
|
||||
final msg =
|
||||
jsonEncode({"type": WindowType.FileTransfer.index, "id": remote_id});
|
||||
jsonEncode({"type": WindowType.FileTransfer.index, "id": remoteId});
|
||||
|
||||
try {
|
||||
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||
@ -88,12 +87,9 @@ class RustDeskMultiWindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> new_port_forward(String remote_id, bool isRDP) async {
|
||||
final msg = jsonEncode({
|
||||
"type": WindowType.PortForward.index,
|
||||
"id": remote_id,
|
||||
"isRDP": isRDP
|
||||
});
|
||||
Future<dynamic> newPortForward(String remoteId, bool isRDP) async {
|
||||
final msg = jsonEncode(
|
||||
{"type": WindowType.PortForward.index, "id": remoteId, "isRDP": isRDP});
|
||||
|
||||
try {
|
||||
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||
|
@ -73,6 +73,7 @@ dependencies:
|
||||
contextmenu: ^3.0.0
|
||||
desktop_drop: ^0.3.3
|
||||
scroll_pos: ^0.3.0
|
||||
rxdart: ^0.27.5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: ^0.9.1
|
||||
|
@ -1278,11 +1278,11 @@ impl LoginConfigHandler {
|
||||
///
|
||||
/// * `username` - The name of the peer.
|
||||
/// * `pi` - The peer info.
|
||||
pub fn handle_peer_info(&mut self, pi: PeerInfo) {
|
||||
pub fn handle_peer_info(&mut self, pi: &PeerInfo) {
|
||||
if !pi.version.is_empty() {
|
||||
self.version = hbb_common::get_version_number(&pi.version);
|
||||
}
|
||||
self.features = pi.features.into_option();
|
||||
self.features = pi.features.clone().into_option();
|
||||
let serde = PeerInfoSerde {
|
||||
username: pi.username.clone(),
|
||||
hostname: pi.hostname.clone(),
|
||||
|
@ -143,14 +143,6 @@ pub fn session_get_toggle_option_sync(id: String, arg: String) -> SyncReturn<boo
|
||||
SyncReturn(res)
|
||||
}
|
||||
|
||||
pub fn session_get_image_quality(id: String) -> Option<String> {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||
Some(session.get_image_quality())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_get_option(id: String, arg: String) -> Option<String> {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||
Some(session.get_option(arg))
|
||||
@ -190,12 +182,34 @@ pub fn session_toggle_option(id: String, value: String) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_get_image_quality(id: String) -> Option<String> {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||
Some(session.get_image_quality())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_set_image_quality(id: String, value: String) {
|
||||
if let Some(session) = SESSIONS.write().unwrap().get_mut(&id) {
|
||||
session.save_image_quality(value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_get_custom_image_quality(id: String) -> Option<Vec<i32>> {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||
Some(session.get_custom_image_quality())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_set_custom_image_quality(id: String, value: i32) {
|
||||
if let Some(session) = SESSIONS.write().unwrap().get_mut(&id) {
|
||||
session.save_custom_image_quality(value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_lock_screen(id: String) {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||
session.lock_screen();
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "中继连接"),
|
||||
("Secure Connection", "安全连接"),
|
||||
("Insecure Connection", "非安全连接"),
|
||||
("Scale original", "原始尺寸"),
|
||||
("Scale adaptive", "适应窗口"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Připojení relé"),
|
||||
("Secure Connection", "Zabezpečené připojení"),
|
||||
("Insecure Connection", "Nezabezpečené připojení"),
|
||||
("Scale original", "Měřítko původní"),
|
||||
("Scale adaptive", "Měřítko adaptivní"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Relæforbindelse"),
|
||||
("Secure Connection", "Sikker forbindelse"),
|
||||
("Insecure Connection", "Usikker forbindelse"),
|
||||
("Scale original", "Skala original"),
|
||||
("Scale adaptive", "Skala adaptiv"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Relaisverbindung"),
|
||||
("Secure Connection", "Sichere Verbindung"),
|
||||
("Insecure Connection", "Unsichere Verbindung"),
|
||||
("Scale original", "Original skalieren"),
|
||||
("Scale adaptive", "Adaptiv skalieren"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Relajsa Konekto"),
|
||||
("Secure Connection", "Sekura Konekto"),
|
||||
("Insecure Connection", "Nesekura Konekto"),
|
||||
("Scale original", "Skalo originalo"),
|
||||
("Scale adaptive", "Skalo adapta"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Conexión de relé"),
|
||||
("Secure Connection", "Conexión segura"),
|
||||
("Insecure Connection", "Conexión insegura"),
|
||||
("Scale original", "escala originales"),
|
||||
("Scale adaptive", "Adaptable a escala"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Connexion relais"),
|
||||
("Secure Connection", "Connexion sécurisée"),
|
||||
("Insecure Connection", "Connexion non sécurisée"),
|
||||
("Scale original", "Échelle d'origine"),
|
||||
("Scale adaptive", "Échelle adaptative"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Relé csatlakozás"),
|
||||
("Secure Connection", "Biztonságos kapcsolat"),
|
||||
("Insecure Connection", "Nem biztonságos kapcsolat"),
|
||||
("Scale original", "Eredeti méretarány"),
|
||||
("Scale adaptive", "Skála adaptív"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Koneksi Relay"),
|
||||
("Secure Connection", "Koneksi aman"),
|
||||
("Insecure Connection", "Koneksi Tidak Aman"),
|
||||
("Scale original", "Skala asli"),
|
||||
("Scale adaptive", "Skala adaptif"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -316,5 +316,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Collegamento a relè"),
|
||||
("Secure Connection", "Connessione sicura"),
|
||||
("Insecure Connection", "Connessione insicura"),
|
||||
("Scale original", "Scala originale"),
|
||||
("Scale adaptive", "Scala adattiva"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "リレー接続"),
|
||||
("Secure Connection", "安全な接続"),
|
||||
("Insecure Connection", "安全でない接続"),
|
||||
("Scale original", "オリジナルサイズ"),
|
||||
("Scale adaptive", "フィットウィンドウ"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "릴레이 연결"),
|
||||
("Secure Connection", "보안 연결"),
|
||||
("Insecure Connection", "안전하지 않은 연결"),
|
||||
("Scale original", "원래 크기"),
|
||||
("Scale adaptive", "맞는 창"),
|
||||
].iter().cloned().collect();
|
||||
}
|
@ -318,5 +318,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Połączenie przekaźnika"),
|
||||
("Secure Connection", "Bezpieczne połączenie"),
|
||||
("Insecure Connection", "Niepewne połączenie"),
|
||||
("Scale original", "Skala oryginalna"),
|
||||
("Scale adaptive", "Skala adaptacyjna"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Conexão de relé"),
|
||||
("Secure Connection", "Conexão segura"),
|
||||
("Insecure Connection", "Conexão insegura"),
|
||||
("Scale original", "Escala original"),
|
||||
("Scale adaptive", "Escala adaptável"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", ""),
|
||||
("Secure Connection", ""),
|
||||
("Insecure Connection", ""),
|
||||
("Scale original", ""),
|
||||
("Scale adaptive", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Релейное соединение"),
|
||||
("Secure Connection", "Безопасное соединение"),
|
||||
("Insecure Connection", "Небезопасное соединение"),
|
||||
("Scale original", "Оригинал масштаба"),
|
||||
("Scale adaptive", "Масштаб адаптивный"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Reléové pripojenie"),
|
||||
("Secure Connection", "Zabezpečené pripojenie"),
|
||||
("Insecure Connection", "Nezabezpečené pripojenie"),
|
||||
("Scale original", "Pôvodná mierka"),
|
||||
("Scale adaptive", "Prispôsobivá mierka"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", ""),
|
||||
("Secure Connection", ""),
|
||||
("Insecure Connection", ""),
|
||||
("Scale original", ""),
|
||||
("Scale adaptive", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Röle Bağlantısı"),
|
||||
("Secure Connection", "Güvenli bağlantı"),
|
||||
("Insecure Connection", "Güvenli Bağlantı"),
|
||||
("Scale original", "Orijinali ölçeklendir"),
|
||||
("Scale adaptive", "Ölçek uyarlanabilir"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "中繼連接"),
|
||||
("Secure Connection", "安全連接"),
|
||||
("Insecure Connection", "非安全連接"),
|
||||
("Scale original", "原始尺寸"),
|
||||
("Scale adaptive", "適應窗口"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Relay Connection", "Kết nối chuyển tiếp"),
|
||||
("Secure Connection", "Kết nối an toàn"),
|
||||
("Insecure Connection", "Kết nối không an toàn"),
|
||||
("Scale original", "Quy mô gốc"),
|
||||
("Scale adaptive", "Quy mô thích ứng"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -47,6 +47,11 @@ impl<T: InvokeUi> Session<T> {
|
||||
self.lc.read().unwrap().image_quality.clone()
|
||||
}
|
||||
|
||||
/// Get custom image quality.
|
||||
pub fn get_custom_image_quality(&self) -> Vec<i32> {
|
||||
self.lc.read().unwrap().custom_image_quality.clone()
|
||||
}
|
||||
|
||||
pub fn save_view_style(&mut self, value: String) {
|
||||
self.lc.write().unwrap().save_view_style(value);
|
||||
}
|
||||
@ -634,7 +639,7 @@ impl<T: InvokeUi> Interface for Session<T> {
|
||||
}
|
||||
} else if !self.is_port_forward() {
|
||||
if pi.displays.is_empty() {
|
||||
self.lc.write().unwrap().handle_peer_info(pi);
|
||||
self.lc.write().unwrap().handle_peer_info(&pi);
|
||||
self.update_privacy_mode();
|
||||
self.msgbox("error", "Remote Error", "No Display");
|
||||
return;
|
||||
@ -647,9 +652,9 @@ impl<T: InvokeUi> Interface for Session<T> {
|
||||
self.set_display(current.x, current.y, current.width, current.height);
|
||||
}
|
||||
self.update_privacy_mode();
|
||||
// Save recent peers, then push event to flutter. So flutter can refresh peer page.
|
||||
self.lc.write().unwrap().handle_peer_info(&pi);
|
||||
self.set_peer_info(&pi);
|
||||
self.lc.write().unwrap().handle_peer_info(pi);
|
||||
|
||||
if self.is_file_transfer() {
|
||||
self.close_success();
|
||||
} else if !self.is_port_forward() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user