Merge pull request #1341 from Heap-Hop/flutter_desktop
Update flutter_desktop
This commit is contained in:
commit
9bb418c772
@ -14,7 +14,7 @@ void main(List<String> args) async {
|
|||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
await windowManager.setSize(Size(400, 600));
|
await windowManager.setSize(Size(400, 600));
|
||||||
await windowManager.setAlignment(Alignment.topRight);
|
await windowManager.setAlignment(Alignment.topRight);
|
||||||
await initEnv(kAppTypeConnectionManager);
|
await initEnv(kAppTypeMain);
|
||||||
gFFI.serverModel.clients
|
gFFI.serverModel.clients
|
||||||
.add(Client(0, false, false, "UserA", "123123123", true, false, false));
|
.add(Client(0, false, false, "UserA", "123123123", true, false, false));
|
||||||
gFFI.serverModel.clients
|
gFFI.serverModel.clients
|
||||||
|
@ -18,11 +18,11 @@ import 'models/platform_model.dart';
|
|||||||
final globalKey = GlobalKey<NavigatorState>();
|
final globalKey = GlobalKey<NavigatorState>();
|
||||||
final navigationBarKey = GlobalKey();
|
final navigationBarKey = GlobalKey();
|
||||||
|
|
||||||
var isAndroid = Platform.isAndroid;
|
final isAndroid = Platform.isAndroid;
|
||||||
var isIOS = Platform.isIOS;
|
final isIOS = Platform.isIOS;
|
||||||
|
final isDesktop = Platform.isWindows || Platform.isMacOS || Platform.isLinux;
|
||||||
var isWeb = false;
|
var isWeb = false;
|
||||||
var isWebDesktop = false;
|
var isWebDesktop = false;
|
||||||
var isDesktop = Platform.isWindows || Platform.isMacOS || Platform.isLinux;
|
|
||||||
var version = "";
|
var version = "";
|
||||||
int androidVersion = 0;
|
int androidVersion = 0;
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
const double kDesktopRemoteTabBarHeight = 28.0;
|
const double kDesktopRemoteTabBarHeight = 28.0;
|
||||||
|
|
||||||
|
/// [kAppTypeMain] used by 'Desktop Main Page' , 'Mobile (Client and Server)' , 'Desktop CM Page'
|
||||||
const String kAppTypeMain = "main";
|
const String kAppTypeMain = "main";
|
||||||
const String kAppTypeDesktopRemote = "remote";
|
const String kAppTypeDesktopRemote = "remote";
|
||||||
const String kAppTypeDesktopFileTransfer = "file transfer";
|
const String kAppTypeDesktopFileTransfer = "file transfer";
|
||||||
const String kAppTypeConnectionManager = "connection manager";
|
|
||||||
const String kTabLabelHomePage = "Home";
|
const String kTabLabelHomePage = "Home";
|
||||||
const String kTabLabelSettingPage = "Settings";
|
const String kTabLabelSettingPage = "Settings";
|
||||||
|
|
||||||
|
@ -87,27 +87,6 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
super.build(context);
|
super.build(context);
|
||||||
return ChangeNotifierProvider.value(
|
|
||||||
value: _ffi.fileModel,
|
|
||||||
child: Consumer<FileModel>(builder: (_context, _model, _child) {
|
|
||||||
return WillPopScope(
|
|
||||||
onWillPop: () async {
|
|
||||||
if (model.selectMode) {
|
|
||||||
model.toggleSelectMode();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
|
||||||
backgroundColor: MyTheme.color(context).bg,
|
|
||||||
body: Row(
|
|
||||||
children: [
|
|
||||||
Flexible(flex: 3, child: body(isLocal: true)),
|
|
||||||
Flexible(flex: 3, child: body(isLocal: false)),
|
|
||||||
Flexible(flex: 2, child: statusList())
|
|
||||||
],
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}));
|
|
||||||
return Overlay(initialEntries: [
|
return Overlay(initialEntries: [
|
||||||
OverlayEntry(builder: (context) {
|
OverlayEntry(builder: (context) {
|
||||||
_ffi.dialogManager.setOverlayState(Overlay.of(context));
|
_ffi.dialogManager.setOverlayState(Overlay.of(context));
|
||||||
@ -122,6 +101,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
backgroundColor: MyTheme.color(context).bg,
|
||||||
body: Row(
|
body: Row(
|
||||||
children: [
|
children: [
|
||||||
Flexible(flex: 3, child: body(isLocal: true)),
|
Flexible(flex: 3, child: body(isLocal: true)),
|
||||||
|
@ -18,13 +18,27 @@ class DesktopServerPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _DesktopServerPageState extends State<DesktopServerPage>
|
class _DesktopServerPageState extends State<DesktopServerPage>
|
||||||
with AutomaticKeepAliveClientMixin {
|
with WindowListener, AutomaticKeepAliveClientMixin {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
gFFI.ffiModel.updateEventListener("");
|
gFFI.ffiModel.updateEventListener("");
|
||||||
|
windowManager.addListener(this);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
windowManager.removeListener(this);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onWindowClose() {
|
||||||
|
gFFI.serverModel.closeAll();
|
||||||
|
gFFI.close();
|
||||||
|
super.onWindowClose();
|
||||||
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
super.build(context);
|
super.build(context);
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
|
@ -62,7 +62,7 @@ class _PeerCardState extends State<_PeerCard>
|
|||||||
: null);
|
: null);
|
||||||
},
|
},
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onDoubleTap: () => _connect(peer.id),
|
onDoubleTapDown: (_) => _connect(peer.id),
|
||||||
child: Obx(() => peerCardUiType.value == PeerUiType.grid
|
child: Obx(() => peerCardUiType.value == PeerUiType.grid
|
||||||
? _buildPeerCard(context, peer, deco)
|
? _buildPeerCard(context, peer, deco)
|
||||||
: _buildPeerTile(context, peer, deco))),
|
: _buildPeerTile(context, peer, deco))),
|
||||||
@ -168,8 +168,6 @@ class _PeerCardState extends State<_PeerCard>
|
|||||||
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
|
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
|
||||||
return Card(
|
return Card(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
child: GestureDetector(
|
|
||||||
onDoubleTap: () => _connect(peer.id),
|
|
||||||
child: Obx(
|
child: Obx(
|
||||||
() => Container(
|
() => Container(
|
||||||
decoration: deco.value,
|
decoration: deco.value,
|
||||||
@ -250,9 +248,8 @@ class _PeerCardState extends State<_PeerCard>
|
|||||||
padding: EdgeInsets.fromLTRB(0, 4, 8, 4),
|
padding: EdgeInsets.fromLTRB(0, 4, 8, 4),
|
||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
radius: 5,
|
radius: 5,
|
||||||
backgroundColor: peer.online
|
backgroundColor:
|
||||||
? Colors.green
|
peer.online ? Colors.green : Colors.yellow)),
|
||||||
: Colors.yellow)),
|
|
||||||
Text('${peer.id}')
|
Text('${peer.id}')
|
||||||
]),
|
]),
|
||||||
InkWell(
|
InkWell(
|
||||||
@ -270,7 +267,7 @@ class _PeerCardState extends State<_PeerCard>
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +161,7 @@ class DesktopTabBar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static onAdd(RxList<TabInfo> tabs, TabInfo tab) {
|
static onAdd(RxList<TabInfo> tabs, TabInfo tab) {
|
||||||
|
if (!isDesktop) return;
|
||||||
int index = tabs.indexWhere((e) => e.key == tab.key);
|
int index = tabs.indexWhere((e) => e.key == tab.key);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
selected.value = index;
|
selected.value = index;
|
||||||
@ -178,6 +179,7 @@ class DesktopTabBar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static remove(RxList<TabInfo> tabs, int index) {
|
static remove(RxList<TabInfo> tabs, int index) {
|
||||||
|
if (!isDesktop) return;
|
||||||
if (index < 0) return;
|
if (index < 0) return;
|
||||||
if (index == tabs.length - 1) {
|
if (index == tabs.length - 1) {
|
||||||
selected.value = max(0, selected.value - 1);
|
selected.value = max(0, selected.value - 1);
|
||||||
@ -189,12 +191,14 @@ class DesktopTabBar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void jumpTo(RxList<TabInfo> tabs, int index) {
|
static void jumpTo(RxList<TabInfo> tabs, int index) {
|
||||||
|
if (!isDesktop) return;
|
||||||
if (index < 0 || index >= tabs.length) return;
|
if (index < 0 || index >= tabs.length) return;
|
||||||
selected.value = index;
|
selected.value = index;
|
||||||
controller.value.jumpToPage(selected.value);
|
controller.value.jumpToPage(selected.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close(String? key) {
|
static void close(String? key) {
|
||||||
|
if (!isDesktop) return;
|
||||||
final tabBar = _tabBarListViewKey.currentWidget as _ListView?;
|
final tabBar = _tabBarListViewKey.currentWidget as _ListView?;
|
||||||
if (tabBar == null) return;
|
if (tabBar == null) return;
|
||||||
final tabs = tabBar.tabs;
|
final tabs = tabBar.tabs;
|
||||||
|
@ -27,7 +27,7 @@ Future<Null> main(List<String> args) async {
|
|||||||
print("launch args: $args");
|
print("launch args: $args");
|
||||||
|
|
||||||
if (!isDesktop) {
|
if (!isDesktop) {
|
||||||
runMainApp(false);
|
runMobileApp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// main window
|
// main window
|
||||||
@ -72,9 +72,6 @@ Future<void> initEnv(String appType) async {
|
|||||||
// focus on multi-ffi on desktop first
|
// focus on multi-ffi on desktop first
|
||||||
await initGlobalFFI();
|
await initGlobalFFI();
|
||||||
// await Firebase.initializeApp();
|
// await Firebase.initializeApp();
|
||||||
if (isAndroid) {
|
|
||||||
toAndroidChannelInit();
|
|
||||||
}
|
|
||||||
refreshCurrentUser();
|
refreshCurrentUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +93,12 @@ void runMainApp(bool startService) async {
|
|||||||
runApp(App());
|
runApp(App());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void runMobileApp() async {
|
||||||
|
await initEnv(kAppTypeMain);
|
||||||
|
if (isAndroid) androidChannelInit();
|
||||||
|
runApp(App());
|
||||||
|
}
|
||||||
|
|
||||||
void runRemoteScreen(Map<String, dynamic> argument) async {
|
void runRemoteScreen(Map<String, dynamic> argument) async {
|
||||||
await initEnv(kAppTypeDesktopRemote);
|
await initEnv(kAppTypeDesktopRemote);
|
||||||
runApp(GetMaterialApp(
|
runApp(GetMaterialApp(
|
||||||
@ -129,7 +132,7 @@ void runConnectionManagerScreen() async {
|
|||||||
// initialize window
|
// initialize window
|
||||||
WindowOptions windowOptions = getHiddenTitleBarWindowOptions(Size(300, 400));
|
WindowOptions windowOptions = getHiddenTitleBarWindowOptions(Size(300, 400));
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
initEnv(kAppTypeConnectionManager),
|
initEnv(kAppTypeMain),
|
||||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
await windowManager.setAlignment(Alignment.topRight);
|
await windowManager.setAlignment(Alignment.topRight);
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
|
@ -510,7 +510,7 @@ Widget clientInfo(Client client) {
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toAndroidChannelInit() {
|
void androidChannelInit() {
|
||||||
gFFI.setMethodCallHandler((method, arguments) {
|
gFFI.setMethodCallHandler((method, arguments) {
|
||||||
debugPrint("flutter got android msg,$method,$arguments");
|
debugPrint("flutter got android msg,$method,$arguments");
|
||||||
try {
|
try {
|
||||||
|
@ -465,7 +465,12 @@ class ServerModel with ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
final client = Client.fromJson(jsonDecode(evt['client']));
|
final client = Client.fromJson(jsonDecode(evt['client']));
|
||||||
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(client.id));
|
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(client.id));
|
||||||
|
final index = _clients.indexWhere((c) => c.id == client.id);
|
||||||
|
if (index < 0) {
|
||||||
_clients.add(client);
|
_clients.add(client);
|
||||||
|
} else {
|
||||||
|
_clients[index].authorized = true;
|
||||||
|
}
|
||||||
DesktopTabBar.onAdd(
|
DesktopTabBar.onAdd(
|
||||||
tabs,
|
tabs,
|
||||||
TabInfo(
|
TabInfo(
|
||||||
|
@ -41,7 +41,6 @@ use crate::{client::*, flutter_ffi::EventToUI, make_fd_flutter};
|
|||||||
pub(super) const APP_TYPE_MAIN: &str = "main";
|
pub(super) const APP_TYPE_MAIN: &str = "main";
|
||||||
pub(super) const APP_TYPE_DESKTOP_REMOTE: &str = "remote";
|
pub(super) const APP_TYPE_DESKTOP_REMOTE: &str = "remote";
|
||||||
pub(super) const APP_TYPE_DESKTOP_FILE_TRANSFER: &str = "file transfer";
|
pub(super) const APP_TYPE_DESKTOP_FILE_TRANSFER: &str = "file transfer";
|
||||||
pub(super) const APP_TYPE_DESKTOP_CONNECTION_MANAGER: &str = "connection manager";
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
// static ref SESSION: Arc<RwLock<Option<Session>>> = Default::default();
|
// static ref SESSION: Arc<RwLock<Option<Session>>> = Default::default();
|
||||||
@ -1940,7 +1939,7 @@ pub mod connection_manager {
|
|||||||
if let Some(s) = GLOBAL_EVENT_STREAM
|
if let Some(s) = GLOBAL_EVENT_STREAM
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get(super::APP_TYPE_DESKTOP_CONNECTION_MANAGER)
|
.get(super::APP_TYPE_MAIN)
|
||||||
{
|
{
|
||||||
s.add(serde_json::ser::to_string(&h).unwrap_or("".to_owned()));
|
s.add(serde_json::ser::to_string(&h).unwrap_or("".to_owned()));
|
||||||
};
|
};
|
||||||
|
@ -2639,7 +2639,7 @@ impl Interface for Handler {
|
|||||||
self.lc.write().unwrap().handle_peer_info(username, pi);
|
self.lc.write().unwrap().handle_peer_info(username, pi);
|
||||||
self.call("updatePrivacyMode", &[]);
|
self.call("updatePrivacyMode", &[]);
|
||||||
self.call("updatePi", &make_args!(pi_sciter));
|
self.call("updatePi", &make_args!(pi_sciter));
|
||||||
if self.is_file_transfer() {
|
if self.is_file_transfer() || self.is_port_forward() {
|
||||||
self.call2("closeSuccess", &make_args!());
|
self.call2("closeSuccess", &make_args!());
|
||||||
} else if !self.is_port_forward() {
|
} else if !self.is_port_forward() {
|
||||||
self.msgbox("success", "Successful", "Connected, waiting for image...");
|
self.msgbox("success", "Successful", "Connected, waiting for image...");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user