feat: add entry in left panel
This commit is contained in:
parent
77fa807b57
commit
229df038fc
@ -14,6 +14,7 @@ import 'package:flutter_hbb/desktop/pages/desktop_tab_page.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/scroll_wrapper.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_hbb/plugin/ui_manager.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -88,6 +89,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
||||
}
|
||||
},
|
||||
),
|
||||
buildPluginEntry()
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -572,6 +574,22 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
||||
_updateTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget buildPluginEntry() {
|
||||
final entries = PluginUiManager.instance.entries.entries;
|
||||
return Offstage(
|
||||
offstage: entries.isEmpty,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...
|
||||
entries.map((entry) {
|
||||
return entry.value;
|
||||
})
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void setPasswordDialog() async {
|
||||
|
@ -2,6 +2,8 @@ import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/plugin/ui_manager.dart';
|
||||
import 'package:flutter_hbb/plugin/utils/dialogs.dart';
|
||||
|
||||
abstract class NativeHandler {
|
||||
@ -34,6 +36,15 @@ class NativeUiHandler extends NativeHandler {
|
||||
final cbFuncDart = cbFuncNative.asFunction<OnSelectPeersCallbackDart>();
|
||||
onSelectPeers(cbFuncDart, userData);
|
||||
break;
|
||||
case "register_ui_entry":
|
||||
int cb = evt['on_tap_cb'];
|
||||
int userData = evt['user_data'] ?? 0;
|
||||
String title = evt['title'] ?? "";
|
||||
final cbFuncNative = Pointer.fromAddress(cb)
|
||||
.cast<NativeFunction<OnSelectPeersCallback>>();
|
||||
final cbFuncDart = cbFuncNative.asFunction<OnSelectPeersCallbackDart>();
|
||||
onRegisterUiEntry(title, cbFuncDart, userData);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -50,4 +61,19 @@ class NativeUiHandler extends NativeHandler {
|
||||
malloc.free(native);
|
||||
});
|
||||
}
|
||||
|
||||
void onRegisterUiEntry(String title, OnSelectPeersCallbackDart cbFuncDart, int userData) {
|
||||
Widget widget = InkWell(
|
||||
child: Container(
|
||||
height: 25.0,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text(title)),
|
||||
Icon(Icons.chevron_right_rounded, size: 12.0,)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
PluginUiManager.instance.registerEntry(title, widget);
|
||||
}
|
||||
}
|
||||
|
17
flutter/lib/plugin/ui_manager.dart
Normal file
17
flutter/lib/plugin/ui_manager.dart
Normal file
@ -0,0 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PluginUiManager {
|
||||
PluginUiManager._();
|
||||
|
||||
static PluginUiManager instance = PluginUiManager._();
|
||||
|
||||
Map<String, Widget> entries = <String, Widget>{};
|
||||
|
||||
void registerEntry(String key, Widget widget) {
|
||||
entries[key] = widget;
|
||||
}
|
||||
|
||||
void unregisterEntry(String key) {
|
||||
entries.remove(key);
|
||||
}
|
||||
}
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "复制指纹"),
|
||||
("no fingerprints", "没有指纹"),
|
||||
("Select a peer", "选择一个被控端"),
|
||||
("Select peers", "选择被控端")
|
||||
("Select peers", "选择被控"),
|
||||
("Plugins", "插件")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "Fingerabdruck kopieren"),
|
||||
("no fingerprints", "Keine Fingerabdrücke"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "Copiar huella digital"),
|
||||
("no fingerprints", "sin huellas digitales"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "کپی کردن اثر انگشت"),
|
||||
("no fingerprints", "بدون اثر انگشت"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "Copia firma digitale"),
|
||||
("no fingerprints", "Nessuna firma digitale"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "Kopieer Vingerafdruk"),
|
||||
("no fingerprints", "geen vingerafdrukken"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "Skopiuj sygnaturę"),
|
||||
("no fingerprints", "brak sygnatur"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "Копировать отпечаток"),
|
||||
("no fingerprints", "отпечатки отсутствуют"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", "複製指紋"),
|
||||
("no fingerprints", "沒有指紋"),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Copy Fingerprint", ""),
|
||||
("no fingerprints", ""),
|
||||
("Select a peer", ""),
|
||||
("Select peers", "")
|
||||
("Select peers", ""),
|
||||
("Plugins", "")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -58,6 +58,33 @@ impl PluginNativeHandler for PluginNativeUIHandler {
|
||||
data: "missing cb field message".as_ptr() as _,
|
||||
});
|
||||
}
|
||||
"register_ui_entry" => {
|
||||
let title;
|
||||
if let Some(v) = data.get("title") {
|
||||
title = v.as_str().unwrap_or("");
|
||||
} else {
|
||||
title = "";
|
||||
}
|
||||
if let Some(on_tap_cb) = data.get("on_tap_cb") {
|
||||
if let Some(on_tap_cb) = on_tap_cb.as_u64() {
|
||||
let user_data = match data.get("user_data") {
|
||||
Some(user_data) => {
|
||||
user_data.as_u64().unwrap_or(0)
|
||||
},
|
||||
None => 0,
|
||||
};
|
||||
self.register_ui_entry(title, on_tap_cb, user_data);
|
||||
return Some(super::NR {
|
||||
return_type: 0,
|
||||
data: std::ptr::null(),
|
||||
});
|
||||
}
|
||||
}
|
||||
return Some(super::NR {
|
||||
return_type: -1,
|
||||
data: "missing cb field message".as_ptr() as _,
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
None
|
||||
@ -97,4 +124,26 @@ impl PluginNativeUIHandler {
|
||||
serde_json::to_string(¶m).unwrap_or("".to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
/// Call with method `register_ui_entry` and the following json:
|
||||
/// ```
|
||||
/// {
|
||||
///
|
||||
/// "on_tap_cb": 0, // The function address
|
||||
/// "user_data": 0, // An opaque pointer value passed to the callback.
|
||||
/// "title": "entry name"
|
||||
/// }
|
||||
/// ```
|
||||
fn register_ui_entry(&self, title: &str, on_tap_cb: u64, user_data: u64) {
|
||||
let mut param = HashMap::new();
|
||||
param.insert("name", json!("native_ui"));
|
||||
param.insert("action", json!("register_ui_entry"));
|
||||
param.insert("title", json!(title));
|
||||
param.insert("cb", json!(on_tap_cb));
|
||||
param.insert("user_data", json!(user_data));
|
||||
crate::flutter::push_global_event(
|
||||
APP_TYPE_MAIN,
|
||||
serde_json::to_string(¶m).unwrap_or("".to_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user