Resolve #382 VIew camera in chrome custom tab

This commit is contained in:
estevez-dev 2019-06-21 21:01:53 +03:00
parent caabf25260
commit 3c0ca5d16d
5 changed files with 31 additions and 24 deletions

View File

@ -17,10 +17,15 @@ class _CameraStreamViewState extends State<CameraStreamView> {
CameraEntity _entity; CameraEntity _entity;
bool started = false; bool started = false;
String streamUrl = "";
launchStream() { launchStream() {
HAUtils.launchURLInCustomTab(context, '${Connection().httpWebHost}/api/camera_proxy_stream/${_entity HAUtils.launchURLInCustomTab(
.entityId}?token=${_entity.attributes['access_token']}'); context: context,
url: streamUrl,
enableDefaultShare: false,
showPageTitle: false
);
} }
@override @override
@ -32,13 +37,15 @@ class _CameraStreamViewState extends State<CameraStreamView> {
.entity; .entity;
started = true; started = true;
} }
streamUrl = '${Connection().httpWebHost}/api/camera_proxy_stream/${_entity
.entityId}?token=${_entity.attributes['access_token']}';
return Column( return Column(
children: <Widget>[ children: <Widget>[
Container( Container(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
child: FlatButton( child: IconButton(
child: Text("View camera stream"), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:monitor-screenshot"), color: Colors.amber),
onPressed: () => launchStream(), iconSize: 50.0
) )
) )
], ],

View File

@ -153,7 +153,7 @@ class HAClientApp extends StatelessWidget {
appBar: new AppBar( appBar: new AppBar(
leading: IconButton( leading: IconButton(
icon: Icon(Icons.help), 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"), title: new Text("Login to your Home Assistant"),
), ),
@ -548,7 +548,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
GestureDetector( GestureDetector(
onTap: () { onTap: () {
Navigator.of(context).pop(); 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( child: Text(
"Terms and Conditions", "Terms and Conditions",
@ -564,7 +564,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
GestureDetector( GestureDetector(
onTap: () { onTap: () {
Navigator.of(context).pop(); 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( child: Text(
"Privacy Policy", "Privacy Policy",
@ -649,7 +649,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
actions.add(FlatButton( actions.add(FlatButton(
child: Text("${action.title}", style: textStyle), child: Text("${action.title}", style: textStyle),
onPressed: () { onPressed: () {
HAUtils.launchURLInCustomTab(context, "${action.url}"); HAUtils.launchURLInCustomTab(context: context, url: "${action.url}");
}, },
)); ));
break; break;

View File

@ -28,7 +28,7 @@ class Panel {
void handleOpen(BuildContext context) { void handleOpen(BuildContext context) {
if (type == "iframe") { if (type == "iframe") {
Logger.d("Launching custom tab with ${config["url"]}"); Logger.d("Launching custom tab with ${config["url"]}");
HAUtils.launchURLInCustomTab(context, config["url"]); HAUtils.launchURLInCustomTab(context: context, url: config["url"]);
} else if (type == "config") { } else if (type == "config") {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
@ -38,7 +38,7 @@ class Panel {
} else { } else {
String url = "${Connection().httpWebHost}/$urlPath"; String url = "${Connection().httpWebHost}/$urlPath";
Logger.d("Launching custom tab with $url"); Logger.d("Launching custom tab with $url");
HAUtils.launchURLInCustomTab(context, url); HAUtils.launchURLInCustomTab(context: context, url: url);
} }
} }

View File

@ -34,7 +34,7 @@ class _ConfigPanelWidgetState extends State<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { onPressed: () {
HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/core"); HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/core");
}, },
), ),
Container(height: Sizes.rowPadding,), Container(height: Sizes.rowPadding,),
@ -124,7 +124,7 @@ class _ConfigPanelWidgetState extends State<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { 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<ConfigPanelWidget> {
FlatButton( FlatButton(
child: Text('Open web version', style: TextStyle(color: Colors.blue)), child: Text('Open web version', style: TextStyle(color: Colors.blue)),
onPressed: () { onPressed: () {
HAUtils.launchURLInCustomTab(context, Connection().httpWebHost+"/config/customize"); HAUtils.launchURLInCustomTab(context: context, url: Connection().httpWebHost+"/config/customize");
}, },
) )
], ],

View File

@ -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 { try {
await launch( await launch(
"$url", "$url",
option: new CustomTabsOption( option: new CustomTabsOption(
toolbarColor: Theme.of(context).primaryColor, toolbarColor: Theme.of(context).primaryColor,
enableDefaultShare: true, enableDefaultShare: enableDefaultShare,
enableUrlBarHiding: true, enableUrlBarHiding: true,
showPageTitle: true, showPageTitle: showPageTitle,
animation: new CustomTabsAnimation.slideIn() animation: new CustomTabsAnimation.slideIn()
// or user defined animation. // or user defined animation.
/*animation: new CustomTabsAnimation( /*animation: new CustomTabsAnimation(