diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index b9a2a7598..44ca71912 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -17,7 +17,8 @@ import 'package:flutter_hbb/models/server_model.dart'; import 'package:flutter_hbb/models/user_model.dart'; import 'package:flutter_hbb/models/state_model.dart'; import 'package:flutter_hbb/plugin/event.dart'; -import 'package:flutter_hbb/plugin/reloader.dart'; +import 'package:flutter_hbb/plugin/desc.dart'; +import 'package:flutter_hbb/plugin/widget.dart'; import 'package:flutter_hbb/common/shared_state.dart'; import 'package:tuple/tuple.dart'; import 'package:image/image.dart' as img2; @@ -229,7 +230,7 @@ class FfiModel with ChangeNotifier { } else if (name == "fingerprint") { FingerprintState.find(peerId).value = evt['fingerprint'] ?? ''; } else if (name == "plugin_desc") { - handleReloading(evt, peerId); + updateDesc(evt); } else if (name == "plugin_event") { handlePluginEvent( evt, peerId, (Map e) => handleMsgBox(e, peerId)); diff --git a/flutter/lib/plugin/common.dart b/flutter/lib/plugin/common.dart new file mode 100644 index 000000000..5cbc0f871 --- /dev/null +++ b/flutter/lib/plugin/common.dart @@ -0,0 +1 @@ +typedef PluginId = String; diff --git a/flutter/lib/plugin/desc.dart b/flutter/lib/plugin/desc.dart index c6b04d11c..6be712697 100644 --- a/flutter/lib/plugin/desc.dart +++ b/flutter/lib/plugin/desc.dart @@ -38,9 +38,14 @@ class UiType { : button = json['t'] == 'Button' ? UiButton.fromJson(json['c']) : null, checkbox = json['t'] != 'Checkbox' ? UiCheckbox.fromJson(json['c']) : null; + + bool get isValid => button != null || checkbox != null; } class Location { + // location key: + // host|main|settings|display|others + // client|remote|toolbar|display HashMap ui; Location(this.ui); diff --git a/flutter/lib/plugin/model.dart b/flutter/lib/plugin/model.dart new file mode 100644 index 000000000..824992e20 --- /dev/null +++ b/flutter/lib/plugin/model.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import './common.dart'; +import './desc.dart'; + +// ui location +// host|main|settings|display|others +// client|remote|toolbar|display + +final Map> locationModels = {}; + +class LocationModel with ChangeNotifier { + final List uiList = []; + + void add(UiType ui) { + uiList.add(ui); + notifyListeners(); + } +} + +void addLocation(PluginId id, String location, UiType ui) { + if (!locationModels.containsKey(id)) { + locationModels[id] = {}; + } + if (!locationModels[id]!.containsKey(location)) { + locationModels[id]![location] = LocationModel(); + } + locationModels[id]![location]!.add(ui); +} diff --git a/flutter/lib/plugin/reloader.dart b/flutter/lib/plugin/reloader.dart deleted file mode 100644 index 1b1641f87..000000000 --- a/flutter/lib/plugin/reloader.dart +++ /dev/null @@ -1,29 +0,0 @@ -void handleReloading(Map evt, String peer) { - // location - // host|main|settings|display|others - // client|remote|toolbar|display - // - // ui - // { - // "t": "Button", - // "c": { - // "key": "key", - // "text": "text", - // "icon": "icon", - // "tooltip": "tooltip", - // "action": "action" - // } - // } - // - // { - // "t": "Checkbox", - // "c": { - // "key": "key", - // "text": "text", - // "tooltip": "tooltip", - // "action": "action" - // } - // } - // - -} diff --git a/flutter/lib/plugin/widget.dart b/flutter/lib/plugin/widget.dart index dbdfbbadd..a99e25e4e 100644 --- a/flutter/lib/plugin/widget.dart +++ b/flutter/lib/plugin/widget.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import './desc.dart'; +import './model.dart'; final Map pluginWidgets = {}; @@ -14,4 +16,32 @@ class PluginWidget { required this.location, required this.widget, }); + + // static Widget createButton(UiButton btn) {} + + // static Widget createCheckbox(UiCheckbox chk) {} + + // // ui location + // // host|main|settings|display|others + // // client|remote|toolbar|display + // static Widget? create(String id, String locatin, UiType ui) { + // if (ui.button != null) { + // return createButton(ui.button!); + // } else if (ui.checkbox != null) { + // return createCheckbox(ui.checkbox!); + // } else { + // return null; + // } + // } +} + +void handleReloading(Map evt, String peer) { + if (evt['id'] == null || evt['location'] == null) { + return; + } + final ui = UiType.fromJson(evt); + if (!ui.isValid) { + return; + } + addLocation(evt['id']!, evt['location']!, ui); } diff --git a/flutter/lib/plugin/widgets/remote/toolbar/display.dart b/flutter/lib/plugin/widgets/remote/toolbar/display.dart new file mode 100644 index 000000000..1f7cc359e --- /dev/null +++ b/flutter/lib/plugin/widgets/remote/toolbar/display.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import '../../../model.dart'; + +class Display extends StatelessWidget { + final String peerId; + final LocationModel locationModel; + + Display({ + Key? key, + required this.peerId, + required this.locationModel, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return ChangeNotifierProvider.value( + value: locationModel, + child: Consumer(builder: (context, model, child) { + return Column( + children: [], + ); + }), + ); + } +}