Skip to content

Commit

Permalink
Device ready call
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Nov 29, 2015
1 parent 3327fe8 commit 45dc983
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 14 deletions.
3 changes: 2 additions & 1 deletion demo/www/app/home/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Page, NavController} from 'ionic/ionic'

import {Camera, StatusBar, Toast} from 'ionic-native';
import {ActionSheet, Camera, StatusBar, Toast} from 'ionic-native';

import {Plugin} from '../plugin/plugin';

Expand All @@ -12,6 +12,7 @@ export class HomePage {
this.nav = nav;

this.plugins = [
ActionSheet,
Camera,
StatusBar,
Toast
Expand Down
14 changes: 13 additions & 1 deletion demo/www/app/plugin/plugin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import {Page, NavParams} from 'ionic/ionic';

import {Camera, StatusBar, Toast} from 'ionic-native';
import {Camera, StatusBar, Toast, ActionSheet} from 'ionic-native';

// To specify arguments for any plugin calls
var demoArgs = {};
demoArgs[ActionSheet] = {
show: {
'title': 'What do you want with this image?',
'buttonLabels': ['Share via Facebook', 'Share via Twitter'],
'androidEnableCancelButton' : true, // default false
'winphoneEnableCancelButton' : true, // default false
'addCancelButtonWithLabel': 'Cancel',
'addDestructiveButtonWithLabel' : 'Delete it',
'position': [20, 40] // for iPad pass in the [x, y] position of the popover
}
}

demoArgs[Toast] = {
showWithOptions: [
{
Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './plugins/actionsheet';
export * from './plugins/camera';
export * from './plugins/statusbar';
export * from './plugins/toast';
11 changes: 11 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var DEVICE_READY_TIMEOUT = 2000;
__export(require('./plugins/actionsheet'));
__export(require('./plugins/camera'));
__export(require('./plugins/statusbar'));
__export(require('./plugins/toast'));
var didFireReady = false;
window.addEventListener('deviceready', function () {
didFireReady = true;
});
setTimeout(function () {
if (!didFireReady) {
console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.');
}
}, DEVICE_READY_TIMEOUT);
4 changes: 4 additions & 0 deletions dist/plugins/actionsheet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare class ActionSheet {
static show: any;
static hide: any;
}
35 changes: 35 additions & 0 deletions dist/plugins/actionsheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var plugin_1 = require('./plugin');
var ActionSheet = (function () {
function ActionSheet() {
}
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], ActionSheet, "show");
__decorate([
plugin_1.Cordova({
successIndex: 1,
errIndex: 2
})
], ActionSheet, "hide");
ActionSheet = __decorate([
plugin_1.Plugin({
name: 'ActionSheet',
plugin: 'cordova-plugin-actionsheet',
pluginRef: 'plugins.actionsheet',
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-actionsheet'
})
], ActionSheet);
return ActionSheet;
})();
exports.ActionSheet = ActionSheet;
1 change: 0 additions & 1 deletion dist/plugins/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (typeof __decorate !== "function") __decorate = function (decorators, target,
}
};
var plugin_1 = require('./plugin');
var PLUGIN_REF = 'navigator.camera';
var Camera = (function () {
function Camera() {
}
Expand Down
7 changes: 6 additions & 1 deletion dist/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ exports.wrap = function (pluginObj, methodName, opts) {
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
console.log('Trying', pluginObj.name, methodName, args);
return new Promise(function (resolve, reject) {
if (!window.cordova) {
console.warn('Native: tried calling ' + pluginObj.name + '.' + methodName + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
reject({
error: 'cordova_not_available'
});
}
if (typeof opts.successIndex !== 'undefined') {
args[opts.successIndex] = resolve;
}
Expand Down
3 changes: 2 additions & 1 deletion dist/plugins/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var Toast = (function () {
plugin_1.Plugin({
name: 'Toast',
plugin: 'cordova-plugin-x-toast',
pluginRef: 'plugins.toast'
pluginRef: 'plugins.toast',
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
})
], Toast);
return Toast;
Expand Down
1 change: 1 addition & 0 deletions dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './plugins/actionsheet';
export * from './plugins/camera';
export * from './plugins/statusbar';
export * from './plugins/toast';
11 changes: 11 additions & 0 deletions dist/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var DEVICE_READY_TIMEOUT = 2000;
__export(require('./plugins/actionsheet'));
__export(require('./plugins/camera'));
__export(require('./plugins/statusbar'));
__export(require('./plugins/toast'));
var didFireReady = false;
window.addEventListener('deviceready', function () {
didFireReady = true;
});
setTimeout(function () {
if (!didFireReady && window.cordova) {
console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.');
}
}, DEVICE_READY_TIMEOUT);
1 change: 0 additions & 1 deletion dist/src/plugins/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var plugin_1 = require('./plugin');
var PLUGIN_REF = 'navigator.camera';
var Camera = (function () {
function Camera() {
}
Expand Down
7 changes: 6 additions & 1 deletion dist/src/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ exports.wrap = function (pluginObj, methodName, opts) {
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
console.log('Trying', pluginObj.name, methodName, args);
return new Promise(function (resolve, reject) {
if (!window.cordova) {
console.warn('Native: tried calling ' + pluginObj.name + '.' + methodName + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
reject({
error: 'cordova_not_available'
});
}
if (typeof opts.successIndex !== 'undefined') {
args[opts.successIndex] = resolve;
}
Expand Down
3 changes: 2 additions & 1 deletion dist/src/plugins/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var Toast = (function () {
plugin_1.Plugin({
name: 'Toast',
plugin: 'cordova-plugin-x-toast',
pluginRef: 'plugins.toast'
pluginRef: 'plugins.toast',
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
}),
__metadata('design:paramtypes', [])
], Toast);
Expand Down
3 changes: 3 additions & 0 deletions dist/src/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function get(obj, path) {
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
if (!obj) {
return null;
}
obj = obj[path[i]];
}
return obj;
Expand Down
3 changes: 3 additions & 0 deletions dist/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function get(obj, path) {
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
if (!obj) {
return null;
}
obj = obj[path[i]];
}
return obj;
Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
const DEVICE_READY_TIMEOUT = 2000;

export * from './plugins/actionsheet';
export * from './plugins/camera';
export * from './plugins/statusbar';
export * from './plugins/toast';

declare var window;


let didFireReady = false;
window.addEventListener('deviceready', function() {
didFireReady = true;
})

setTimeout(function() {
if(!didFireReady && window.cordova) {
console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.');
}
}, DEVICE_READY_TIMEOUT);
21 changes: 21 additions & 0 deletions src/plugins/actionsheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Plugin, Cordova} from './plugin';

@Plugin({
name: 'ActionSheet',
plugin: 'cordova-plugin-actionsheet',
pluginRef: 'plugins.actionsheet',
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-actionsheet'
})
export class ActionSheet {
@Cordova({
successIndex: 1,
errIndex: 2
})
static show;

@Cordova({
successIndex: 1,
errIndex: 2
})
static hide;
}
2 changes: 0 additions & 2 deletions src/plugins/camera.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Plugin, Cordova} from './plugin';

let PLUGIN_REF = 'navigator.camera';

@Plugin({
name: 'Camera',
plugin: 'cordova-plugin-camera',
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ declare var Promise;

export const wrap = function(pluginObj, methodName, opts: any = {}) {
return (...args) => {
console.log('Trying', pluginObj.name, methodName, args);
return new Promise((resolve, reject) => {

if(!window.cordova) {
console.warn('Native: tried calling ' + pluginObj.name + '.' + methodName + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
reject({
error: 'cordova_not_available'
})
}

if(typeof opts.successIndex !== 'undefined') {
args[opts.successIndex] = resolve;
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {Plugin, Cordova} from './plugin';
@Plugin({
name: 'Toast',
plugin: 'cordova-plugin-x-toast',
pluginRef: 'plugins.toast'
pluginRef: 'plugins.toast',
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
})
export class Toast {
@Cordova({
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export function get(obj, path) {
for (var i=0, path = path.split('.'), len = path.length; i < len; i++) {
for(var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
if(!obj) { return null; }
obj = obj[path[i]];
}
return obj;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"node_modules"
],
"files": [
"src/cordova.ts",
"src/index.ts",
"src/plugin-config.ts",
"src/plugins/actionsheet.ts",
"src/plugins/camera.ts",
"src/plugins/plugin.ts",
"src/plugins/statusbar.ts",
Expand Down

0 comments on commit 45dc983

Please sign in to comment.