request elevation menu

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-02-24 15:51:13 +08:00
parent 0ad6bca9ce
commit a9598e006a
8 changed files with 59 additions and 23 deletions

View File

@ -598,6 +598,7 @@ class _ControlMenu extends StatelessWidget {
hoverColor: _MenubarTheme.hoverBlueColor,
ffi: ffi,
menuChildren: [
requestElevation(),
osPassword(),
transferFile(context),
tcpTunneling(context),
@ -611,6 +612,15 @@ class _ControlMenu extends StatelessWidget {
]);
}
requestElevation() {
final visible = ffi.elevationModel.showRequestMenu;
if (!visible) return Offstage();
return _MenuItemButton(
child: Text(translate('Request Elevation')),
ffi: ffi,
onPressed: () => showRequestElevationDialog(id, ffi.dialogManager));
}
osPassword() {
return _MenuItemButton(
child: Text(translate('OS Password')),

View File

@ -374,8 +374,7 @@ void showWaitUacDialog(
));
}
void _showRequestElevationDialog(
String id, OverlayDialogManager dialogManager) {
void showRequestElevationDialog(String id, OverlayDialogManager dialogManager) {
RxString groupValue = ''.obs;
RxString errUser = ''.obs;
RxString errPwd = ''.obs;
@ -531,7 +530,7 @@ void showOnBlockDialog(
dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() {
close();
_showRequestElevationDialog(id, dialogManager);
showRequestElevationDialog(id, dialogManager);
}
return CustomAlertDialog(
@ -553,7 +552,7 @@ void showElevationError(String id, String type, String title, String text,
dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() {
close();
_showRequestElevationDialog(id, dialogManager);
showRequestElevationDialog(id, dialogManager);
}
return CustomAlertDialog(

View File

@ -203,6 +203,8 @@ class FfiModel with ChangeNotifier {
final peer_id = evt['peer_id'].toString();
await bind.sessionSwitchSides(id: peer_id);
closeConnection(id: peer_id);
} else if (name == 'portable_service_running') {
parent.target?.elevationModel.onPortableServiceRunning(evt);
} else if (name == "on_url_scheme_received") {
final url = evt['url'].toString();
parseRustdeskUri(url);
@ -439,6 +441,7 @@ class FfiModel with ChangeNotifier {
Map<String, dynamic> features = json.decode(evt['features']);
_pi.features.privacyMode = features['privacy_mode'] == 1;
handleResolutions(peerId, evt["resolutions"]);
parent.target?.elevationModel.onPeerInfo(_pi);
}
notifyListeners();
}
@ -1395,6 +1398,21 @@ class RecordingModel with ChangeNotifier {
}
}
class ElevationModel with ChangeNotifier {
WeakReference<FFI> parent;
ElevationModel(this.parent);
bool _running = false;
bool _canElevate = false;
bool get showRequestMenu => _canElevate && !_running;
onPeerInfo(PeerInfo pi) {
_canElevate = pi.platform == kPeerPlatformWindows && pi.sasEnabled == false;
}
onPortableServiceRunning(Map<String, dynamic> evt) {
_running = evt['running'] == 'true';
}
}
enum ConnType { defaultConn, fileTransfer, portForward, rdp }
/// Flutter state manager and data communication with the Rust core.
@ -1420,6 +1438,7 @@ class FFI {
late final QualityMonitorModel qualityMonitorModel; // session
late final RecordingModel recordingModel; // session
late final InputModel inputModel; // session
late final ElevationModel elevationModel; // session
FFI() {
imageModel = ImageModel(WeakReference(this));
@ -1436,6 +1455,7 @@ class FFI {
qualityMonitorModel = QualityMonitorModel(WeakReference(this));
recordingModel = RecordingModel(WeakReference(this));
inputModel = InputModel(WeakReference(this));
elevationModel = ElevationModel(WeakReference(this));
}
/// Start with the given [id]. Only transfer file if [isFileTransfer], only port forward if [isPortForward].

View File

@ -56,6 +56,7 @@ pub struct Remote<T: InvokeUiSession> {
data_count: Arc<AtomicUsize>,
frame_count: Arc<AtomicUsize>,
video_format: CodecFormat,
elevation_requested: bool,
}
impl<T: InvokeUiSession> Remote<T> {
@ -87,6 +88,7 @@ impl<T: InvokeUiSession> Remote<T> {
video_format: CodecFormat::Unknown,
stop_voice_call_sender: None,
voice_call_request_timestamp: None,
elevation_requested: false,
}
}
@ -686,6 +688,7 @@ impl<T: InvokeUiSession> Remote<T> {
let mut msg = Message::new();
msg.set_misc(misc);
allow_err!(peer.send(&msg).await);
self.elevation_requested = true;
}
Data::ElevateWithLogon(username, password) => {
let mut request = ElevationRequest::new();
@ -699,6 +702,7 @@ impl<T: InvokeUiSession> Remote<T> {
let mut msg = Message::new();
msg.set_misc(misc);
allow_err!(peer.send(&msg).await);
self.elevation_requested = true;
}
Data::NewVoiceCall => {
let msg = new_voice_call_request(true);
@ -1181,7 +1185,8 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
Some(misc::Union::PortableServiceRunning(b)) => {
if b {
self.handler.portable_service_running(b);
if self.elevation_requested && b {
self.handler.msgbox(
"custom-nocancel-success",
"Successful",
@ -1253,14 +1258,12 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
}
Some(message::Union::PeerInfo(pi)) => {
match pi.conn_id {
Some(message::Union::PeerInfo(pi)) => match pi.conn_id {
crate::SYNC_PEER_INFO_DISPLAYS => {
self.handler.set_displays(&pi.displays);
}
_ => {}
}
}
},
_ => {}
}
}

View File

@ -572,6 +572,13 @@ impl InvokeUiSession for FlutterHandler {
self.push_event("switch_back", [("peer_id", peer_id)].into());
}
fn portable_service_running(&self, running: bool) {
self.push_event(
"portable_service_running",
[("running", running.to_string().as_str())].into(),
);
}
fn on_voice_call_started(&self) {
self.push_event("on_voice_call_started", [].into());
}

View File

@ -1552,7 +1552,6 @@ impl Connection {
.err()
.map_or("".to_string(), |e| e.to_string());
}
self.portable.elevation_requested = err.is_empty();
let mut misc = Misc::new();
misc.set_elevation_response(err);
let mut msg = Message::new();
@ -1571,7 +1570,6 @@ impl Connection {
.err()
.map_or("".to_string(), |e| e.to_string());
}
self.portable.elevation_requested = err.is_empty();
let mut misc = Misc::new();
misc.set_elevation_response(err);
let mut msg = Message::new();
@ -1936,14 +1934,12 @@ impl Connection {
let p = &mut self.portable;
if running != p.last_running {
p.last_running = running;
if running && p.elevation_requested {
let mut misc = Misc::new();
misc.set_portable_service_running(running);
let mut msg = Message::new();
msg.set_misc(misc);
self.inner.send(msg.into());
}
}
let uac = crate::video_service::IS_UAC_RUNNING.lock().unwrap().clone();
if p.last_uac != uac {
p.last_uac = uac;
@ -2166,7 +2162,6 @@ pub struct PortableState {
pub last_foreground_window_elevated: bool,
pub last_running: bool,
pub is_installed: bool,
pub elevation_requested: bool,
}
#[cfg(windows)]
@ -2177,7 +2172,6 @@ impl Default for PortableState {
last_uac: Default::default(),
last_foreground_window_elevated: Default::default(),
last_running: Default::default(),
elevation_requested: Default::default(),
}
}
}

View File

@ -277,6 +277,8 @@ impl InvokeUiSession for SciterHandler {
fn switch_back(&self, _id: &str) {}
fn portable_service_running(&self, _running: bool) {}
fn on_voice_call_started(&self) {
self.call("onVoiceCallStart", &make_args!());
}

View File

@ -805,6 +805,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
fn clipboard(&self, content: String);
fn cancel_msgbox(&self, tag: &str);
fn switch_back(&self, id: &str);
fn portable_service_running(&self, running: bool);
fn on_voice_call_started(&self);
fn on_voice_call_closed(&self, reason: &str);
fn on_voice_call_waiting(&self);