From 3c0ca5d16d4816b20b3534bb68d28e2a53d4e837 Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Fri, 21 Jun 2019 21:01:53 +0300 Subject: [PATCH] Resolve #382 VIew camera in chrome custom tab --- .../common/camera_stream_view.dart | 17 +++++++++++----- lib/main.dart | 8 ++++---- lib/ui_class/panel_class.dart | 4 ++-- lib/ui_widgets/config_panel_widget.dart | 20 +++++++++---------- lib/utils.class.dart | 6 +++--- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/lib/entity_widgets/common/camera_stream_view.dart b/lib/entity_widgets/common/camera_stream_view.dart index b9ebd08..b6a5afe 100644 --- a/lib/entity_widgets/common/camera_stream_view.dart +++ b/lib/entity_widgets/common/camera_stream_view.dart @@ -17,10 +17,15 @@ class _CameraStreamViewState extends State { CameraEntity _entity; bool started = false; + String streamUrl = ""; launchStream() { - HAUtils.launchURLInCustomTab(context, '${Connection().httpWebHost}/api/camera_proxy_stream/${_entity - .entityId}?token=${_entity.attributes['access_token']}'); + HAUtils.launchURLInCustomTab( + context: context, + url: streamUrl, + enableDefaultShare: false, + showPageTitle: false + ); } @override @@ -32,13 +37,15 @@ class _CameraStreamViewState extends State { .entity; started = true; } + streamUrl = '${Connection().httpWebHost}/api/camera_proxy_stream/${_entity + .entityId}?token=${_entity.attributes['access_token']}'; return Column( children: [ Container( padding: const EdgeInsets.all(20.0), - child: FlatButton( - child: Text("View camera stream"), - onPressed: () => launchStream(), + child: IconButton( + icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:monitor-screenshot"), color: Colors.amber), + iconSize: 50.0 ) ) ], diff --git a/lib/main.dart b/lib/main.dart index c43ad69..03b6a63 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -153,7 +153,7 @@ class HAClientApp extends StatelessWidget { appBar: new AppBar( leading: IconButton( icon: Icon(Icons.help), - onPressed: () => HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/docs#authentication") + onPressed: () => HAUtils.launchURLInCustomTab(context: context, url: "http://ha-client.homemade.systems/docs#authentication") ), title: new Text("Login to your Home Assistant"), ), @@ -548,7 +548,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker GestureDetector( onTap: () { Navigator.of(context).pop(); - HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/terms_and_conditions"); + HAUtils.launchURLInCustomTab(context: context, url: "http://ha-client.homemade.systems/terms_and_conditions"); }, child: Text( "Terms and Conditions", @@ -564,7 +564,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker GestureDetector( onTap: () { Navigator.of(context).pop(); - HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/privacy_policy"); + HAUtils.launchURLInCustomTab(context: context, url: "http://ha-client.homemade.systems/privacy_policy"); }, child: Text( "Privacy Policy", @@ -649,7 +649,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker actions.add(FlatButton( child: Text("${action.title}", style: textStyle), onPressed: () { - HAUtils.launchURLInCustomTab(context, "${action.url}"); + HAUtils.launchURLInCustomTab(context: context, url: "${action.url}"); }, )); break; diff --git a/lib/ui_class/panel_class.dart b/lib/ui_class/panel_class.dart index bbb1dd0..8f4c9ef 100644 --- a/lib/ui_class/panel_class.dart +++ b/lib/ui_class/panel_class.dart @@ -28,7 +28,7 @@ class Panel { void handleOpen(BuildContext context) { if (type == "iframe") { Logger.d("Launching custom tab with ${config["url"]}"); - HAUtils.launchURLInCustomTab(context, config["url"]); + HAUtils.launchURLInCustomTab(context: context, url: config["url"]); } else if (type == "config") { Navigator.of(context).push( MaterialPageRoute( @@ -38,7 +38,7 @@ class Panel { } else { String url = "${Connection().httpWebHost}/$urlPath"; Logger.d("Launching custom tab with $url"); - HAUtils.launchURLInCustomTab(context, url); + HAUtils.launchURLInCustomTab(context: context, url: url); } } diff --git a/lib/ui_widgets/config_panel_widget.dart b/lib/ui_widgets/config_panel_widget.dart index 92528ab..51d0a91 100644 --- a/lib/ui_widgets/config_panel_widget.dart +++ b/lib/ui_widgets/config_panel_widget.dart @@ -34,7 +34,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/cloud/account"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/cloud/account"); }, ) ], @@ -52,7 +52,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/integrations/dashboard"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/integrations/dashboard"); }, ) ], @@ -70,7 +70,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/users/picker"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/users/picker"); }, ) ], @@ -88,7 +88,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/core"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/core"); }, ), Container(height: Sizes.rowPadding,), @@ -124,7 +124,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/person"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/person"); }, ) ], @@ -142,7 +142,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/entity_registry"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/entity_registry"); }, ) ], @@ -160,7 +160,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/area_registry"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/area_registry"); }, ) ], @@ -178,7 +178,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/automation"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/automation"); }, ) ], @@ -196,7 +196,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/script"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/script"); }, ) ], @@ -214,7 +214,7 @@ class _ConfigPanelWidgetState extends State { FlatButton( child: Text('Open web version', style: TextStyle(color: Colors.blue)), onPressed: () { - HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/customize"); + HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/customize"); }, ) ], diff --git a/lib/utils.class.dart b/lib/utils.class.dart index a7e18f6..c34a1de 100644 --- a/lib/utils.class.dart +++ b/lib/utils.class.dart @@ -98,15 +98,15 @@ class HAUtils { } } - static void launchURLInCustomTab(BuildContext context, String url) async { + static void launchURLInCustomTab({BuildContext context, String url, bool enableDefaultShare: true, bool showPageTitle: true}) async { try { await launch( "$url", option: new CustomTabsOption( toolbarColor: Theme.of(context).primaryColor, - enableDefaultShare: true, + enableDefaultShare: enableDefaultShare, enableUrlBarHiding: true, - showPageTitle: true, + showPageTitle: showPageTitle, animation: new CustomTabsAnimation.slideIn() // or user defined animation. /*animation: new CustomTabsAnimation(