Dart Documentationchrome.alarmsChromeAlarms

ChromeAlarms class

class ChromeAlarms extends ChromeApi {
 static final JsObject _alarms = chrome['alarms'];

 ChromeAlarms._();

 bool get available => _alarms != null;

 /**
  * Creates an alarm. Near the time(s) specified by [alarmInfo], the `onAlarm`
  * event is fired. If there is another alarm with the same name (or no name if
  * none is specified), it will be cancelled and replaced by this alarm.
  * 
  * In order to reduce the load on the user's machine, Chrome limits alarms to
  * at most once every 1 minute but may delay them an arbitrary amount more.
  * That is, setting `delayInMinutes` or `periodInMinutes` to less than `1`
  * will not be honored and will cause a warning. `when` can be set to less
  * than 1 minute after "now" without warning but won't actually cause the
  * alarm to fire for at least 1 minute.
  * 
  * To help you debug your app or extension, when you've loaded it unpacked,
  * there's no limit to how often the alarm can fire.
  * 
  * [name]: Optional name to identify this alarm. Defaults to the empty string.
  * 
  * [alarmInfo]: Describes when the alarm should fire. The initial time must be
  * specified by either [when] or [delayInMinutes] (but not both). If
  * [periodInMinutes] is set, the alarm will repeat every [periodInMinutes]
  * minutes after the initial event. If neither [when] or [delayInMinutes] is
  * set for a repeating alarm, [periodInMinutes] is used as the default for
  * [delayInMinutes].
  */
 void create(AlarmCreateInfo alarmInfo, [String name]) {
   if (_alarms == null) _throwNotAvailable();

   _alarms.callMethod('create', [name, jsify(alarmInfo)]);
 }

 /**
  * Retrieves details about the specified alarm.
  * [name]: The name of the alarm to get. Defaults to the empty string.
  */
 Future<Alarm> get([String name]) {
   if (_alarms == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Alarm>.oneArg(_createAlarm);
   _alarms.callMethod('get', [name, completer.callback]);
   return completer.future;
 }

 /**
  * Gets an array of all the alarms.
  */
 Future<List<Alarm>> getAll() {
   if (_alarms == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<Alarm>>.oneArg((e) => listify(e, _createAlarm));
   _alarms.callMethod('getAll', [completer.callback]);
   return completer.future;
 }

 /**
  * Clears the alarm with the given name.
  * [name]: The name of the alarm to clear. Defaults to the empty string.
  */
 void clear([String name]) {
   if (_alarms == null) _throwNotAvailable();

   _alarms.callMethod('clear', [name]);
 }

 /**
  * Clears all alarms.
  */
 void clearAll() {
   if (_alarms == null) _throwNotAvailable();

   _alarms.callMethod('clearAll');
 }

 Stream<Alarm> get onAlarm => _onAlarm.stream;

 final ChromeStreamController<Alarm> _onAlarm =
     new ChromeStreamController<Alarm>.oneArg(_alarms, 'onAlarm', _createAlarm);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.alarms' is not available");
 }
}

Extends

ChromeApi > ChromeAlarms

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _alarms != null;

final Stream<Alarm> onAlarm #

Stream<Alarm> get onAlarm => _onAlarm.stream;

Methods

void clear([String name]) #

Clears the alarm with the given name. name: The name of the alarm to clear. Defaults to the empty string.

void clear([String name]) {
 if (_alarms == null) _throwNotAvailable();

 _alarms.callMethod('clear', [name]);
}

void clearAll() #

Clears all alarms.

void clearAll() {
 if (_alarms == null) _throwNotAvailable();

 _alarms.callMethod('clearAll');
}

void create(AlarmCreateInfo alarmInfo, [String name]) #

Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.

In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.

To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.

name: Optional name to identify this alarm. Defaults to the empty string.

alarmInfo: Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.

void create(AlarmCreateInfo alarmInfo, [String name]) {
 if (_alarms == null) _throwNotAvailable();

 _alarms.callMethod('create', [name, jsify(alarmInfo)]);
}

Future<Alarm> get([String name]) #

Retrieves details about the specified alarm. name: The name of the alarm to get. Defaults to the empty string.

Future<Alarm> get([String name]) {
 if (_alarms == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Alarm>.oneArg(_createAlarm);
 _alarms.callMethod('get', [name, completer.callback]);
 return completer.future;
}

Future<List<Alarm>> getAll() #

Gets an array of all the alarms.

Future<List<Alarm>> getAll() {
 if (_alarms == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<Alarm>>.oneArg((e) => listify(e, _createAlarm));
 _alarms.callMethod('getAll', [completer.callback]);
 return completer.future;
}