Permalink
Browse files

GPS bugs fixed for most, still broken for tons others. Also broken: O…

…Auth account authorizing for some users
  • Loading branch information...
zhephree committed Jun 14, 2011
1 parent 87e50c4 commit 822ddf98efe67f7f074d67de05ae170c7a9cdec8
View
Binary file not shown.
@@ -25,22 +25,179 @@ function MainAssistant(expressLogin,credentials,fp) {
this.loggedIn=false;
_globals.firstLoad=true;
this.wrongcreds=false;
+ this.gpsCount=0;
+ this.gettingGPS=false;
+
+};
+MainAssistant.prototype.gpsTimedOut = function(){
+ logthis("gps timed out. trying one final time");
+ this.controller.get("gps-message").update("GPS timed out! Trying again...");
+ this.controller.window.clearTimeout(this.gpsTimeout);
+
+ this.getLocationClearAll();
+
+ logthis("cleared gps trackers");
+
+ this.failedLocationBound=this.failedLocation.bind(this);
+
+ logthis("trying one-off request");
+ fsq.Metrix.ServiceRequest.request('palm://com.palm.location', {
+ method: "getCurrentPosition",
+ parameters: {accuracy: 1, maximumAge:0, responseTime: 1},
+ onSuccess: this.gpsSuccessBound,
+ onFailure: this.failedLocationBound
+ });
+
+};
+
+MainAssistant.prototype.getLocation = function(event){
+logthis("getting location...");
+ this.gettingGPS=true;
+ this.controller.get("gps-message").update("Initiating GPS...");
+ //set up the timeout timer
+ this.gpsTimeout=this.controller.window.setTimeout(function(){this.gpsTimedOut();}.bind(this),17000);
+
+ this.trackGPSObjA = new Mojo.Service.Request('palm://com.palm.location', {
+ method: 'startTracking',
+ parameters: {
+ subscribe: true
+ },
+ onSuccess: function(event){
+ logthis("gps ok!");
+ logthis(Object.toJSON(event));
+ this.gpsCount++;
+ if (event.errorCode==undefined){
+ //--> This is simply our 'returnValue: true' call. No data here.
+ logthis("true call");
+ this.controller.get("gps-message").update("Finding your location...");
+
+ }else{
+ if (event.errorCode != 0){
+ logthis("location error");
+ this.failedLocationBound=this.failedLocation.bind(this);
+ this.failedLocationBound(event);
+ if (event.errorCode == 5){
+ //--> Alert user that location services are off
+ this.controller.get("gps-message").update("Location services not enabled!");
+ this.controller.window.clearTimeout(this.gpsTimeout);
+
+ }else if (event.errorCode == 4){
+ //--> Alert user that GPS Permanent Failure (reboot device is the advice).
+ this.controller.get("gps-message").update("Permanent GPS Failure! Restart device.");
+ this.controller.window.clearTimeout(this.gpsTimeout);
+
+ }
+ }else{
+ logthis("location OK!");
+ //--> Got a GPS Response, cache it for later!
+ _globals.gps = event;
+
+ var acc=(_globals.gpsAccuracy != undefined)? Math.abs(_globals.gpsAccuracy): 750;
+ logthis("acc="+acc);
+ if(this.gpsCount<4){
+ if(acc>=event.horizAccuracy || acc==0){
+ this.controller.get("gps-message").update("Found you!");
+
+ this.gpsSuccessBound(event);
+
+ //--> Stop tracking
+ this.trackGPSObjA.cancel();
+ }else{
+ this.controller.get("gps-message").update("Getting better accuracy...");
+ }
+ }else{
+
+ //--> Do your other stuff here and give up
+ /* ... code
+ */
+ this.controller.get("gps-message").update("Found you!");
+
+ this.gpsSuccessBound(event);
+
+ //--> Stop tracking
+ this.trackGPSObjA.cancel();
+
+ }
+ }
+ }
+ }.bind(this),
+ onFailure: function(event){
+ this.controller.get("gps-message").update("GPS Failure! Error: "+event.errorCode);
+ this.controller.window.clearTimeout(this.gpsTimeout);
+
+ //Mojo.Log.error("*** trackGPSObj FAILURE: " + event.errorCode + " [" + gps.errorCodeDescription(event.errorCode) + "]");
+ }.bind(this)
+ });
+
+ logthis("gettting location b");
+
+ //--> Launch a second tracking to 'unstick' GPS
+ this.trackGPSObjB = new Mojo.Service.Request('palm://com.palm.location', {
+ method: 'startTracking',
+ parameters: {
+ subscribe: true
+ },
+ onSuccess: function(event){
+ if (event.errorCode){
+ logthis("tracker b canceled");
+ this.trackGPSObjB.cancel(); //--> Stop tracking
+ }
+ }.bind(this),
+ onFailure: function(event){
+ //logthis("*** trackGPSObjB FAILURE: " + event.errorCode + " [" + gps.errorCodeDescription(event.errorCode) + "]");
+ logthis("tracker b failed: "+event.errorCode);
+ }.bind(this)
+ });
+
+ logthis("getting location c");
+ //--> Launch a third tracking to 'unstick' GPS
+ this.trackGPSObjC = new Mojo.Service.Request('palm://com.palm.location', {
+ method: 'startTracking',
+ parameters: {
+ subscribe: true
+ },
+ onSuccess: function(event){
+ if (event.errorCode){
+ logthis("tracker c canceled");
+ this.trackGPSObjC.cancel(); //--> Stop tracking
+ }
+ }.bind(this),
+ onFailure: function(event){
+ logthis("tracker c failed: "+event.errorCode);
+ //logthis("*** trackGPSObjC FAILURE: " + event.errorCode + " [" + gps.errorCodeDescription(event.errorCode) + "]");
+ }.bind(this)
+ });
}
+MainAssistant.prototype.getLocationClearAll = function(event){
+ logthis("clearing all trackers");
+
+ try{
+ this.trackGPSObjC.cancel();
+ }catch(e){logthis("tracker c failed clear");}
+ try{
+ this.trackGPSObjA.cancel();
+ }catch(e){logthis("tracker a failed clear");}
+ try{
+ this.trackGPSObjB.cancel();
+ }catch(e){logthis("tracker b failed clear");}
+};
MainAssistant.prototype.setup = function() {
_globals.mainLoaded=true;
this.gpsSuccessBound=this.gpsSuccess.bind(this);
// this.controller.serviceRequest('palm://com.palm.location', {
- fsq.Metrix.ServiceRequest.request('palm://com.palm.location', {
+
+
+ /*fsq.Metrix.ServiceRequest.request('palm://com.palm.location', {
method:"getCurrentPosition",
parameters:{accuracy:1, maximumAge: 0, responseTime: 1},
onSuccess: this.gpsSuccessBound,
onFailure: this.failedLocation.bind(this)
}
- );
+ );*/
/* this.controller.setupWidget("loginSpinner",
this.attributes = {
@@ -339,6 +496,11 @@ MainAssistant.prototype.activate = function(event) {
_globals.main=this;
}
+ if(!this.gettingGPS){
+ this.getLocation();
+ }
+
+
if(event){
if(event.token){
//start logging in!
@@ -373,6 +535,8 @@ MainAssistant.prototype.proceed = function(){
MainAssistant.prototype.gpsSuccess = function(event) {
logthis("got gps response");
+ this.controller.window.clearTimeout(this.gpsTimeout);
+
if(event.errorCode==0){
logthis("gps is ok");
@@ -394,6 +558,9 @@ MainAssistant.prototype.gpsSuccess = function(event) {
};
MainAssistant.prototype.failedLocation = function(event) {
+ logthis("location failed!");
+ this.controller.window.clearTimeout(this.gpsTimeout);
+
var msg='';
switch(event.errorCode){
case 1:
@@ -418,7 +585,7 @@ MainAssistant.prototype.failedLocation = function(event) {
msg="foursquare was denied GPS access for this session. Please restart your phone and allow foursquare access when prompted. (EC8)";
break;
}
-
+ logthis("failure msg="+msg);
this.controller.showAlertDialog({
onChoose: function(value) {
@@ -456,6 +623,7 @@ MainAssistant.prototype.cleanup = function(event) {
// Mojo.Event.stopListening(this.controller.get("goLogin"), Mojo.Event.tap, this.onLoginTappedBound);
// Mojo.Event.stopListening(this.controller.get("goSignup"), Mojo.Event.tap, this.onSignupTappedBound);
this.controller.document.removeEventListener("keyup", this.keyDownHandlerBound, true);
+ this.getLocationClearAll();
}
@@ -2,8 +2,16 @@ function OauthAssistant(fp) {
this.fromPrefs=fp;
}
+//https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=code&redirect_uri=http://zhephree.com/foursquare/callback
+
OauthAssistant.prototype.setup = function() {
- var theURL=(this.fromPrefs)? 'http://foursquare.com/logout': 'https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&display=touch&redirect_uri=http://zhephree.com/foursquare/callback';
+ if(_globals.isTouchPad()){
+ logthis("touchpad!");
+ var theURL=(this.fromPrefs)? 'http://foursquare.com/logout': 'https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&redirect_uri=http://zhephree.com/foursquare/callback';
+ }else{
+ var theURL=(this.fromPrefs)? 'http://foursquare.com/logout': 'https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&display=touch&redirect_uri=http://zhephree.com/foursquare/callback';
+
+ }
this.controller.setupWidget("WebId",
this.attributes = {
url: theURL,
@@ -12,21 +20,25 @@ OauthAssistant.prototype.setup = function() {
this.model = {
}
);
- Mojo.Event.listen(this.controller.get('WebId'), Mojo.Event.webViewTitleUrlChanged, this.titleChanged.bind(this));
+// Mojo.Event.listen(this.controller.get('WebId'), Mojo.Event.webViewTitleUrlChanged, this.titleChanged.bind(this));
Mojo.Event.listen(this.controller.get("WebId"), Mojo.Event.webViewLoadStopped, this.loadStopped.bind(this));
Mojo.Event.listen(this.controller.get("WebId"), Mojo.Event.webViewLoadStarted, this.loadStarted.bind(this));
+ Mojo.Event.listen(this.controller.get('WebId'), Mojo.Event.webViewUrlChanged, this.titleChanged.bind(this));
};
OauthAssistant.prototype.loadStarted = function(event) {
+ logthis("url="+event.url);
this.controller.get("tooltip").show();
};
OauthAssistant.prototype.loadStopped = function(event) {
this.controller.get("tooltip").hide();
};
OauthAssistant.prototype.titleChanged = function(event) {
+ logthis("url changed");
+ logthis("url="+event.url);
event.stop();
event.preventDefault();
var callbackUrl=event.url;
@@ -39,7 +51,13 @@ OauthAssistant.prototype.titleChanged = function(event) {
});
this.controller.stageController.popScenesTo('main',{token:responseVars[1]});
}else if((responseVars[0]=="http://foursquare.com" || responseVars[0]=="http://foursquare.com/") && responseVars[0].indexOf("logout")==-1){
- setTimeout(function(){this.controller.get("WebId").mojo.stopLoad();this.controller.get("WebId").mojo.openURL("https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&display=touch&redirect_uri=http://zhephree.com/foursquare/callback");}.bind(this),500);
+// if(_globals.isTouchPad()){
+// setTimeout(function(){this.controller.get("WebId").mojo.stopLoad();this.controller.get("WebId").mojo.openURL("https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&redirect_uri=http://zhephree.com/foursquare/callback");}.bind(this),500);
+// }else{
+ setTimeout(function(){this.controller.get("WebId").mojo.stopLoad();this.controller.get("WebId").mojo.openURL("https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&display=touch&redirect_uri=http://zhephree.com/foursquare/callback");}.bind(this),500);
+
+// }
+
/* }else if(responseVars[0].indexOf("logout")!=-1){
setTimeout(function(){this.controller.get("WebId").mojo.stopLoad();this.controller.get("WebId").mojo.openURL("https://foursquare.com/oauth2/authenticate?client_id=OCLXBFYUDCOGQVILNNN1RZMEI4HDS5VQGY5QASRYILPQTFFI&response_type=token&display=touch&redirect_uri=http://zhephree.com/foursquare/callback");}.bind(this),500);*/
@@ -99,7 +99,7 @@ UserInfoAssistant.prototype.setup = function() {
{label: "Friends", value: 1}
] }
);
- this.controller.setupWidget("venuehistoryToggle",
+/* this.controller.setupWidget("venuehistoryToggle",
this.vhtabAttributes = {
},
@@ -110,7 +110,7 @@ UserInfoAssistant.prototype.setup = function() {
{label: "Visits", value: 1},
{label: "Last There", value: 2}
] }
- );
+ );*/
if(this.fromFriends){
var cm_items=[
@@ -1362,16 +1362,18 @@ UserInfoAssistant.prototype.getVenueHistorySuccess = function(response){
j.venues.items[v].primarycategory={icon:"images/no-cat.png"};
}
- var ca=new Date(j.venues.items[v].lastHereAt*1000);
- var months=['January','February','March','April','May','June','July','August','September','October','November','December'];
-
+ if(j.venues.items[v].lastHereAt!=undefined){
+ var ca=new Date(j.venues.items[v].lastHereAt*1000);
+ var months=['January','February','March','April','May','June','July','August','September','October','November','December'];
- var mins=(ca.getMinutes()<10)? "0"+ca.getMinutes(): ca.getMinutes();
- var hours=(ca.getHours()<10)? "0"+ca.getHours(): ca.getHours();
- var t=hours+':'+mins;
- var d=months[ca.getMonth()]+' '+ca.getDate()+', '+(ca.getYear()+1900);
- j.venues.items[v].lasthere='Last here: '+t+' '+d;
+ var mins=(ca.getMinutes()<10)? "0"+ca.getMinutes(): ca.getMinutes();
+ var hours=(ca.getHours()<10)? "0"+ca.getHours(): ca.getHours();
+
+ var t=hours+':'+mins;
+ var d=months[ca.getMonth()]+' '+ca.getDate()+', '+(ca.getYear()+1900);
+ j.venues.items[v].lasthere='Last here: '+t+' '+d;
+ }
j.venues.items[v].times=(j.venues.items[v].beenHere==1)? '1 time': j.venues.items[v].beenHere+' times';
@@ -16,6 +16,24 @@ _globals.retryingGPS=false;
_globals.hiddenVenues=[];
_globals.userData={};
_globals.rec={};
+_globals.isTouchPad=function(){
+ var isTouchPad=false;
+ if(Mojo.Environment.DeviceInfo.modelNameAscii.indexOf("ouch")>-1){
+ isTouchPad=true;
+ }
+ if(Mojo.Environment.DeviceInfo.modelNameAscii.indexOf("Emulator")>-1){
+ isTouchPad=true;
+ }
+ if(Mojo.Environment.DeviceInfo.screenWidth==1024){
+ isTouchPad=true;
+ }
+ if(Mojo.Environment.DeviceInfo.screenHeight==1024){
+ isTouchPad=true;
+ }
+
+ return isTouchPad;
+};
+
_globals.cmmodel = {
visible: true,
items: [{
@@ -40,9 +58,10 @@ _globals.whatsnew={
"id":"whatsnew",
"icon":"",
"pages":[
+ "Here's what's new in foursquare webOS <b>v2.7.3</b>! Follow me on Twitter: <a href=\"http://mobile.twitter.com/zhephree\">@zhephree</a><ul><li>GPS Issues resolved</li></ul>",
+ "Here's what's new in foursquare webOS <b>v2.7.0</b>! Follow me on Twitter: <a href=\"http://mobile.twitter.com/zhephree\">@zhephree</a><ul><li>I seriously, absolutely, feel that I once-and-for-all fixed the GPS and timing-out issues during start up, thanks to James Harris. Automatically waits for the best accuracy (if available)</li><li>[USER PROFILE] Removed \"Last Visited\" option from the \"Where Have I Been?\" feature since foursquare removed it from the API</li><li>[ABOUT] Updated the content on here finally</li></ul>",
"Here's what's new in foursquare webOS <b>v2.6.0</b>! Follow me on Twitter: <a href=\"http://mobile.twitter.com/zhephree\">@zhephree</a><ul><li>[USER PROFILE] Added points and mini-leaderboard. Tap mini-leaderboard to view full leaderboard</li><li>[LEADERBOARD] No longer an embedded web page! An actual, pretty, and useful leaderboard now.</li><li>[CHECKIN RESULT] Uses new data point for scores instead of old deprecated one. Future-proofing, yo.</li><li>[USER PROFILE] Number of user's check-ins now visible, regardless of friendship status, however, check-in history still only viewable for yourself</li><li>[USER PROFILE] Did I mention how much I love the new points progress bar? I didn't? Well, it's awesome!</li></ul>",
- "Here's what's new in foursquare webOS <b>v2.5.0</b>! Follow me on Twitter: <a href=\"http://mobile.twitter.com/zhephree\">@zhephree</a><ul><li>Added Explore feature</li><li>[CHECKIN RESULTS] Redesigned layout; added leaderboard rankings; added special unlock detection</li><li>Fixed ability to view check-ins from links supplied by Twitter clients</li><li>[NEARBY VENUES] Fixed a bug that prevented searching for venues with a space</li><li>[VIEW TODO] Fixed ability to view to-dos with no text assigned to them</li><li>[VENUE DETAIL] Fixed incorrect \"time ago\" for Who's Here listing</li><li>[ADD VENUE] Adding a venue respects coordinates selected from map and not just GPS specified location</li><li>[ABOUT] Update content</li></ul>",
- "Here's what's new in foursquare webOS <b>v2.2.5</b>! Follow me on Twitter: <a href=\"http://mobile.twitter.com/zhephree\">@zhephree</a><ul><li>[LAUNCH] Fixed update checker due to new Palm website</li><li>[PLACES] Nearby specials button now shows a badge of the number of specials nearby</li><li>[LAUNCH] (Hopefully) Fixed a bug with the app timing out when logging in/getting GPS. If it still fails, let me know on Twitter or e-mail (geoff@zhephree.com) instead of leaving bad reviews. I'll send some good karma your way and if you don't believe in karma, I won't talk about you behind your back if you let me know problems directly :)</li><li>[COMING SOON] 3.0 features like Explore and a new Leaderboard. It's gonna be awesome</li><li>[SPINES] Reticulating</li></ul>"
+ "Here's what's new in foursquare webOS <b>v2.5.0</b>! Follow me on Twitter: <a href=\"http://mobile.twitter.com/zhephree\">@zhephree</a><ul><li>Added Explore feature</li><li>[CHECKIN RESULTS] Redesigned layout; added leaderboard rankings; added special unlock detection</li><li>Fixed ability to view check-ins from links supplied by Twitter clients</li><li>[NEARBY VENUES] Fixed a bug that prevented searching for venues with a space</li><li>[VIEW TODO] Fixed ability to view to-dos with no text assigned to them</li><li>[VENUE DETAIL] Fixed incorrect \"time ago\" for Who's Here listing</li><li>[ADD VENUE] Adding a venue respects coordinates selected from map and not just GPS specified location</li><li>[ABOUT] Update content</li></ul>"
]
};
Oops, something went wrong.

0 comments on commit 822ddf9

Please sign in to comment.