refactor(screenshot):

This commit is contained in:
Guille 2016-07-17 20:07:49 +02:00
parent d46f22d2a1
commit 313b6952ae

View File

@ -1,5 +1,8 @@
import {Cordova, Plugin} from './plugin'; import { Cordova, Plugin } from './plugin';
declare var navigator: any; declare var navigator: any;
@Plugin({ @Plugin({
plugin: 'https://github.com/gitawego/cordova-screenshot.git', plugin: 'https://github.com/gitawego/cordova-screenshot.git',
pluginRef: 'navigator.screenshot', pluginRef: 'navigator.screenshot',
@ -7,23 +10,23 @@ declare var navigator: any;
}) })
export class Screenshot { export class Screenshot {
/** /**
* Takes screenshot and saves the image * Takes screenshot and saves the image
* *
* @param {string} format. Format can take the value of either 'jpg' or 'png' * @param {string} format. Format can take the value of either 'jpg' or 'png'
* On ios, only 'jpg' format is supported * On ios, only 'jpg' format is supported
* @param {number} quality. Determines the quality of the screenshot. * @param {number} quality. Determines the quality of the screenshot.
* Default quality is set to 100. * Default quality is set to 100.
* @param {string} filename. Name of the file as stored on the storage * @param {string} filename. Name of the file as stored on the storage
*/ */
static save (format?: string, quality?: number, filename?: string): Promise<any> { static save(format?: string, quality?: number, filename?: string): Promise<any> {
return new Promise<any>( return new Promise<any>(
(resolve, reject) => { (resolve, reject) => {
navigator.screenshot.save( navigator.screenshot.save(
(error, result) => { (error, result) => {
if (error) { if (error) {
reject(error); reject(error);
}else { } else {
resolve(result); resolve(result);
} }
}, },
@ -35,20 +38,20 @@ export class Screenshot {
); );
} }
/** /**
* Takes screenshot and returns the image as an URI * Takes screenshot and returns the image as an URI
* *
* @param {number} quality. Determines the quality of the screenshot. * @param {number} quality. Determines the quality of the screenshot.
* Default quality is set to 100. * Default quality is set to 100.
*/ */
static URI (quality?: number): Promise<any> { static URI(quality?: number): Promise<any> {
return new Promise<any>( return new Promise<any>(
(resolve, reject) => { (resolve, reject) => {
navigator.screenshot.URI( navigator.screenshot.URI(
(error, result) => { (error, result) => {
if (error) { if (error) {
reject(error); reject(error);
}else { } else {
resolve(result); resolve(result);
} }
}, },
@ -56,5 +59,5 @@ export class Screenshot {
); );
} }
); );
} }
} }