# ember-cli-cordova-shims

> Makes it simple to use a range of different Cordova plugins.

Latest version **0.3.0** (published 2015-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-cli-cordova-shims
pnpm add ember-cli-cordova-shims
yarn add ember-cli-cordova-shims
bun add ember-cli-cordova-shims
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2015-06-02 |
| First published | 2015-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Maintainers | theodorton |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-cli-cordova-shims
- Repository: https://github.com/Skalar/ember-cli-cordova-shims
- Issues: https://github.com/Skalar/ember-cli-cordova-shims/issues
- npm.io page: https://npm.io/package/ember-cli-cordova-shims

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^5.0.0

## Recent versions

- 0.3.0 (latest) — 2015-06-02
- 0.2.1 — 2015-06-01
- 0.1.0 — 2015-05-29
- 0.0.1 — 2015-05-27

## README

# Ember CLI Cordova Shims

This Ember addon makes it simple to use a range of different Cordova plugins.

## Supported features

### Push Notifications

Dependencies:

* `cordova plugin add org.apache.cordova.device`
* `cordova plugin add https://github.com/phonegap-build/PushPlugin.git`

Automatic behavior:

* Badge count will be set on the application on incoming notification
* Sounds will play on incoming notification (if set in the payload)

Events:

* `alert` - passes the message in the notification
* `badge` - passes a badge count with every emitted event
* `sound` - passes the filename of the sound to play

Public Methods:

* `register` - Prompts the user to allow notifications to this device
* `unregister` - Revokes notification subscription for this device

Usage:

```javascript
// app/initializers/pushplugin.js
import NotificationsService from 'ember-cli-cordova-shims/services/notifications';

export function initialize(container, application) {
  let service = NotificationsService.create({
    gcmSenderId: '{INSERT-KEY-FROM-GCM-HERE}',
    gcmTimeout: 10000 // Timeout for GCM in ms. Default: 15000
  });
  application.register('service:notifications', service, {
    instantiate: false
  });
  application.inject('route', 'notifications', 'service:notifications');
}

export default {
  name: 'notifications-service',
  initialize: initialize
};
```

```javascript
// app/routes/application.js
import Em from 'ember';

export default Em.Route.extend({

  badge: 0,

  listenForNotifications: function(){
    this.notifications.on('alert', function(message){
      alert(message); // or do whatever you want
    });
    this.notifications.on('badge', (badgeCount) => {
      this.set('badge', badgeCount); // or do whatever you want
    });
  }.on('init'),

  actions: {
    subscribeForNotifications: function(){
      let store = this.store;

      this.notifications.register().then(function(data){
        let network = data.network,
              token = data.token;
        return store.createRecord('device', {
          network: network,
          token: token
        }).save();
      }).then(function(deviceModelFromStore){
        Em.Logger.info('Successfully registered for notifications');
      }).catch(function(error){
        Em.Logger.error('Something went wrong registering for notifications', error);
      });
    },

    unsubscribeNotifications: function(){
      this.notifications.unregister().then(function(){
        Em.Logger.info('Successfully unregistered the device');
      }).catch(function(error){
        Em.Logger.error('Something went wrong while unregistering', error);
      });
    }
  }
});
```

Caveats:

* It's not possible to know what device what unregistered when calling `unregister`
* PushPlugin has a weird setup for registering devices with GCM. There is a timeout
of 15 seconds when doing a registration with GCM. If GCM does not send a `registered`
event within this timeframe, the device is not registered. The timeout value may be
overridden by passing `gcmTimeout` when instantiating the service.

### Dialogs

Dependencies:

* `cordova plugin add https://github.com/apache/cordova-plugin-dialogs.git`

Public Methods:

* `alert` - Show a message to the user
* `confirm` - Ask for some confirmation from the user
* `prompt` - Ask for some information from the user

Usage:

```javascript
// app/initializers/dialogs-service.js
import DialogsService from 'ember-cli-cordova-shims/services/dialogs';

export function initialize(container, application) {
  application.register('service:dialogs', DialogsService);
  application.inject('route', 'dialogs', 'service:dialogs');
}

export default {
  name: 'dialogs-service',
  initialize: initialize
};
```

```javascript
// app/routes/application.js
import Em from 'ember';

export default Em.Route.extend({

  actions: {
    something: function(){
      this.dialogs.alert({
        title: 'Hey',
        message: 'This just happened',
        button: 'OK'
      }).then(function(){
        // Do something
      });
    }
  }
});
```

### Network Activity Indicator

Dependencies:

* `cordova plugin add com.wearecocoon.cordova.plugin.networkactivity`

Usage:

```javascript
// app/adaptesr/application.js
import NetworkActivityAdapterMixin from 'ember-cli-cordova-shims/mixins/network-activity-adapter';

export default DS.RESTAdapter.extend(NetworkActivityAdapterMixin, {
  // Your implementation goes here
});
```

## Installation

* `git clone` this repository
* `npm install`
* `bower install`

## Running

* `ember server`
* Visit your app at http://localhost:4200.

## Running Tests

* `ember test`
* `ember test --server`

## Documentation

The modules are documented with yuidoc.

* `npm install yuidocjs -g`
* `yuidoc -c yuidoc.json`

## Building

* `ember build`

For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).

---
_Source: https://npm.io/package/ember-cli-cordova-shims · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
