diff --git a/lib/home_assistant.class.dart b/lib/home_assistant.class.dart index 84ddc81..8369428 100644 --- a/lib/home_assistant.class.dart +++ b/lib/home_assistant.class.dart @@ -262,7 +262,6 @@ class HomeAssistant { await _sendInitialMessage("get_panels").then((data) { if (data["success"]) { 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)}"; panels.add(Panel( id: k, @@ -273,7 +272,6 @@ class HomeAssistant { icon: v["icon"] ) ); - } }); } }); diff --git a/lib/main.dart b/lib/main.dart index 5b5780a..2b7f153 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -305,15 +305,6 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ); } - void _showPanelPage(Panel panel) { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PanelPage(title: "${panel.title}", panel: panel), - ) - ); - } - List buildUIViewTabs() { List result = []; @@ -362,15 +353,24 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker } else { if (_homeAssistant != null && _homeAssistant.panels.isNotEmpty) { _homeAssistant.panels.forEach((Panel panel) { - menuItems.add( - new ListTile( - leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)), - title: Text("${panel.title}(${panel.urlPath})"), - onTap: () =>_showPanelPage(panel) - ) - ); + if (!panel.isHidden) { + menuItems.add( + new ListTile( + leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)), + title: Text("${panel.title}"), + 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([ new ListTile( diff --git a/lib/ui_class/panel_class.dart b/lib/ui_class/panel_class.dart index 9361842..252f766 100644 --- a/lib/ui_class/panel_class.dart +++ b/lib/ui_class/panel_class.dart @@ -16,11 +16,30 @@ class Panel { final String urlPath; final Map config; String icon; + bool isHidden = true; Panel({this.id, this.type, this.title, this.urlPath, this.icon, this.config}) { if (icon == null || !icon.startsWith("mdi:")) { 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() {