DestinyItemManager / dim-mobile-client

DIM Mobile Client for Android, iOS, and Windows 10 Mobile
4 stars 3 forks source link

Flash of inAppBrowser when already authentiated #8

Open SunburnedGoose opened 8 years ago

SunburnedGoose commented 8 years ago

The app starts and it doesn't know if it is authenticated. It opens the inAppBrowser to Bungie.net to get the token, and it will flash the inAppBrowser briefly. Need to add a timeout to the ref.show() method to give it a moment to grab the token and close quickly. If it isn't closing quickly, then there is something that should be shown.

kyleshay commented 8 years ago

can we always hide it by default... and then if we need the login screen, toggle it to the front?

kyleshay commented 8 years ago

ripped out code/logic from old version

  function viaPhonegap(callback) {
    document.addEventListener('deviceready', function() {

        type = 'Wlid';
        var visible = false;
        var ref = window.open('https://www.bungie.net/en/User/SignIn/' + type, '_blank', 'location=no,hidden=yes');

        var tries = 0;
        var refStart = function(event) {
          if(event.url.indexOf('bungie.net/en/User/SignIn/') !== -1) {
            return;
          }
          if(event.url === 'https://www.bungie.net/') {
            (function query() {
              ref.executeScript({code: 'document.cookie'}, function(result) {
                ref.removeEventListener('loadstart', refStart);
                ref.close();
                _cookie = /bungled=(\d*);/.exec(result)[1];
                callback(_cookie);
              });
            })();
          } else {
            ref.show();
            visible = true;
          }
        }
        ref.addEventListener('loadstart', refStart);

      }, false);
  }
SunburnedGoose commented 8 years ago

It is hidden by default but I show it if the first page that loads doesn't have the token.

Usually that first page is just the redirect back to Bungie.net if you're already logged into Microsoft or Sony. So that 'tricks' the logic into showing the inAppBrowser briefly and Bungie.net loads, and DIM grabs the token.

What I'm suggesting is wrapping the show() function in a timeout that I can cancel if I'm able to get the token within 1s or so. Should fix the issue. I'm just making this ticket so I don't forget when I'm out this week.

kyleshay commented 8 years ago

ahhh, gotcha! yeah that would do it. nice!

SunburnedGoose commented 8 years ago

I could sniff the event for the endpoint that is loaded but it's a timing issue really since the url signature of the redirect from the pre-authenticated page is not something I can anticipate.