awesome-cordova-plugins/src/plugins/screenshot.ts

61 lines
1.6 KiB
TypeScript
Raw Normal View History

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