Fix automatic OAuth window open issue
This commit is contained in:
		| @@ -14,6 +14,7 @@ class AuthManager { | |||||||
|     Completer completer = Completer(); |     Completer completer = Completer(); | ||||||
|     final flutterWebviewPlugin = new FlutterWebviewPlugin(); |     final flutterWebviewPlugin = new FlutterWebviewPlugin(); | ||||||
|     flutterWebviewPlugin.onUrlChanged.listen((String url) { |     flutterWebviewPlugin.onUrlChanged.listen((String url) { | ||||||
|  |       Logger.d("Webview url changed to $url"); | ||||||
|       if (url.startsWith("http://ha-client.homemade.systems/service/auth_callback.html")) { |       if (url.startsWith("http://ha-client.homemade.systems/service/auth_callback.html")) { | ||||||
|         String authCode = url.split("=")[1]; |         String authCode = url.split("=")[1]; | ||||||
|         Logger.d("We have auth code. Getting temporary access token..."); |         Logger.d("We have auth code. Getting temporary access token..."); | ||||||
|   | |||||||
| @@ -147,7 +147,17 @@ class HAClientApp extends StatelessWidget { | |||||||
|         "/": (context) => MainPage(title: 'HA Client', homeAssistant: homeAssistant,), |         "/": (context) => MainPage(title: 'HA Client', homeAssistant: homeAssistant,), | ||||||
|         "/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"), |         "/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"), | ||||||
|         "/configuration": (context) => PanelPage(title: "Configuration"), |         "/configuration": (context) => PanelPage(title: "Configuration"), | ||||||
|         "/log-view": (context) => LogViewPage(title: "Log") |         "/log-view": (context) => LogViewPage(title: "Log"), | ||||||
|  |         "/login": (_) => WebviewScaffold( | ||||||
|  |           url: "${Connection().oauthUrl}", | ||||||
|  |           appBar: new AppBar( | ||||||
|  |             leading: IconButton( | ||||||
|  |                 icon: Icon(Icons.help), | ||||||
|  |                 onPressed: () => HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/docs#authentication") | ||||||
|  |             ), | ||||||
|  |             title: new Text("Login to your Home Assistant"), | ||||||
|  |           ), | ||||||
|  |         ) | ||||||
|       }, |       }, | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| @@ -337,10 +347,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker | |||||||
|  |  | ||||||
|     if (_startAuthSubscription == null) { |     if (_startAuthSubscription == null) { | ||||||
|       _startAuthSubscription = eventBus.on<StartAuthEvent>().listen((event){ |       _startAuthSubscription = eventBus.on<StartAuthEvent>().listen((event){ | ||||||
|         //TODO _showOAuth |  | ||||||
|         setState(() { |         setState(() { | ||||||
|           _showLoginButton = event.showButton; |           _showLoginButton = event.showButton; | ||||||
|         }); |         }); | ||||||
|  |         if (event.showButton) { | ||||||
|  |           _showOAuth(); | ||||||
|  |         } | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -348,27 +360,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker | |||||||
|       HomeAssistant().fcmToken = token; |       HomeAssistant().fcmToken = token; | ||||||
|       completer.complete(); |       completer.complete(); | ||||||
|     }); |     }); | ||||||
|     //completer.complete(); |  | ||||||
|     return completer.future; |     return completer.future; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void _showOAuth() { |   void _showOAuth() { | ||||||
|     Logger.d("_showOAuth: ${Connection().oauthUrl}"); |     Logger.d("_showOAuth: ${Connection().oauthUrl}"); | ||||||
|     Navigator.push( |     Navigator.of(context).pushNamed('/login'); | ||||||
|         context, |  | ||||||
|         MaterialPageRoute( |  | ||||||
|           builder: (context) => WebviewScaffold( |  | ||||||
|             url: "${Connection().oauthUrl}", |  | ||||||
|             appBar: new AppBar( |  | ||||||
|               leading: IconButton( |  | ||||||
|                   icon: Icon(Icons.help), |  | ||||||
|                   onPressed: () => HAUtils.launchURLInCustomTab(context, "http://ha-client.homemade.systems/docs#authentication") |  | ||||||
|               ), |  | ||||||
|               title: new Text("Login to your Home Assistant"), |  | ||||||
|             ), |  | ||||||
|           ), |  | ||||||
|         ) |  | ||||||
|     ); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   _setErrorState(HAError e) { |   _setErrorState(HAError e) { | ||||||
| @@ -708,7 +705,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker | |||||||
|         FlatButton( |         FlatButton( | ||||||
|           child: Text("Login with Home Assistant", style: TextStyle(fontSize: 16.0, color: Colors.white)), |           child: Text("Login with Home Assistant", style: TextStyle(fontSize: 16.0, color: Colors.white)), | ||||||
|           color: Colors.blue, |           color: Colors.blue, | ||||||
|           onPressed: () => _showOAuth(), |           onPressed: () => _fullLoad(), | ||||||
|         ) |         ) | ||||||
|       ]; |       ]; | ||||||
|     } |     } | ||||||
| @@ -849,6 +846,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker | |||||||
|     _stateSubscription?.cancel(); |     _stateSubscription?.cancel(); | ||||||
|     _settingsSubscription?.cancel(); |     _settingsSubscription?.cancel(); | ||||||
|     _serviceCallSubscription?.cancel(); |     _serviceCallSubscription?.cancel(); | ||||||
|  |     _showDialogSubscription?.cancel(); | ||||||
|     _showEntityPageSubscription?.cancel(); |     _showEntityPageSubscription?.cancel(); | ||||||
|     _showErrorSubscription?.cancel(); |     _showErrorSubscription?.cancel(); | ||||||
|     _startAuthSubscription?.cancel(); |     _startAuthSubscription?.cancel(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user