fix dialog res bug ; add desktop restart remote device
This commit is contained in:
parent
3e702c834a
commit
f99ab7d0a7
@ -92,7 +92,7 @@ typedef DialogBuilder = CustomAlertDialog Function(
|
|||||||
|
|
||||||
class Dialog<T> {
|
class Dialog<T> {
|
||||||
OverlayEntry? entry;
|
OverlayEntry? entry;
|
||||||
Completer<T?> completer = Completer<T>();
|
Completer<T?> completer = Completer<T?>();
|
||||||
|
|
||||||
Dialog();
|
Dialog();
|
||||||
|
|
||||||
@ -101,9 +101,10 @@ class Dialog<T> {
|
|||||||
if (!completer.isCompleted) {
|
if (!completer.isCompleted) {
|
||||||
completer.complete(res);
|
completer.complete(res);
|
||||||
}
|
}
|
||||||
entry?.remove();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("Dialog complete catch error: $e");
|
debugPrint("Dialog complete catch error: $e");
|
||||||
|
} finally {
|
||||||
|
entry?.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -589,11 +589,10 @@ class _RemotePageState extends State<RemotePage>
|
|||||||
more.add(PopupMenuItem<String>(
|
more.add(PopupMenuItem<String>(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: ([
|
children: ([
|
||||||
Container(width: 100.0, child: Text(translate('OS Password'))),
|
Text(translate('OS Password')),
|
||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
|
||||||
showSetOSPassword(widget.id, false, _ffi.dialogManager);
|
showSetOSPassword(widget.id, false, _ffi.dialogManager);
|
||||||
},
|
},
|
||||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||||
@ -625,6 +624,13 @@ class _RemotePageState extends State<RemotePage>
|
|||||||
value: 'block-input'));
|
value: 'block-input'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (gFFI.ffiModel.permissions["restart"] != false &&
|
||||||
|
(pi.platform == "Linux" ||
|
||||||
|
pi.platform == "Windows" ||
|
||||||
|
pi.platform == "Mac OS")) {
|
||||||
|
more.add(PopupMenuItem<String>(
|
||||||
|
child: Text(translate('Restart Remote Device')), value: 'restart'));
|
||||||
|
}
|
||||||
() async {
|
() async {
|
||||||
var value = await showMenu(
|
var value = await showMenu(
|
||||||
context: context,
|
context: context,
|
||||||
@ -652,6 +658,7 @@ class _RemotePageState extends State<RemotePage>
|
|||||||
}();
|
}();
|
||||||
} else if (value == 'enter_os_password') {
|
} else if (value == 'enter_os_password') {
|
||||||
// FIXME:
|
// FIXME:
|
||||||
|
// TODO icon diff
|
||||||
// null means no session of id
|
// null means no session of id
|
||||||
// empty string means no password
|
// empty string means no password
|
||||||
var password = await bind.getSessionOption(id: id, arg: "os-password");
|
var password = await bind.getSessionOption(id: id, arg: "os-password");
|
||||||
@ -662,6 +669,8 @@ class _RemotePageState extends State<RemotePage>
|
|||||||
}
|
}
|
||||||
} else if (value == 'reset_canvas') {
|
} else if (value == 'reset_canvas') {
|
||||||
_ffi.cursorModel.reset();
|
_ffi.cursorModel.reset();
|
||||||
|
} else if (value == 'restart') {
|
||||||
|
showRestartRemoteDevice(pi, widget.id, gFFI.dialogManager);
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
@ -670,7 +670,6 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
|
||||||
showSetOSPassword(id, false, gFFI.dialogManager);
|
showSetOSPassword(id, false, gFFI.dialogManager);
|
||||||
},
|
},
|
||||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||||
@ -1110,28 +1109,6 @@ void showOptions(String id, OverlayDialogManager dialogManager) async {
|
|||||||
}, clickMaskDismiss: true, backDismiss: true);
|
}, clickMaskDismiss: true, backDismiss: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showRestartRemoteDevice(
|
|
||||||
PeerInfo pi, String id, OverlayDialogManager dialogManager) async {
|
|
||||||
final res =
|
|
||||||
await dialogManager.show<bool>((setState, close) => CustomAlertDialog(
|
|
||||||
title: Row(children: [
|
|
||||||
Icon(Icons.warning_amber_sharp,
|
|
||||||
color: Colors.redAccent, size: 28),
|
|
||||||
SizedBox(width: 10),
|
|
||||||
Text(translate("Restart Remote Device")),
|
|
||||||
]),
|
|
||||||
content: Text(
|
|
||||||
"${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => close(), child: Text(translate("Cancel"))),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => close(true), child: Text(translate("OK"))),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
if (res == true) bind.sessionRestartRemoteDevice(id: id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showSetOSPassword(
|
void showSetOSPassword(
|
||||||
String id, bool login, OverlayDialogManager dialogManager) async {
|
String id, bool login, OverlayDialogManager dialogManager) async {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
|
import '../../models/model.dart';
|
||||||
import '../../models/platform_model.dart';
|
import '../../models/platform_model.dart';
|
||||||
|
|
||||||
void clientClose(OverlayDialogManager dialogManager) {
|
void clientClose(OverlayDialogManager dialogManager) {
|
||||||
@ -16,6 +17,28 @@ void showError() {
|
|||||||
showToast(translate("Error"));
|
showToast(translate("Error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showRestartRemoteDevice(
|
||||||
|
PeerInfo pi, String id, OverlayDialogManager dialogManager) async {
|
||||||
|
final res =
|
||||||
|
await dialogManager.show<bool>((setState, close) => CustomAlertDialog(
|
||||||
|
title: Row(children: [
|
||||||
|
Icon(Icons.warning_amber_sharp,
|
||||||
|
color: Colors.redAccent, size: 28),
|
||||||
|
SizedBox(width: 10),
|
||||||
|
Text(translate("Restart Remote Device")),
|
||||||
|
]),
|
||||||
|
content: Text(
|
||||||
|
"${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => close(), child: Text(translate("Cancel"))),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => close(true), child: Text(translate("OK"))),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
if (res == true) bind.sessionRestartRemoteDevice(id: id);
|
||||||
|
}
|
||||||
|
|
||||||
void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
|
void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
|
||||||
final pw = await bind.mainGetPermanentPassword();
|
final pw = await bind.mainGetPermanentPassword();
|
||||||
final p0 = TextEditingController(text: pw);
|
final p0 = TextEditingController(text: pw);
|
||||||
|
@ -1050,7 +1050,6 @@ class FFI {
|
|||||||
await for (final message in stream) {
|
await for (final message in stream) {
|
||||||
if (message is Event) {
|
if (message is Event) {
|
||||||
try {
|
try {
|
||||||
debugPrint("event:${message.field0}");
|
|
||||||
Map<String, dynamic> event = json.decode(message.field0);
|
Map<String, dynamic> event = json.decode(message.field0);
|
||||||
cb(event);
|
cb(event);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -31,9 +31,10 @@ use hbb_common::{
|
|||||||
Stream,
|
Stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::common::{
|
use crate::common::{self, make_fd_to_json, CLIPBOARD_INTERVAL};
|
||||||
self, check_clipboard, make_fd_to_json, update_clipboard, ClipboardContext, CLIPBOARD_INTERVAL,
|
|
||||||
};
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
use crate::common::{check_clipboard, update_clipboard, ClipboardContext};
|
||||||
|
|
||||||
use crate::{client::*, flutter_ffi::EventToUI, make_fd_flutter};
|
use crate::{client::*, flutter_ffi::EventToUI, make_fd_flutter};
|
||||||
|
|
||||||
@ -127,26 +128,18 @@ impl Session {
|
|||||||
}
|
}
|
||||||
lc.set_option(name, value);
|
lc.set_option(name, value);
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
// input_os_password
|
|
||||||
// restart_remote_device
|
|
||||||
|
|
||||||
/// Input the OS password.
|
/// Input the OS password.
|
||||||
pub fn input_os_password(&self, pass: String, activate: bool) {
|
pub fn input_os_password(&self, pass: String, activate: bool) {
|
||||||
input_os_password(pass, activate, self.clone());
|
input_os_password(pass, activate, self.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl Interface
|
pub fn restart_remote_device(&self) {
|
||||||
/// Send message to the remote session.
|
let mut lc = self.lc.write().unwrap();
|
||||||
///
|
lc.restarting_remote_device = true;
|
||||||
/// # Arguments
|
let msg = lc.restart_remote_device();
|
||||||
///
|
self.send_msg(msg);
|
||||||
/// * `data` - The data to send. See [`Data`] for more details.
|
}
|
||||||
// fn send(data: Data) {
|
|
||||||
// if let Some(session) = SESSION.read().unwrap().as_ref() {
|
|
||||||
// session.send(data);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// Toggle an option.
|
/// Toggle an option.
|
||||||
pub fn toggle_option(&self, name: &str) {
|
pub fn toggle_option(&self, name: &str) {
|
||||||
@ -670,6 +663,7 @@ impl Connection {
|
|||||||
lc: Arc<RwLock<LoginConfigHandler>>,
|
lc: Arc<RwLock<LoginConfigHandler>>,
|
||||||
) -> Option<std::sync::mpsc::Sender<()>> {
|
) -> Option<std::sync::mpsc::Sender<()>> {
|
||||||
let (tx, rx) = std::sync::mpsc::channel();
|
let (tx, rx) = std::sync::mpsc::channel();
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
match ClipboardContext::new() {
|
match ClipboardContext::new() {
|
||||||
Ok(mut ctx) => {
|
Ok(mut ctx) => {
|
||||||
let old_clipboard: Arc<Mutex<String>> = Default::default();
|
let old_clipboard: Arc<Mutex<String>> = Default::default();
|
||||||
|
@ -696,8 +696,9 @@ pub fn session_send_mouse(id: String, msg: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn session_restart_remote_device(id: String) {
|
pub fn session_restart_remote_device(id: String) {
|
||||||
// TODO
|
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||||
// Session::restart_remote_device();
|
session.restart_remote_device();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_set_home_dir(home: String) {
|
pub fn main_set_home_dir(home: String) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user