Re: [b2g] Can't use mozAlarms API

2014-04-15 Thread Chris Mills
I wrote a guide to setting alarms and then handling them using Notification API:

https://developer.mozilla.org/en-US/Apps/Build/Control_the_display/Using_Alarms_to_notify_users

This makes the point clear, I think. But I agree that it should be mentioned 
more explicitly in the reference docs. 

Chris Mills
   Senior tech writer || Mozilla
developer.mozilla.org || MDN
   cmi...@mozilla.com || @chrisdavidmills



On 14 Apr 2014, at 23:37, Prateek Jadhwani prateekjadhw...@gmail.com wrote:

 Dang it!!!
 Someone seriously needs to write this thing in the mozAlarm API 
 documentation. 
 
 Anyways, thanks alot for clearing out my doubts Nikhil. I really appreciate 
 it.
 
 Thanks
 
 Prateek Jadhwani
 www.prateekjadhwani.com
 
 
 On Mon, Apr 14, 2014 at 6:16 PM, Nikhil Marathe nsm.nik...@gmail.com wrote:
 
 
 
 On Mon, Apr 14, 2014 at 2:45 PM, Prateek Jadhwani prateekjadhw...@gmail.com 
 wrote:
 Thanks Nikhil for the reply. What I am doing is trying to get a list of 
 alarms in the system app. This is the code that I am using wrapped in a 
 function.
 
 
 
 
 var request = navigator.mozAlarms.getAll();
 
 
 request
 .onsuccess = function () {
 
   console
 .log('operation successful:' + this.result.length + 'alarms pending');
 
 
   this
 .result.forEach(function (alarm) {
 
 console
 .log(alarm.id + ' : ' + alarm.date.toString() + ' : ' + 
 alarm.respectTimezone);
 
   
 });
 }
 
 
 request
 .onerror = function () {
 
   console
 .log('operation failed: ' + this.error);
 }
 I will try to make it work with IAC. I never knew about it. Although I would 
 still love to see an example of how the above code could be modified to get 
 the list of alarms. 
 
 If this code is running in the system app, you are getting the list of alarms 
 added by the system app and not the clock.
 
 I think there seems to be confusion with what Alarms means. The Alarms API is 
 not for the 'wake me up every morning at 6' alarm the user adds in the clock, 
 but a set time in the future when the app would like to be woken up by the 
 system to do some task. So alarms are timers to 'start up me (the email app) 
 every 30 min so I can sync the user's email'. The Clock app uses the mozAlarm 
 API to implement the corresponding 'wake up a human' alarm. I hope this is 
 clear now.
 
 Nikhil
 
 ___
 dev-b2g mailing list
 dev-b2g@lists.mozilla.org
 https://lists.mozilla.org/listinfo/dev-b2g

___
dev-b2g mailing list
dev-b2g@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-b2g


Re: [b2g] Can't use mozAlarms API

2014-04-14 Thread nsm . nikhil
On Thursday, April 10, 2014 4:52:55 PM UTC-7, Prateek Jadhwani wrote:
 Hi there,
 
 I am trying to use the example given in 
 
 https://developer.mozilla.org/en-US/docs/Web/API/MozAlarmsManager.getAll 
 
 for one of my bugs, and it seems that it returns a different id everytime I 
 try to get alarm.id  and returns the current time in alarm.date.toString().

Could you paste example code of what your script is doing. If you are using the 
result of add(), it will be a new ID every time.
 
 Also, this link https://wiki.mozilla.org/WebAPI/AlarmAPI says No, the 
 getAll(...) only returns the alarms scheduled by the application.   If it 
 only returns the alarms added by the app itself, then what would be the 
 correct procedure to get the Alarm from the clock app. Will I have to use 
 alarmdb.js to retrieve them?

Apps are bound by the same-origin policy, just like normal web pages. Which 
means you cannot access anything the clock app is doing from another app. If 
you really need to get the list of alarms added by the clock app, you'll have 
to add Inter-App Communication API support to the clock, get it landed in Gaia 
(with a requisite justification of strong enough use cases for this feature) 
and then have your app talk to clock over IAC.

Regards,
Nikhil
___
dev-b2g mailing list
dev-b2g@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-b2g


Re: [b2g] Can't use mozAlarms API

2014-04-14 Thread Prateek Jadhwani
Thanks Nikhil for the reply. What I am doing is trying to get a list of
alarms in the system app. This is the code that I am using wrapped in a
function.

var request = navigator.mozAlarms.getAll();

request.onsuccess = function () {
  console.log('operation successful:' + this.result.length + 'alarms pending');

  this.result.forEach(function (alarm) {
console.log(alarm.id + ' : ' + alarm.date.toString() + ' : ' +
alarm.respectTimezone);
  });}

request.onerror = function () {
  console.log('operation failed: ' + this.error);}

I will try to make it work with IAC. I never knew about it. Although I
would still love to see an example of how the above code could be modified
to get the list of alarms.

Thanks

*Prateek Jadhwani*
www.prateekjadhwani.com


On Mon, Apr 14, 2014 at 5:29 PM, nsm.nik...@gmail.com wrote:

 On Thursday, April 10, 2014 4:52:55 PM UTC-7, Prateek Jadhwani wrote:
  Hi there,
 
  I am trying to use the example given in
 
  https://developer.mozilla.org/en-US/docs/Web/API/MozAlarmsManager.getAll
 
  for one of my bugs, and it seems that it returns a different id
 everytime I try to get alarm.id  and returns the current time in
 alarm.date.toString().

 Could you paste example code of what your script is doing. If you are
 using the result of add(), it will be a new ID every time.
 
  Also, this link https://wiki.mozilla.org/WebAPI/AlarmAPI says No, the
 getAll(...) only returns the alarms scheduled by the application.   If it
 only returns the alarms added by the app itself, then what would be the
 correct procedure to get the Alarm from the clock app. Will I have to use
 alarmdb.js to retrieve them?

 Apps are bound by the same-origin policy, just like normal web pages.
 Which means you cannot access anything the clock app is doing from another
 app. If you really need to get the list of alarms added by the clock app,
 you'll have to add Inter-App Communication API support to the clock, get it
 landed in Gaia (with a requisite justification of strong enough use cases
 for this feature) and then have your app talk to clock over IAC.

 Regards,
 Nikhil
 ___
 dev-b2g mailing list
 dev-b2g@lists.mozilla.org
 https://lists.mozilla.org/listinfo/dev-b2g

___
dev-b2g mailing list
dev-b2g@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-b2g


Re: [b2g] Can't use mozAlarms API

2014-04-14 Thread Nikhil Marathe
On Mon, Apr 14, 2014 at 2:45 PM, Prateek Jadhwani prateekjadhw...@gmail.com
 wrote:

 Thanks Nikhil for the reply. What I am doing is trying to get a list of
 alarms in the system app. This is the code that I am using wrapped in a
 function.

 var request = navigator.mozAlarms.getAll();

 request.onsuccess = function () {
   console.log('operation successful:' + this.result.length + 'alarms 
 pending');

   this.result.forEach(function (alarm) {
 console.log(alarm.id + ' : ' + alarm.date.toString() + ' : ' + 
 alarm.respectTimezone);
   });}

 request.onerror = function () {
   console.log('operation failed: ' + this.error);}

 I will try to make it work with IAC. I never knew about it. Although I
 would still love to see an example of how the above code could be modified
 to get the list of alarms.


If this code is running in the system app, you are getting the list of
alarms added by the system app and not the clock.

I think there seems to be confusion with what Alarms means. The Alarms API
is not for the 'wake me up every morning at 6' alarm the user adds in the
clock, but a set time in the future when the app would like to be woken up
by the system to do some task. So alarms are timers to 'start up me (the
email app) every 30 min so I can sync the user's email'. The Clock app uses
the mozAlarm API to implement the corresponding 'wake up a human' alarm. I
hope this is clear now.

Nikhil
___
dev-b2g mailing list
dev-b2g@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-b2g


Re: [b2g] Can't use mozAlarms API

2014-04-14 Thread Prateek Jadhwani
Dang it!!!
Someone seriously needs to write this thing in the mozAlarm API
documentation.

Anyways, thanks alot for clearing out my doubts Nikhil. I really appreciate
it.

Thanks

*Prateek Jadhwani*
www.prateekjadhwani.com


On Mon, Apr 14, 2014 at 6:16 PM, Nikhil Marathe nsm.nik...@gmail.comwrote:




 On Mon, Apr 14, 2014 at 2:45 PM, Prateek Jadhwani 
 prateekjadhw...@gmail.com wrote:

 Thanks Nikhil for the reply. What I am doing is trying to get a list of
 alarms in the system app. This is the code that I am using wrapped in a
 function.


 var request = navigator.mozAlarms.getAll();

 request.onsuccess = function () {
   console.log('operation successful:' + this.result.length + 'alarms 
 pending');

   this.result.forEach(function (alarm) {
 console.log(alarm.id + ' : ' + alarm.date.toString() + ' : ' + 
 alarm.respectTimezone);
   });}

 request.onerror = function () {
   console.log('operation failed: ' + this.error);}

 I will try to make it work with IAC. I never knew about it. Although I
 would still love to see an example of how the above code could be modified
 to get the list of alarms.


 If this code is running in the system app, you are getting the list of
 alarms added by the system app and not the clock.

 I think there seems to be confusion with what Alarms means. The Alarms API
 is not for the 'wake me up every morning at 6' alarm the user adds in the
 clock, but a set time in the future when the app would like to be woken up
 by the system to do some task. So alarms are timers to 'start up me (the
 email app) every 30 min so I can sync the user's email'. The Clock app uses
 the mozAlarm API to implement the corresponding 'wake up a human' alarm. I
 hope this is clear now.

 Nikhil

___
dev-b2g mailing list
dev-b2g@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-b2g