Merge pull request #4132 from fufesou/feat/plugin_framework
Feat/plugin framework
This commit is contained in:
commit
e2ca802d98
flutter/lib
desktop
models
plugin
src
49
flutter/lib/desktop/plugin/common.dart
Normal file
49
flutter/lib/desktop/plugin/common.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
typedef PluginId = String;
|
||||||
|
|
||||||
|
// ui location
|
||||||
|
const String kLocationHostMainDisplayOthers =
|
||||||
|
'host|main|settings|display|others';
|
||||||
|
const String kLocationClientRemoteToolbarDisplay =
|
||||||
|
'client|remote|toolbar|display';
|
||||||
|
|
||||||
|
class MsgFromUi {
|
||||||
|
String remotePeerId;
|
||||||
|
String localPeerId;
|
||||||
|
String id;
|
||||||
|
String name;
|
||||||
|
String location;
|
||||||
|
String key;
|
||||||
|
String value;
|
||||||
|
String action;
|
||||||
|
|
||||||
|
MsgFromUi({
|
||||||
|
required this.remotePeerId,
|
||||||
|
required this.localPeerId,
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.location,
|
||||||
|
required this.key,
|
||||||
|
required this.value,
|
||||||
|
required this.action,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return <String, dynamic>{
|
||||||
|
'remote_peer_id': remotePeerId,
|
||||||
|
'local_peer_id': localPeerId,
|
||||||
|
'id': id,
|
||||||
|
'name': name,
|
||||||
|
'location': location,
|
||||||
|
'key': key,
|
||||||
|
'value': value,
|
||||||
|
'action': action,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return jsonEncode(toJson());
|
||||||
|
}
|
||||||
|
}
|
@ -1,49 +1,75 @@
|
|||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
|
||||||
class UiButton {
|
const String kValueTrue = '1';
|
||||||
String key;
|
const String kValueFalse = '0';
|
||||||
String text;
|
|
||||||
String icon;
|
|
||||||
String tooltip;
|
|
||||||
String action;
|
|
||||||
|
|
||||||
UiButton(this.key, this.text, this.icon, this.tooltip, this.action);
|
|
||||||
UiButton.fromJson(Map<String, dynamic> json)
|
|
||||||
: key = json['key'] ?? '',
|
|
||||||
text = json['text'] ?? '',
|
|
||||||
icon = json['icon'] ?? '',
|
|
||||||
tooltip = json['tooltip'] ?? '',
|
|
||||||
action = json['action'] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
class UiCheckbox {
|
|
||||||
String key;
|
|
||||||
String text;
|
|
||||||
String tooltip;
|
|
||||||
String action;
|
|
||||||
|
|
||||||
UiCheckbox(this.key, this.text, this.tooltip, this.action);
|
|
||||||
UiCheckbox.fromJson(Map<String, dynamic> json)
|
|
||||||
: key = json['key'] ?? '',
|
|
||||||
text = json['text'] ?? '',
|
|
||||||
tooltip = json['tooltip'] ?? '',
|
|
||||||
action = json['action'] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
class UiType {
|
class UiType {
|
||||||
UiButton? button;
|
String key;
|
||||||
UiCheckbox? checkbox;
|
String text;
|
||||||
|
String tooltip;
|
||||||
|
String action;
|
||||||
|
|
||||||
|
UiType(this.key, this.text, this.tooltip, this.action);
|
||||||
|
|
||||||
UiType.fromJson(Map<String, dynamic> json)
|
UiType.fromJson(Map<String, dynamic> json)
|
||||||
: button = json['t'] == 'Button' ? UiButton.fromJson(json['c']) : null,
|
: key = json['key'] ?? '',
|
||||||
checkbox =
|
text = json['text'] ?? '',
|
||||||
json['t'] != 'Checkbox' ? UiCheckbox.fromJson(json['c']) : null;
|
tooltip = json['tooltip'] ?? '',
|
||||||
|
action = json['action'] ?? '';
|
||||||
|
|
||||||
|
static UiType? create(Map<String, dynamic> json) {
|
||||||
|
if (json['t'] == 'Button') {
|
||||||
|
return UiButton.fromJson(json['c']);
|
||||||
|
} else if (json['t'] == 'Checkbox') {
|
||||||
|
return UiCheckbox.fromJson(json['c']);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UiButton extends UiType {
|
||||||
|
String icon;
|
||||||
|
|
||||||
|
UiButton(
|
||||||
|
{required String key,
|
||||||
|
required String text,
|
||||||
|
required this.icon,
|
||||||
|
required String tooltip,
|
||||||
|
required String action})
|
||||||
|
: super(key, text, tooltip, action);
|
||||||
|
|
||||||
|
UiButton.fromJson(Map<String, dynamic> json)
|
||||||
|
: icon = json['icon'] ?? '',
|
||||||
|
super.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
class UiCheckbox extends UiType {
|
||||||
|
UiCheckbox(
|
||||||
|
{required String key,
|
||||||
|
required String text,
|
||||||
|
required String tooltip,
|
||||||
|
required String action})
|
||||||
|
: super(key, text, tooltip, action);
|
||||||
|
|
||||||
|
UiCheckbox.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Location {
|
class Location {
|
||||||
|
// location key:
|
||||||
|
// host|main|settings|display|others
|
||||||
|
// client|remote|toolbar|display
|
||||||
HashMap<String, UiType> ui;
|
HashMap<String, UiType> ui;
|
||||||
|
|
||||||
Location(this.ui);
|
Location(this.ui);
|
||||||
|
Location.fromJson(Map<String, dynamic> json) : ui = HashMap() {
|
||||||
|
json.forEach((key, value) {
|
||||||
|
var ui = UiType.create(value);
|
||||||
|
if (ui != null) {
|
||||||
|
this.ui[ui.key] = ui;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigItem {
|
class ConfigItem {
|
||||||
@ -58,6 +84,11 @@ class ConfigItem {
|
|||||||
value = json['value'] ?? '',
|
value = json['value'] ?? '',
|
||||||
description = json['description'] ?? '',
|
description = json['description'] ?? '',
|
||||||
defaultValue = json['default'] ?? '';
|
defaultValue = json['default'] ?? '';
|
||||||
|
|
||||||
|
static String get trueValue => kValueTrue;
|
||||||
|
static String get falseValue => kValueFalse;
|
||||||
|
static bool isTrue(String value) => value == kValueTrue;
|
||||||
|
static bool isFalse(String value) => value == kValueFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Config {
|
class Config {
|
44
flutter/lib/desktop/plugin/model.dart
Normal file
44
flutter/lib/desktop/plugin/model.dart
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import './common.dart';
|
||||||
|
import './desc.dart';
|
||||||
|
|
||||||
|
final Map<String, LocationModel> locationModels = {};
|
||||||
|
|
||||||
|
class PluginModel with ChangeNotifier {
|
||||||
|
final List<UiType> uiList = [];
|
||||||
|
|
||||||
|
void add(UiType ui) {
|
||||||
|
uiList.add(ui);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isEmpty => uiList.isEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocationModel with ChangeNotifier {
|
||||||
|
final Map<PluginId, PluginModel> pluginModels = {};
|
||||||
|
|
||||||
|
void add(PluginId id, UiType ui) {
|
||||||
|
if (pluginModels[id] != null) {
|
||||||
|
pluginModels[id]!.add(ui);
|
||||||
|
} else {
|
||||||
|
var model = PluginModel();
|
||||||
|
model.add(ui);
|
||||||
|
pluginModels[id] = model;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isEmpty => pluginModels.isEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addLocationUi(String location, PluginId id, UiType ui) {
|
||||||
|
locationModels[location]?.add(id, ui);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocationModel addLocation(String location) {
|
||||||
|
if (locationModels[location] == null) {
|
||||||
|
locationModels[location] = LocationModel();
|
||||||
|
}
|
||||||
|
return locationModels[location]!;
|
||||||
|
}
|
175
flutter/lib/desktop/plugin/widget.dart
Normal file
175
flutter/lib/desktop/plugin/widget.dart
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/widgets/remote_toolbar.dart';
|
||||||
|
import 'package:flutter_hbb/models/platform_model.dart';
|
||||||
|
|
||||||
|
import './desc.dart';
|
||||||
|
import './model.dart';
|
||||||
|
import './common.dart';
|
||||||
|
|
||||||
|
class LocationItem extends StatelessWidget {
|
||||||
|
final String peerId;
|
||||||
|
final FFI ffi;
|
||||||
|
final String location;
|
||||||
|
final LocationModel locationModel;
|
||||||
|
|
||||||
|
LocationItem({
|
||||||
|
Key? key,
|
||||||
|
required this.peerId,
|
||||||
|
required this.ffi,
|
||||||
|
required this.location,
|
||||||
|
required this.locationModel,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
bool get isEmpty => locationModel.isEmpty;
|
||||||
|
|
||||||
|
static LocationItem createLocationItem(
|
||||||
|
String peerId, FFI ffi, String location) {
|
||||||
|
final model = addLocation(location);
|
||||||
|
return LocationItem(
|
||||||
|
peerId: peerId,
|
||||||
|
ffi: ffi,
|
||||||
|
location: location,
|
||||||
|
locationModel: model,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ChangeNotifierProvider.value(
|
||||||
|
value: locationModel,
|
||||||
|
child: Consumer<LocationModel>(builder: (context, model, child) {
|
||||||
|
return Column(
|
||||||
|
children: model.pluginModels.entries
|
||||||
|
.map((entry) => _buildPluginItem(entry.key, entry.value))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildPluginItem(PluginId id, PluginModel model) => PluginItem(
|
||||||
|
pluginId: id,
|
||||||
|
peerId: peerId,
|
||||||
|
ffi: ffi,
|
||||||
|
location: location,
|
||||||
|
pluginModel: model,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PluginItem extends StatelessWidget {
|
||||||
|
final PluginId pluginId;
|
||||||
|
final String peerId;
|
||||||
|
final FFI ffi;
|
||||||
|
final String location;
|
||||||
|
final PluginModel pluginModel;
|
||||||
|
|
||||||
|
PluginItem({
|
||||||
|
Key? key,
|
||||||
|
required this.pluginId,
|
||||||
|
required this.peerId,
|
||||||
|
required this.ffi,
|
||||||
|
required this.location,
|
||||||
|
required this.pluginModel,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
bool get isEmpty => pluginModel.isEmpty;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ChangeNotifierProvider.value(
|
||||||
|
value: pluginModel,
|
||||||
|
child: Consumer<PluginModel>(builder: (context, model, child) {
|
||||||
|
return Column(
|
||||||
|
children: model.uiList.map((ui) => _buildItem(ui)).toList(),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// to-do: add plugin icon and tooltip
|
||||||
|
Widget _buildItem(UiType ui) {
|
||||||
|
switch (ui.runtimeType) {
|
||||||
|
case UiButton:
|
||||||
|
return _buildMenuButton(ui as UiButton);
|
||||||
|
case UiCheckbox:
|
||||||
|
return _buildCheckboxMenuButton(ui as UiCheckbox);
|
||||||
|
default:
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8List _makeEvent(
|
||||||
|
String localPeerId,
|
||||||
|
String key, {
|
||||||
|
bool? v,
|
||||||
|
}) {
|
||||||
|
final event = MsgFromUi(
|
||||||
|
remotePeerId: peerId,
|
||||||
|
localPeerId: localPeerId,
|
||||||
|
id: pluginId,
|
||||||
|
name: getDesc(pluginId)?.name ?? '',
|
||||||
|
location: location,
|
||||||
|
key: key,
|
||||||
|
value:
|
||||||
|
v != null ? (v ? ConfigItem.trueValue : ConfigItem.falseValue) : '',
|
||||||
|
action: '',
|
||||||
|
);
|
||||||
|
return Uint8List.fromList(event.toString().codeUnits);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildMenuButton(UiButton ui) {
|
||||||
|
return MenuButton(
|
||||||
|
onPressed: () {
|
||||||
|
() async {
|
||||||
|
final localPeerId = await bind.mainGetMyId();
|
||||||
|
bind.pluginEvent(
|
||||||
|
id: pluginId,
|
||||||
|
event: _makeEvent(localPeerId, ui.key),
|
||||||
|
);
|
||||||
|
}();
|
||||||
|
},
|
||||||
|
trailingIcon: Icon(
|
||||||
|
IconData(int.parse(ui.icon, radix: 16), fontFamily: 'MaterialIcons')),
|
||||||
|
// to-do: RustDesk translate or plugin translate ?
|
||||||
|
child: Text(ui.text),
|
||||||
|
ffi: ffi,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCheckboxMenuButton(UiCheckbox ui) {
|
||||||
|
final v =
|
||||||
|
bind.pluginGetSessionOption(id: pluginId, peer: peerId, key: ui.key);
|
||||||
|
if (v == null) {
|
||||||
|
// session or plugin not found
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
return CkbMenuButton(
|
||||||
|
value: ConfigItem.isTrue(v),
|
||||||
|
onChanged: (v) {
|
||||||
|
if (v != null) {
|
||||||
|
() async {
|
||||||
|
final localPeerId = await bind.mainGetMyId();
|
||||||
|
bind.pluginEvent(
|
||||||
|
id: pluginId,
|
||||||
|
event: _makeEvent(localPeerId, ui.key, v: v),
|
||||||
|
);
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// to-do: rustdesk translate or plugin translate ?
|
||||||
|
child: Text(ui.text),
|
||||||
|
ffi: ffi,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleReloading(Map<String, dynamic> evt, String peer) {
|
||||||
|
if (evt['id'] == null || evt['location'] == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ui = UiType.fromJson(evt);
|
||||||
|
addLocationUi(evt['location']!, evt['id']!, ui);
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -9,6 +8,8 @@ import 'package:flutter_hbb/models/chat_model.dart';
|
|||||||
import 'package:flutter_hbb/models/state_model.dart';
|
import 'package:flutter_hbb/models/state_model.dart';
|
||||||
import 'package:flutter_hbb/consts.dart';
|
import 'package:flutter_hbb/consts.dart';
|
||||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/plugin/widget.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/plugin/common.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -641,7 +642,7 @@ class _ControlMenu extends StatelessWidget {
|
|||||||
if (e.divider) {
|
if (e.divider) {
|
||||||
return Divider();
|
return Divider();
|
||||||
} else {
|
} else {
|
||||||
return _MenuItemButton(
|
return MenuButton(
|
||||||
child: e.child,
|
child: e.child,
|
||||||
onPressed: e.onPressed,
|
onPressed: e.onPressed,
|
||||||
ffi: ffi,
|
ffi: ffi,
|
||||||
@ -656,13 +657,19 @@ class _DisplayMenu extends StatefulWidget {
|
|||||||
final FFI ffi;
|
final FFI ffi;
|
||||||
final MenubarState state;
|
final MenubarState state;
|
||||||
final Function(bool) setFullscreen;
|
final Function(bool) setFullscreen;
|
||||||
|
final LocationItem pluginItem;
|
||||||
_DisplayMenu(
|
_DisplayMenu(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.ffi,
|
required this.ffi,
|
||||||
required this.state,
|
required this.state,
|
||||||
required this.setFullscreen})
|
required this.setFullscreen})
|
||||||
: super(key: key);
|
: pluginItem = LocationItem.createLocationItem(
|
||||||
|
id,
|
||||||
|
ffi,
|
||||||
|
kLocationClientRemoteToolbarDisplay,
|
||||||
|
),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_DisplayMenu> createState() => _DisplayMenuState();
|
State<_DisplayMenu> createState() => _DisplayMenuState();
|
||||||
@ -700,6 +707,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
resolutions(),
|
resolutions(),
|
||||||
Divider(),
|
Divider(),
|
||||||
toggles(),
|
toggles(),
|
||||||
|
widget.pluginItem,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,7 +719,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
if (!visible) return Offstage();
|
if (!visible) return Offstage();
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
_MenuItemButton(
|
MenuButton(
|
||||||
child: Text(translate('Adjust Window')),
|
child: Text(translate('Adjust Window')),
|
||||||
onPressed: _doAdjustWindow,
|
onPressed: _doAdjustWindow,
|
||||||
ffi: widget.ffi),
|
ffi: widget.ffi),
|
||||||
@ -828,7 +836,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
final v = data as List<TRadioMenu<String>>;
|
final v = data as List<TRadioMenu<String>>;
|
||||||
return Column(children: [
|
return Column(children: [
|
||||||
...v
|
...v
|
||||||
.map((e) => _RadioMenuButton<String>(
|
.map((e) => RdoMenuButton<String>(
|
||||||
value: e.value,
|
value: e.value,
|
||||||
groupValue: e.groupValue,
|
groupValue: e.groupValue,
|
||||||
onChanged: e.onChanged,
|
onChanged: e.onChanged,
|
||||||
@ -858,14 +866,14 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
|
|
||||||
final enabled = widget.ffi.canvasModel.imageOverflow.value;
|
final enabled = widget.ffi.canvasModel.imageOverflow.value;
|
||||||
return Column(children: [
|
return Column(children: [
|
||||||
_RadioMenuButton<String>(
|
RdoMenuButton<String>(
|
||||||
child: Text(translate('ScrollAuto')),
|
child: Text(translate('ScrollAuto')),
|
||||||
value: kRemoteScrollStyleAuto,
|
value: kRemoteScrollStyleAuto,
|
||||||
groupValue: groupValue,
|
groupValue: groupValue,
|
||||||
onChanged: enabled ? (value) => onChange(value) : null,
|
onChanged: enabled ? (value) => onChange(value) : null,
|
||||||
ffi: widget.ffi,
|
ffi: widget.ffi,
|
||||||
),
|
),
|
||||||
_RadioMenuButton<String>(
|
RdoMenuButton<String>(
|
||||||
child: Text(translate('Scrollbar')),
|
child: Text(translate('Scrollbar')),
|
||||||
value: kRemoteScrollStyleBar,
|
value: kRemoteScrollStyleBar,
|
||||||
groupValue: groupValue,
|
groupValue: groupValue,
|
||||||
@ -886,7 +894,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
ffi: widget.ffi,
|
ffi: widget.ffi,
|
||||||
child: Text(translate('Image Quality')),
|
child: Text(translate('Image Quality')),
|
||||||
menuChildren: v
|
menuChildren: v
|
||||||
.map((e) => _RadioMenuButton<String>(
|
.map((e) => RdoMenuButton<String>(
|
||||||
value: e.value,
|
value: e.value,
|
||||||
groupValue: e.groupValue,
|
groupValue: e.groupValue,
|
||||||
onChanged: e.onChanged,
|
onChanged: e.onChanged,
|
||||||
@ -908,7 +916,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
ffi: widget.ffi,
|
ffi: widget.ffi,
|
||||||
child: Text(translate('Codec')),
|
child: Text(translate('Codec')),
|
||||||
menuChildren: v
|
menuChildren: v
|
||||||
.map((e) => _RadioMenuButton(
|
.map((e) => RdoMenuButton(
|
||||||
value: e.value,
|
value: e.value,
|
||||||
groupValue: e.groupValue,
|
groupValue: e.groupValue,
|
||||||
onChanged: e.onChanged,
|
onChanged: e.onChanged,
|
||||||
@ -948,7 +956,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
return _SubmenuButton(
|
return _SubmenuButton(
|
||||||
ffi: widget.ffi,
|
ffi: widget.ffi,
|
||||||
menuChildren: resolutions
|
menuChildren: resolutions
|
||||||
.map((e) => _RadioMenuButton(
|
.map((e) => RdoMenuButton(
|
||||||
value: '${e.width}x${e.height}',
|
value: '${e.width}x${e.height}',
|
||||||
groupValue: groupValue,
|
groupValue: groupValue,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
@ -966,7 +974,7 @@ class _DisplayMenuState extends State<_DisplayMenu> {
|
|||||||
if (v.isEmpty) return Offstage();
|
if (v.isEmpty) return Offstage();
|
||||||
return Column(
|
return Column(
|
||||||
children: v
|
children: v
|
||||||
.map((e) => _CheckboxMenuButton(
|
.map((e) => CkbMenuButton(
|
||||||
value: e.value,
|
value: e.value,
|
||||||
onChanged: e.onChanged,
|
onChanged: e.onChanged,
|
||||||
child: e.child,
|
child: e.child,
|
||||||
@ -1026,7 +1034,7 @@ class _KeyboardMenu extends StatelessWidget {
|
|||||||
KeyboardModeMenu(key: _kKeyMapMode, menu: 'Map mode'),
|
KeyboardModeMenu(key: _kKeyMapMode, menu: 'Map mode'),
|
||||||
KeyboardModeMenu(key: _kKeyTranslateMode, menu: 'Translate mode'),
|
KeyboardModeMenu(key: _kKeyTranslateMode, menu: 'Translate mode'),
|
||||||
];
|
];
|
||||||
List<_RadioMenuButton> list = [];
|
List<RdoMenuButton> list = [];
|
||||||
final enabled = !ffi.ffiModel.viewOnly;
|
final enabled = !ffi.ffiModel.viewOnly;
|
||||||
onChanged(String? value) async {
|
onChanged(String? value) async {
|
||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
@ -1049,7 +1057,7 @@ class _KeyboardMenu extends StatelessWidget {
|
|||||||
if (mode.key == _kKeyTranslateMode) {
|
if (mode.key == _kKeyTranslateMode) {
|
||||||
text = '$text beta';
|
text = '$text beta';
|
||||||
}
|
}
|
||||||
list.add(_RadioMenuButton<String>(
|
list.add(RdoMenuButton<String>(
|
||||||
child: Text(text),
|
child: Text(text),
|
||||||
value: mode.key,
|
value: mode.key,
|
||||||
groupValue: groupValue,
|
groupValue: groupValue,
|
||||||
@ -1069,7 +1077,7 @@ class _KeyboardMenu extends StatelessWidget {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Divider(),
|
Divider(),
|
||||||
_MenuItemButton(
|
MenuButton(
|
||||||
child: Text(
|
child: Text(
|
||||||
'${translate('Local keyboard type')}: ${KBLayoutType.value}'),
|
'${translate('Local keyboard type')}: ${KBLayoutType.value}'),
|
||||||
trailingIcon: const Icon(Icons.settings),
|
trailingIcon: const Icon(Icons.settings),
|
||||||
@ -1085,7 +1093,7 @@ class _KeyboardMenu extends StatelessWidget {
|
|||||||
view_mode() {
|
view_mode() {
|
||||||
final ffiModel = ffi.ffiModel;
|
final ffiModel = ffi.ffiModel;
|
||||||
final enabled = version_cmp(pi.version, '1.2.0') >= 0 && ffiModel.keyboard;
|
final enabled = version_cmp(pi.version, '1.2.0') >= 0 && ffiModel.keyboard;
|
||||||
return _CheckboxMenuButton(
|
return CkbMenuButton(
|
||||||
value: ffiModel.viewOnly,
|
value: ffiModel.viewOnly,
|
||||||
onChanged: enabled
|
onChanged: enabled
|
||||||
? (value) async {
|
? (value) async {
|
||||||
@ -1129,7 +1137,7 @@ class _ChatMenuState extends State<_ChatMenu> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
textChat() {
|
textChat() {
|
||||||
return _MenuItemButton(
|
return MenuButton(
|
||||||
child: Text(translate('Text chat')),
|
child: Text(translate('Text chat')),
|
||||||
ffi: widget.ffi,
|
ffi: widget.ffi,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -1148,7 +1156,7 @@ class _ChatMenuState extends State<_ChatMenu> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
voiceCall() {
|
voiceCall() {
|
||||||
return _MenuItemButton(
|
return MenuButton(
|
||||||
child: Text(translate('Voice call')),
|
child: Text(translate('Voice call')),
|
||||||
ffi: widget.ffi,
|
ffi: widget.ffi,
|
||||||
onPressed: () => bind.sessionRequestVoiceCall(id: widget.id),
|
onPressed: () => bind.sessionRequestVoiceCall(id: widget.id),
|
||||||
@ -1403,12 +1411,12 @@ class _SubmenuButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MenuItemButton extends StatelessWidget {
|
class MenuButton extends StatelessWidget {
|
||||||
final VoidCallback? onPressed;
|
final VoidCallback? onPressed;
|
||||||
final Widget? trailingIcon;
|
final Widget? trailingIcon;
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
final FFI ffi;
|
final FFI ffi;
|
||||||
_MenuItemButton(
|
MenuButton(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
this.onPressed,
|
this.onPressed,
|
||||||
this.trailingIcon,
|
this.trailingIcon,
|
||||||
@ -1431,12 +1439,12 @@ class _MenuItemButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CheckboxMenuButton extends StatelessWidget {
|
class CkbMenuButton extends StatelessWidget {
|
||||||
final bool? value;
|
final bool? value;
|
||||||
final ValueChanged<bool?>? onChanged;
|
final ValueChanged<bool?>? onChanged;
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
final FFI ffi;
|
final FFI ffi;
|
||||||
const _CheckboxMenuButton(
|
const CkbMenuButton(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.value,
|
required this.value,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
@ -1460,13 +1468,13 @@ class _CheckboxMenuButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RadioMenuButton<T> extends StatelessWidget {
|
class RdoMenuButton<T> extends StatelessWidget {
|
||||||
final T value;
|
final T value;
|
||||||
final T? groupValue;
|
final T? groupValue;
|
||||||
final ValueChanged<T?>? onChanged;
|
final ValueChanged<T?>? onChanged;
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
final FFI ffi;
|
final FFI ffi;
|
||||||
const _RadioMenuButton(
|
const RdoMenuButton(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.value,
|
required this.value,
|
||||||
required this.groupValue,
|
required this.groupValue,
|
||||||
|
@ -16,8 +16,9 @@ import 'package:flutter_hbb/models/peer_tab_model.dart';
|
|||||||
import 'package:flutter_hbb/models/server_model.dart';
|
import 'package:flutter_hbb/models/server_model.dart';
|
||||||
import 'package:flutter_hbb/models/user_model.dart';
|
import 'package:flutter_hbb/models/user_model.dart';
|
||||||
import 'package:flutter_hbb/models/state_model.dart';
|
import 'package:flutter_hbb/models/state_model.dart';
|
||||||
import 'package:flutter_hbb/plugin/event.dart';
|
import 'package:flutter_hbb/desktop/plugin/event.dart';
|
||||||
import 'package:flutter_hbb/plugin/reloader.dart';
|
import 'package:flutter_hbb/desktop/plugin/desc.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/plugin/widget.dart';
|
||||||
import 'package:flutter_hbb/common/shared_state.dart';
|
import 'package:flutter_hbb/common/shared_state.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
import 'package:image/image.dart' as img2;
|
import 'package:image/image.dart' as img2;
|
||||||
@ -229,7 +230,7 @@ class FfiModel with ChangeNotifier {
|
|||||||
} else if (name == "fingerprint") {
|
} else if (name == "fingerprint") {
|
||||||
FingerprintState.find(peerId).value = evt['fingerprint'] ?? '';
|
FingerprintState.find(peerId).value = evt['fingerprint'] ?? '';
|
||||||
} else if (name == "plugin_desc") {
|
} else if (name == "plugin_desc") {
|
||||||
handleReloading(evt, peerId);
|
updateDesc(evt);
|
||||||
} else if (name == "plugin_event") {
|
} else if (name == "plugin_event") {
|
||||||
handlePluginEvent(
|
handlePluginEvent(
|
||||||
evt, peerId, (Map<String, dynamic> e) => handleMsgBox(e, peerId));
|
evt, peerId, (Map<String, dynamic> e) => handleMsgBox(e, peerId));
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
void handleReloading(Map<String, dynamic> 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"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
final Map<String, PluginWidget> pluginWidgets = {};
|
|
||||||
|
|
||||||
class PluginWidget {
|
|
||||||
final String id;
|
|
||||||
final String name;
|
|
||||||
final String location;
|
|
||||||
final Widget widget;
|
|
||||||
|
|
||||||
PluginWidget({
|
|
||||||
required this.id,
|
|
||||||
required this.name,
|
|
||||||
required this.location,
|
|
||||||
required this.widget,
|
|
||||||
});
|
|
||||||
}
|
|
@ -1405,6 +1405,58 @@ pub fn plugin_event(_id: String, _event: Vec<u8>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn plugin_get_session_option(_id: String, _peer: String, _key: String) -> SyncReturn<Option<String>> {
|
||||||
|
#[cfg(feature = "plugin_framework")]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
{
|
||||||
|
return SyncReturn(crate::plugin::PeerConfig::get(&_id, &_peer, &_key));
|
||||||
|
}
|
||||||
|
#[cfg(any(
|
||||||
|
not(feature = "plugin_framework"),
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "ios"
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
return SyncReturn(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn plugin_set_session_option(_id: String, _peer: String, _key: String, _value: String) {
|
||||||
|
#[cfg(feature = "plugin_framework")]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
{
|
||||||
|
crate::plugin::PeerConfig::set(&_id, &_peer, &_key, &_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn plugin_get_local_option(_id: String, _key: String) -> SyncReturn<Option<String>> {
|
||||||
|
#[cfg(feature = "plugin_framework")]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
{
|
||||||
|
return SyncReturn(crate::plugin::LocalConfig::get(&_id, &_key));
|
||||||
|
}
|
||||||
|
#[cfg(any(
|
||||||
|
not(feature = "plugin_framework"),
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "ios"
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
return SyncReturn(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn plugin_set_local_option(_id: String, _key: String, _value: String) {
|
||||||
|
#[cfg(feature = "plugin_framework")]
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
{
|
||||||
|
crate::plugin::LocalConfig::set(&_id, &_key, &_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub mod server_side {
|
pub mod server_side {
|
||||||
use hbb_common::{config, log};
|
use hbb_common::{config, log};
|
||||||
|
@ -15,9 +15,9 @@ lazy_static::lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||||
struct LocalConfig(HashMap<String, String>);
|
pub struct LocalConfig(HashMap<String, String>);
|
||||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||||
struct PeerConfig(HashMap<String, String>);
|
pub struct PeerConfig(HashMap<String, String>);
|
||||||
type PeersConfig = HashMap<String, PeerConfig>;
|
type PeersConfig = HashMap<String, PeerConfig>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -8,7 +8,7 @@ use std::ffi::{c_char, CStr};
|
|||||||
pub struct UiButton {
|
pub struct UiButton {
|
||||||
key: String,
|
key: String,
|
||||||
text: String,
|
text: String,
|
||||||
icon: String,
|
icon: String, // icon can be int in flutter, but string in other ui framework. And it is flexible to use string.
|
||||||
tooltip: String,
|
tooltip: String,
|
||||||
action: String, // The action to be triggered when the button is clicked.
|
action: String, // The action to be triggered when the button is clicked.
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ pub use plugins::{
|
|||||||
reload_plugin, unload_plugin,
|
reload_plugin, unload_plugin,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use config::{LocalConfig, PeerConfig};
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cstr_to_string(cstr: *const c_char) -> ResultType<String> {
|
fn cstr_to_string(cstr: *const c_char) -> ResultType<String> {
|
||||||
Ok(String::from_utf8(unsafe {
|
Ok(String::from_utf8(unsafe {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user