Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for custom watchDog timer interval #313

Closed
hirbod opened this issue Nov 20, 2014 · 15 comments
Closed

Add option for custom watchDog timer interval #313

hirbod opened this issue Nov 20, 2014 · 15 comments
Milestone

Comments

@hirbod
Copy link
Contributor

hirbod commented Nov 20, 2014

Hi,

actually the watchdog-timer is set to 100ms.

https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/www/googlemaps-cdv-plugin.js#L2018

Could you please provide a function to override the value or even disable it? (false = disabled, 0 = disbaled, 1 = 1ms, 20 = 20ms... etc)

@wf9a5m75
Copy link
Member

If I implement this, you need to test many all android devices.
Android devices are very different performance.
The value 100ms, for some device, it might be too short, but for some device, it might be too long.
So do you want to adjust for each devices?

@hirbod
Copy link
Contributor Author

hirbod commented Nov 20, 2014

I see your point. But iOS and iPhone > 5 do have good performance. Even running on 1ms is super fast and the map resets position like native.

If you implement this, I would make if(iOS) ...setWatchDogTimer(10) else 100 or else nothing. Default is 100.

@wf9a5m75
Copy link
Member

Sounds like your app needs large battery.
In my opinion, applications should consider the device battery.

@hirbod
Copy link
Contributor Author

hirbod commented Nov 20, 2014

Also a very good point. But do you really think that calling an interval every 1ms will dramatically increase battery usage? Look at 3D Games...

@hirbod
Copy link
Contributor Author

hirbod commented Nov 20, 2014

But with this method, I could set the interval to 1ms before menu animation, onfinish, reset to 100. This would be a great feature.

@bFlood
Copy link

bFlood commented Nov 20, 2014

+1 i agree, this option would be nice. leave a sensible default value and then leave it up to the developer to change if needed

@hirbod
Copy link
Contributor Author

hirbod commented Dec 23, 2014

Another option would be:

  1. Option to disable watchDog global
  2. Start method for watchdog (with own ms-setting)
  3. Stop method for watchdog (totally, to save battery)

Just as an extra. I only need to watch/refresh position when I open my navigation menu. It would be perfect to totally deactivate the watchDog and (cause my framework provides some "preopen" and "postopen" callbacks,) to do something like this.

on.('preopen') ->
startWatchDog(1) = 1ms -> open menu

on('postopen') ->
stopWatchDog()

on('preclose') ->
startWatchDog(1)

on('postclose') ->
stopWatchDog()

This would have so many favours. Less battery comsuming application and much better animation, as the position get changes wihtout any delay. Please provide this feature at least as an additional options for us heavy users.

@bFlood
Copy link

bFlood commented Dec 24, 2014

+1, this really needs to be an option

@hirbod
Copy link
Contributor Author

hirbod commented Jan 23, 2015

@bFlood are you in for a bounty? This is a very urgent feature for me. I guess if we both reach 50 bucks masashi will be in for doing this (I would do it myself, but I'm busy enough with the app)

@wf9a5m75
Copy link
Member

Sorry. You guys are already enough donated. I'm really appreciate for you.
I just don't have enough time for my plugin.

@hirbod
Copy link
Contributor Author

hirbod commented Jan 24, 2015

No problem. I will send PR in 10 minuntes ;)
I'm finished in a few minutes

@hirbod
Copy link
Contributor Author

hirbod commented Jan 24, 2015

Hi @wf9a5m75

just add these lines before setCenter function in your JS.

/**
 * @desc Set watchDogTimer for map positioning changes
 */
App.prototype.getWatchDogTimer = function() {
  var self = this;
  time = self.get('watchDogTimer') || 100;
  return time;
};

/**
 * @desc Set watchDogTimer for map positioning changes
 */
App.prototype.setWatchDogTimer = function(time) {
  var self = this;
  time = time || 100;
  self.set('watchDogTimer', time);

  if(time < 50) {
    console.log('Warning: watchdog values under 50ms will drain battery a lot. Just use for short operation times.');
  }
};

And very close to the end, replace

    window._watchDogTimer = window.setInterval(function() { myFunc(); }, 100);

with this one:

    window._watchDogTimer = window.setInterval(function() { myFunc(); }, _mapInstance.getWatchDogTimer());

You still can't cancel the watchdog (this option really should still be implemented, but for now, I could set a high value like 10000 which will save a lot more battery...

You can set your own value with:

Map.setWatchDogTimer(TIMEINMILLISECONDS);

Value needs to be an integer.

@hirbod
Copy link
Contributor Author

hirbod commented Jan 24, 2015

Here as a proof, the benefits are HUGE!
https://www.youtube.com/watch?v=cddcqIibOl8&feature=youtu.be

OnsenUI has a preopen and a postopen, preclose and postclose callbacks for the menu.

Workflow:
Preopen -> setWatchDogTimer(1);
Postopen-> setWatchDogTimer(false); (will reset)
Preclose -> setWatchDogTimer(1);
Postclose-> setWatchDogTimer(false); (will reset)

Of course I could leave it on 1ms till postclose (which is much smarter I guess... nobdy is going to leave the menu open for more then a few seconds.

@wf9a5m75
Copy link
Member

Thank you, @hirbod
It seems looks good!
Please send me a pull request. I will merge it.

@hirbod
Copy link
Contributor Author

hirbod commented Jan 24, 2015

#367

Maybe you will find some time for adding the options for enable/disable totally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants