mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
new dialog impl based on Overlay
This commit is contained in:
@@ -4,7 +4,6 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/file_manager_page.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:path/path.dart' as Path;
|
||||
|
||||
@@ -126,9 +125,9 @@ class FileModel extends ChangeNotifier {
|
||||
|
||||
final _jobResultListener = JobResultListener<Map<String, dynamic>>();
|
||||
|
||||
final WeakReference<FFI> _ffi;
|
||||
final WeakReference<FFI> parent;
|
||||
|
||||
FileModel(this._ffi);
|
||||
FileModel(this.parent);
|
||||
|
||||
toggleSelectMode() {
|
||||
if (jobState == JobState.inProgress) {
|
||||
@@ -275,7 +274,7 @@ class FileModel extends ChangeNotifier {
|
||||
need_override = true;
|
||||
}
|
||||
bind.sessionSetConfirmOverrideFile(
|
||||
id: _ffi.target?.id ?? "",
|
||||
id: parent.target?.id ?? "",
|
||||
actId: id,
|
||||
fileNum: int.parse(evt['file_num']),
|
||||
needOverride: need_override,
|
||||
@@ -292,22 +291,22 @@ class FileModel extends ChangeNotifier {
|
||||
onReady() async {
|
||||
_localOption.home = await bind.mainGetHomeDir();
|
||||
_localOption.showHidden = (await bind.sessionGetPeerOption(
|
||||
id: _ffi.target?.id ?? "", name: "local_show_hidden"))
|
||||
id: parent.target?.id ?? "", name: "local_show_hidden"))
|
||||
.isNotEmpty;
|
||||
|
||||
_remoteOption.showHidden = (await bind.sessionGetPeerOption(
|
||||
id: _ffi.target?.id ?? "", name: "remote_show_hidden"))
|
||||
id: parent.target?.id ?? "", name: "remote_show_hidden"))
|
||||
.isNotEmpty;
|
||||
_remoteOption.isWindows = _ffi.target?.ffiModel.pi.platform == "Windows";
|
||||
_remoteOption.isWindows = parent.target?.ffiModel.pi.platform == "Windows";
|
||||
|
||||
debugPrint("remote platform: ${_ffi.target?.ffiModel.pi.platform}");
|
||||
debugPrint("remote platform: ${parent.target?.ffiModel.pi.platform}");
|
||||
|
||||
await Future.delayed(Duration(milliseconds: 100));
|
||||
|
||||
final local = (await bind.sessionGetPeerOption(
|
||||
id: _ffi.target?.id ?? "", name: "local_dir"));
|
||||
id: parent.target?.id ?? "", name: "local_dir"));
|
||||
final remote = (await bind.sessionGetPeerOption(
|
||||
id: _ffi.target?.id ?? "", name: "remote_dir"));
|
||||
id: parent.target?.id ?? "", name: "remote_dir"));
|
||||
openDirectory(local.isEmpty ? _localOption.home : local, isLocal: true);
|
||||
openDirectory(remote.isEmpty ? _remoteOption.home : remote, isLocal: false);
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
@@ -318,11 +317,11 @@ class FileModel extends ChangeNotifier {
|
||||
openDirectory(_remoteOption.home, isLocal: false);
|
||||
}
|
||||
// load last transfer jobs
|
||||
await bind.sessionLoadLastTransferJobs(id: '${_ffi.target?.id}');
|
||||
await bind.sessionLoadLastTransferJobs(id: '${parent.target?.id}');
|
||||
}
|
||||
|
||||
onClose() {
|
||||
SmartDialog.dismiss();
|
||||
parent.target?.dialogManager.dismissAll();
|
||||
jobReset();
|
||||
|
||||
// save config
|
||||
@@ -332,7 +331,7 @@ class FileModel extends ChangeNotifier {
|
||||
msgMap["local_show_hidden"] = _localOption.showHidden ? "Y" : "";
|
||||
msgMap["remote_dir"] = _currentRemoteDir.path;
|
||||
msgMap["remote_show_hidden"] = _remoteOption.showHidden ? "Y" : "";
|
||||
final id = _ffi.target?.id ?? "";
|
||||
final id = parent.target?.id ?? "";
|
||||
for (final msg in msgMap.entries) {
|
||||
bind.sessionPeerOption(id: id, name: msg.key, value: msg.value);
|
||||
}
|
||||
@@ -419,7 +418,7 @@ class FileModel extends ChangeNotifier {
|
||||
..id = jobId
|
||||
..isRemote = isRemote);
|
||||
bind.sessionSendFiles(
|
||||
id: '${_ffi.target?.id}',
|
||||
id: '${parent.target?.id}',
|
||||
actId: _jobId,
|
||||
path: from.path,
|
||||
to: PathUtil.join(toPath, from.name, isWindows),
|
||||
@@ -477,14 +476,14 @@ class FileModel extends ChangeNotifier {
|
||||
entries = [item];
|
||||
} else if (item.isDirectory) {
|
||||
title = translate("Not an empty directory");
|
||||
showLoading(translate("Waiting"));
|
||||
parent.target?.dialogManager.showLoading(translate("Waiting"));
|
||||
final fd = await _fileFetcher.fetchDirectoryRecursive(
|
||||
_jobId, item.path, items.isLocal!, true);
|
||||
if (fd.path.isEmpty) {
|
||||
fd.path = item.path;
|
||||
}
|
||||
fd.format(isWindows);
|
||||
SmartDialog.dismiss();
|
||||
parent.target?.dialogManager.dismissAll();
|
||||
if (fd.entries.isEmpty) {
|
||||
final confirm = await showRemoveDialog(
|
||||
translate(
|
||||
@@ -543,7 +542,7 @@ class FileModel extends ChangeNotifier {
|
||||
|
||||
Future<bool?> showRemoveDialog(
|
||||
String title, String content, bool showCheckbox) async {
|
||||
return await DialogManager.show<bool>(
|
||||
return await parent.target?.dialogManager.show<bool>(
|
||||
(setState, Function(bool v) close) => CustomAlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
@@ -594,7 +593,7 @@ class FileModel extends ChangeNotifier {
|
||||
Future<bool?> showFileConfirmDialog(
|
||||
String title, String content, bool showCheckbox) async {
|
||||
fileConfirmCheckboxRemember = false;
|
||||
return await DialogManager.show<bool?>(
|
||||
return await parent.target?.dialogManager.show<bool?>(
|
||||
(setState, Function(bool? v) close) => CustomAlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
@@ -648,7 +647,7 @@ class FileModel extends ChangeNotifier {
|
||||
|
||||
sendRemoveFile(String path, int fileNum, bool isLocal) {
|
||||
bind.sessionRemoveFile(
|
||||
id: '${_ffi.target?.id}',
|
||||
id: '${parent.target?.id}',
|
||||
actId: _jobId,
|
||||
path: path,
|
||||
isRemote: !isLocal,
|
||||
@@ -657,7 +656,7 @@ class FileModel extends ChangeNotifier {
|
||||
|
||||
sendRemoveEmptyDir(String path, int fileNum, bool isLocal) {
|
||||
bind.sessionRemoveAllEmptyDirs(
|
||||
id: '${_ffi.target?.id}',
|
||||
id: '${parent.target?.id}',
|
||||
actId: _jobId,
|
||||
path: path,
|
||||
isRemote: !isLocal);
|
||||
@@ -667,14 +666,14 @@ class FileModel extends ChangeNotifier {
|
||||
isLocal = isLocal ?? this.isLocal;
|
||||
_jobId++;
|
||||
bind.sessionCreateDir(
|
||||
id: '${_ffi.target?.id}',
|
||||
id: '${parent.target?.id}',
|
||||
actId: _jobId,
|
||||
path: path,
|
||||
isRemote: !isLocal);
|
||||
}
|
||||
|
||||
cancelJob(int id) async {
|
||||
bind.sessionCancelJob(id: '${_ffi.target?.id}', actId: id);
|
||||
bind.sessionCancelJob(id: '${parent.target?.id}', actId: id);
|
||||
jobReset();
|
||||
}
|
||||
|
||||
@@ -701,7 +700,7 @@ class FileModel extends ChangeNotifier {
|
||||
}
|
||||
|
||||
initFileFetcher() {
|
||||
_fileFetcher.id = _ffi.target?.id;
|
||||
_fileFetcher.id = parent.target?.id;
|
||||
}
|
||||
|
||||
void updateFolderFiles(Map<String, dynamic> evt) {
|
||||
@@ -742,7 +741,7 @@ class FileModel extends ChangeNotifier {
|
||||
..state = JobState.paused;
|
||||
jobTable.add(jobProgress);
|
||||
bind.sessionAddJob(
|
||||
id: '${_ffi.target?.id}',
|
||||
id: '${parent.target?.id}',
|
||||
isRemote: isRemote,
|
||||
includeHidden: showHidden,
|
||||
actId: currJobId,
|
||||
@@ -757,7 +756,7 @@ class FileModel extends ChangeNotifier {
|
||||
if (jobIndex != -1) {
|
||||
final job = jobTable[jobIndex];
|
||||
bind.sessionResumeJob(
|
||||
id: '${_ffi.target?.id}', actId: job.id, isRemote: job.isRemote);
|
||||
id: '${parent.target?.id}', actId: job.id, isRemote: job.isRemote);
|
||||
job.state = JobState.inProgress;
|
||||
} else {
|
||||
debugPrint("jobId ${jobId} is not exists");
|
||||
|
||||
@@ -13,7 +13,6 @@ import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_hbb/models/user_model.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
@@ -60,7 +59,6 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
FfiModel(this.parent) {
|
||||
Translator.call = translate;
|
||||
clear();
|
||||
}
|
||||
|
||||
@@ -261,32 +259,35 @@ class FfiModel with ChangeNotifier {
|
||||
|
||||
/// Handle the message box event based on [evt] and [id].
|
||||
void handleMsgBox(Map<String, dynamic> evt, String id) {
|
||||
if (parent.target == null) return;
|
||||
final dialogManager = parent.target!.dialogManager;
|
||||
var type = evt['type'];
|
||||
var title = evt['title'];
|
||||
var text = evt['text'];
|
||||
if (type == 're-input-password') {
|
||||
wrongPasswordDialog(id);
|
||||
wrongPasswordDialog(id, dialogManager);
|
||||
} else if (type == 'input-password') {
|
||||
enterPasswordDialog(id);
|
||||
enterPasswordDialog(id, dialogManager);
|
||||
} else if (type == 'restarting') {
|
||||
showMsgBox(id, type, title, text, false, hasCancel: false);
|
||||
showMsgBox(id, type, title, text, false, dialogManager, hasCancel: false);
|
||||
} else {
|
||||
var hasRetry = evt['hasRetry'] == 'true';
|
||||
showMsgBox(id, type, title, text, hasRetry);
|
||||
showMsgBox(id, type, title, text, hasRetry, dialogManager);
|
||||
}
|
||||
}
|
||||
|
||||
/// Show a message box with [type], [title] and [text].
|
||||
void showMsgBox(
|
||||
String id, String type, String title, String text, bool hasRetry,
|
||||
void showMsgBox(String id, String type, String title, String text,
|
||||
bool hasRetry, OverlayDialogManager dialogManager,
|
||||
{bool? hasCancel}) {
|
||||
msgBox(type, title, text, hasCancel: hasCancel);
|
||||
msgBox(type, title, text, dialogManager, hasCancel: hasCancel);
|
||||
_timer?.cancel();
|
||||
if (hasRetry) {
|
||||
_timer = Timer(Duration(seconds: _reconnects), () {
|
||||
bind.sessionReconnect(id: id);
|
||||
clearPermissions();
|
||||
showLoading(translate('Connecting...'));
|
||||
dialogManager.showLoading(translate('Connecting...'),
|
||||
cancelToClose: true);
|
||||
});
|
||||
_reconnects *= 2;
|
||||
} else {
|
||||
@@ -296,7 +297,7 @@ class FfiModel with ChangeNotifier {
|
||||
|
||||
/// Handle the peer info event based on [evt].
|
||||
void handlePeerInfo(Map<String, dynamic> evt, String peerId) async {
|
||||
SmartDialog.dismiss();
|
||||
parent.target?.dialogManager.dismissAll();
|
||||
_pi.version = evt['version'];
|
||||
_pi.username = evt['username'];
|
||||
_pi.hostname = evt['hostname'];
|
||||
@@ -332,7 +333,9 @@ class FfiModel with ChangeNotifier {
|
||||
_display = _pi.displays[_pi.currentDisplay];
|
||||
}
|
||||
if (displays.length > 0) {
|
||||
showLoading(translate('Connected, waiting for image...'));
|
||||
parent.target?.dialogManager.showLoading(
|
||||
translate('Connected, waiting for image...'),
|
||||
cancelToClose: true);
|
||||
_waitForImage = true;
|
||||
_reconnects = 1;
|
||||
}
|
||||
@@ -364,7 +367,7 @@ class ImageModel with ChangeNotifier {
|
||||
void onRgba(Uint8List rgba, double tabBarHeight) {
|
||||
if (_waitForImage) {
|
||||
_waitForImage = false;
|
||||
SmartDialog.dismiss();
|
||||
parent.target?.dialogManager.dismissAll();
|
||||
}
|
||||
final pid = parent.target?.id;
|
||||
ui.decodeImageFromPixels(
|
||||
@@ -874,16 +877,20 @@ class FFI {
|
||||
var alt = false;
|
||||
var command = false;
|
||||
var version = "";
|
||||
late final ImageModel imageModel;
|
||||
late final FfiModel ffiModel;
|
||||
late final CursorModel cursorModel;
|
||||
late final CanvasModel canvasModel;
|
||||
late final ServerModel serverModel;
|
||||
late final ChatModel chatModel;
|
||||
late final FileModel fileModel;
|
||||
late final AbModel abModel;
|
||||
late final UserModel userModel;
|
||||
late final QualityMonitorModel qualityMonitorModel;
|
||||
|
||||
/// dialogManager use late to ensure init after main page binding [globalKey]
|
||||
late final dialogManager = OverlayDialogManager();
|
||||
|
||||
late final ImageModel imageModel; // session
|
||||
late final FfiModel ffiModel; // session
|
||||
late final CursorModel cursorModel; // session
|
||||
late final CanvasModel canvasModel; // session
|
||||
late final ServerModel serverModel; // global
|
||||
late final ChatModel chatModel; // session
|
||||
late final FileModel fileModel; // session
|
||||
late final AbModel abModel; // global
|
||||
late final UserModel userModel; // global
|
||||
late final QualityMonitorModel qualityMonitorModel; // session
|
||||
|
||||
FFI() {
|
||||
this.imageModel = ImageModel(WeakReference(this));
|
||||
|
||||
@@ -75,7 +75,7 @@ class PlatformFFI {
|
||||
}
|
||||
|
||||
String translate(String name, String locale) {
|
||||
if (_translate == null) return '';
|
||||
if (_translate == null) return name;
|
||||
var a = name.toNativeUtf8();
|
||||
var b = locale.toNativeUtf8();
|
||||
var p = _translate!(a, b);
|
||||
|
||||
@@ -10,7 +10,7 @@ import '../common.dart';
|
||||
import '../mobile/pages/server_page.dart';
|
||||
import 'model.dart';
|
||||
|
||||
const loginDialogTag = "LOGIN";
|
||||
const KLoginDialogTag = "LOGIN";
|
||||
|
||||
const kUseTemporaryPassword = "use-temporary-password";
|
||||
const kUsePermanentPassword = "use-permanent-password";
|
||||
@@ -206,8 +206,8 @@ class ServerModel with ChangeNotifier {
|
||||
/// Toggle the screen sharing service.
|
||||
toggleService() async {
|
||||
if (_isStart) {
|
||||
final res =
|
||||
await DialogManager.show<bool>((setState, close) => CustomAlertDialog(
|
||||
final res = await parent.target?.dialogManager
|
||||
.show<bool>((setState, close) => CustomAlertDialog(
|
||||
title: Row(children: [
|
||||
Icon(Icons.warning_amber_sharp,
|
||||
color: Colors.redAccent, size: 28),
|
||||
@@ -228,8 +228,8 @@ class ServerModel with ChangeNotifier {
|
||||
stopService();
|
||||
}
|
||||
} else {
|
||||
final res =
|
||||
await DialogManager.show<bool>((setState, close) => CustomAlertDialog(
|
||||
final res = await parent.target?.dialogManager
|
||||
.show<bool>((setState, close) => CustomAlertDialog(
|
||||
title: Row(children: [
|
||||
Icon(Icons.warning_amber_sharp,
|
||||
color: Colors.redAccent, size: 28),
|
||||
@@ -272,7 +272,7 @@ class ServerModel with ChangeNotifier {
|
||||
Future<Null> stopService() async {
|
||||
_isStart = false;
|
||||
// TODO
|
||||
parent.target?.serverModel.closeAll();
|
||||
closeAll();
|
||||
await parent.target?.invokeMethod("stop_service");
|
||||
await bind.mainStopService();
|
||||
notifyListeners();
|
||||
@@ -370,7 +370,7 @@ class ServerModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
void showLoginDialog(Client client) {
|
||||
DialogManager.show(
|
||||
parent.target?.dialogManager.show(
|
||||
(setState, close) => CustomAlertDialog(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -442,7 +442,7 @@ class ServerModel with ChangeNotifier {
|
||||
void onClientAuthorized(Map<String, dynamic> evt) {
|
||||
try {
|
||||
final client = Client.fromJson(jsonDecode(evt['client']));
|
||||
DialogManager.dismissByTag(getLoginDialogTag(client.id));
|
||||
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(client.id));
|
||||
_clients[client.id] = client;
|
||||
scrollToBottom();
|
||||
notifyListeners();
|
||||
@@ -454,7 +454,7 @@ class ServerModel with ChangeNotifier {
|
||||
final id = int.parse(evt['id'] as String);
|
||||
if (_clients.containsKey(id)) {
|
||||
_clients.remove(id);
|
||||
DialogManager.dismissByTag(getLoginDialogTag(id));
|
||||
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
|
||||
parent.target?.invokeMethod("cancel_notification", id);
|
||||
}
|
||||
notifyListeners();
|
||||
@@ -510,11 +510,11 @@ class Client {
|
||||
}
|
||||
|
||||
String getLoginDialogTag(int id) {
|
||||
return loginDialogTag + id.toString();
|
||||
return KLoginDialogTag + id.toString();
|
||||
}
|
||||
|
||||
showInputWarnAlert(FFI ffi) {
|
||||
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||
ffi.dialogManager.show((setState, close) => CustomAlertDialog(
|
||||
title: Text(translate("How to get Android input permission?")),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
Reference in New Issue
Block a user