refactor(screenshot):

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

View File

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