Resolves #116 Add Iframe panel support
This commit is contained in:
parent
92d0b5c055
commit
74572168ae
@ -262,7 +262,6 @@ class HomeAssistant {
|
|||||||
await _sendInitialMessage("get_panels").then((data) {
|
await _sendInitialMessage("get_panels").then((data) {
|
||||||
if (data["success"]) {
|
if (data["success"]) {
|
||||||
data["result"].forEach((k,v) {
|
data["result"].forEach((k,v) {
|
||||||
if (k != "lovelace" && !v["component_name"].startsWith("dev-") && v["component_name"]!="profile" && v["component_name"]!="states" && v["component_name"]!="kiosk") {
|
|
||||||
String title = v['title'] == null ? "${k[0].toUpperCase()}${k.substring(1)}" : "${v['title'][0].toUpperCase()}${v['title'].substring(1)}";
|
String title = v['title'] == null ? "${k[0].toUpperCase()}${k.substring(1)}" : "${v['title'][0].toUpperCase()}${v['title'].substring(1)}";
|
||||||
panels.add(Panel(
|
panels.add(Panel(
|
||||||
id: k,
|
id: k,
|
||||||
@ -273,7 +272,6 @@ class HomeAssistant {
|
|||||||
icon: v["icon"]
|
icon: v["icon"]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -305,15 +305,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showPanelPage(Panel panel) {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => PanelPage(title: "${panel.title}", panel: panel),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Tab> buildUIViewTabs() {
|
List<Tab> buildUIViewTabs() {
|
||||||
List<Tab> result = [];
|
List<Tab> result = [];
|
||||||
|
|
||||||
@ -362,15 +353,24 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
} else {
|
} else {
|
||||||
if (_homeAssistant != null && _homeAssistant.panels.isNotEmpty) {
|
if (_homeAssistant != null && _homeAssistant.panels.isNotEmpty) {
|
||||||
_homeAssistant.panels.forEach((Panel panel) {
|
_homeAssistant.panels.forEach((Panel panel) {
|
||||||
|
if (!panel.isHidden) {
|
||||||
menuItems.add(
|
menuItems.add(
|
||||||
new ListTile(
|
new ListTile(
|
||||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)),
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)),
|
||||||
title: Text("${panel.title}(${panel.urlPath})"),
|
title: Text("${panel.title}"),
|
||||||
onTap: () =>_showPanelPage(panel)
|
onTap: () => panel.handleOpen(context)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
menuItems.add(Divider());
|
menuItems.addAll([
|
||||||
|
new ListTile(
|
||||||
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:home-assistant")),
|
||||||
|
title: Text("Open Web UI"),
|
||||||
|
onTap: null,
|
||||||
|
),
|
||||||
|
Divider()
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
menuItems.addAll([
|
menuItems.addAll([
|
||||||
new ListTile(
|
new ListTile(
|
||||||
|
@ -16,11 +16,30 @@ class Panel {
|
|||||||
final String urlPath;
|
final String urlPath;
|
||||||
final Map config;
|
final Map config;
|
||||||
String icon;
|
String icon;
|
||||||
|
bool isHidden = true;
|
||||||
|
|
||||||
Panel({this.id, this.type, this.title, this.urlPath, this.icon, this.config}) {
|
Panel({this.id, this.type, this.title, this.urlPath, this.icon, this.config}) {
|
||||||
if (icon == null || !icon.startsWith("mdi:")) {
|
if (icon == null || !icon.startsWith("mdi:")) {
|
||||||
icon = Panel.iconsByComponent[type];
|
icon = Panel.iconsByComponent[type];
|
||||||
}
|
}
|
||||||
|
isHidden = (type != "iframe");
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleOpen(BuildContext context) {
|
||||||
|
if (type == "iframe") {
|
||||||
|
Logger.d("Launching custom tab with ${config["url"]}");
|
||||||
|
HAUtils.launchURLInCustomTab(context, config["url"]);
|
||||||
|
} else if (type == "config") {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => PanelPage(title: "$title", panel: this),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
String url = "$homeAssistantWebHost/$urlPath";
|
||||||
|
Logger.d("Launching custom tab with $url");
|
||||||
|
HAUtils.launchURLInCustomTab(context, url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getWidget() {
|
Widget getWidget() {
|
||||||
|
Reference in New Issue
Block a user