diff --git a/lib/main.dart b/lib/main.dart index 1987a23..bf9e399 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -140,7 +140,7 @@ EventBus eventBus = new EventBus(); final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); const String appName = "HA Client"; -const appVersionNumber = "0.7.7"; +const appVersionNumber = "0.8.0-alpha"; const appVersionAdd = ""; const appVersion = "$appVersionNumber$appVersionAdd"; diff --git a/lib/managers/connection_manager.class.dart b/lib/managers/connection_manager.class.dart index 94eb450..787653c 100644 --- a/lib/managers/connection_manager.class.dart +++ b/lib/managers/connection_manager.class.dart @@ -20,6 +20,7 @@ class ConnectionManager { String oauthUrl; String webhookId; bool useLovelace = true; + bool useWebView = true; bool settingsLoaded = false; bool get isAuthenticated => _token != null; StreamSubscription _socketSubscription; diff --git a/lib/pages/main.page.dart b/lib/pages/main.page.dart index fb0343b..2202d9f 100644 --- a/lib/pages/main.page.dart +++ b/lib/pages/main.page.dart @@ -118,6 +118,18 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker } _fetchData() async { + if (ConnectionManager().useWebView) { + final flutterWebViewPlugin = new FlutterWebviewPlugin(); + + flutterWebViewPlugin.onStateChanged.listen((viewState) async { + if (viewState.type == WebViewState.startLoad) { + Logger.d("[WebView] Injecting external auth JS"); + rootBundle.loadString('assets/js/externalAuth.js').then((js){ + flutterWebViewPlugin.evalJavascript(js.replaceFirst("[token]", ConnectionManager()._token)); + }); + } + }); + } await HomeAssistant().fetchData().then((_) { _hideBottomBar(); if (_entityToShow != null) { @@ -143,6 +155,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker Future _subscribe() { Completer completer = Completer(); + if (_stateSubscription == null) { _stateSubscription = eventBus.on().listen((event) { if (event.needToRebuildUI) { @@ -837,33 +850,49 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ); } } - // This method is rerun every time setState is called. - if (HomeAssistant().isNoViews) { + if (!ConnectionManager().settingsLoaded) { return Scaffold( key: _scaffoldKey, primary: false, - drawer: _buildAppDrawer(), bottomNavigationBar: bottomBar, body: _buildScaffoldBody(true) ); - } else { - return WillPopScope( - child: Scaffold( - key: _scaffoldKey, - drawer: _buildAppDrawer(), - primary: false, - bottomNavigationBar: bottomBar, - body: _buildScaffoldBody(false) - ), - onWillPop: () { - if (_entityToShow != null) { - eventBus.fire(ShowEntityPageEvent()); - return Future.value(false); - } else { - return Future.value(true); - } - }, + } else if (ConnectionManager().settingsLoaded && ConnectionManager().useWebView) { + SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark); + return WebviewScaffold( + url: ConnectionManager().httpWebHost, + primary: false, + appBar: EmptyAppBar (), + bottomNavigationBar: bottomBar, ); + } else { + if (HomeAssistant().isNoViews) { + return Scaffold( + key: _scaffoldKey, + primary: false, + drawer: _buildAppDrawer(), + bottomNavigationBar: bottomBar, + body: _buildScaffoldBody(true) + ); + } else { + return WillPopScope( + child: Scaffold( + key: _scaffoldKey, + drawer: _buildAppDrawer(), + primary: false, + bottomNavigationBar: bottomBar, + body: _buildScaffoldBody(false) + ), + onWillPop: () { + if (_entityToShow != null) { + eventBus.fire(ShowEntityPageEvent()); + return Future.value(false); + } else { + return Future.value(true); + } + }, + ); + } } } @@ -888,3 +917,12 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker super.dispose(); } } + +class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget { + @override + Widget build(BuildContext context) { + return Container(); + } + @override + Size get preferredSize => Size(0.0,0.0); +} diff --git a/pubspec.yaml b/pubspec.yaml index afaf4f8..6b5f1b8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: hass_client description: Home Assistant Android Client -version: 0.7.7+770 +version: 0.8.0+880 environment: