diff --git a/README.md b/README.md index 928be770..cfedff33 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_client -[![pub 1.0.2](https://img.shields.io/badge/pub-1.0.2-brightgreen.svg)](https://pub.dartlang.org/packages/angel_client) +[![pub 1.0.3](https://img.shields.io/badge/pub-1.0.3-brightgreen.svg)](https://pub.dartlang.org/packages/angel_client) [![build status](https://travis-ci.org/angel-dart/client.svg)](https://travis-ci.org/angel-dart/client) Client library for the Angel framework. diff --git a/lib/browser.dart b/lib/browser.dart index 1bfe09a2..a506c624 100644 --- a/lib/browser.dart +++ b/lib/browser.dart @@ -1,7 +1,7 @@ /// Browser library for the Angel framework. library angel_client.browser; -import 'dart:async' show Future, Stream, StreamController; +import 'dart:async' show Future, Stream, StreamController, Timer; import 'dart:convert' show JSON; import 'dart:html' show CustomEvent, window; import 'package:http/browser_client.dart' as http; @@ -53,21 +53,24 @@ class Rest extends BaseAngelClient { var ctrl = new StreamController(); var wnd = window.open(url, 'angel_client_auth_popup'); - wnd - ..on['beforeunload'].listen((_) { - if (!ctrl.isClosed) { + new Timer.periodic(new Duration(milliseconds: 500), (timer) { + if (!ctrl.isClosed) { + if (wnd.closed) { ctrl.addError(new AngelHttpException.notAuthenticated( message: errorMessage ?? 'Authentication via popup window failed.')); ctrl.close(); } - }) - ..on[eventName ?? 'token'].listen((CustomEvent e) { - if (!ctrl.isClosed) { - ctrl.add(e.detail); - ctrl.close(); - } - }); + } else + timer.cancel(); + }); + + window.on[eventName ?? 'token'].listen((CustomEvent e) { + if (!ctrl.isClosed) { + ctrl.add(e.detail); + ctrl.close(); + } + }); return ctrl.stream; } diff --git a/pubspec.yaml b/pubspec.yaml index 67bd32be..7c910e01 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_client -version: 1.0.2 +version: 1.0.3 description: Client library for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_client