2016-08-23 06:19:43 +08:00
|
|
|
import { Plugin } from './plugin';
|
2016-07-18 02:07:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
declare var navigator: any;
|
2016-08-11 19:55:26 +08:00
|
|
|
/**
|
|
|
|
* @name Screenshot
|
|
|
|
* @description Captures a screen shot
|
|
|
|
* @usage
|
|
|
|
* ```typescript
|
|
|
|
* import {Screenshot} from 'ionic-native';
|
|
|
|
*
|
|
|
|
* // Take a screenshot and save to file
|
2016-08-26 17:14:57 +08:00
|
|
|
* Screenshot.save('jpg', 80, 'myscreenshot.jpg').then(onSuccess, onError);
|
2016-08-11 19:55:26 +08:00
|
|
|
*
|
|
|
|
* // Take a screenshot and get temporary file URI
|
2016-08-26 17:14:57 +08:00
|
|
|
* Screenshot.URI(80).then(onSuccess, onError);
|
2016-08-11 19:55:26 +08:00
|
|
|
* ```
|
|
|
|
*/
|
2016-07-18 02:07:49 +08:00
|
|
|
@Plugin({
|
2016-10-28 01:48:50 +08:00
|
|
|
pluginName: 'Screenshot',
|
2016-07-18 02:07:49 +08:00
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param {string} format. Format can take the value of either 'jpg' or 'png'
|
|
|
|
* On ios, only 'jpg' format is supported
|
|
|
|
* @param {number} quality. Determines the quality of the screenshot.
|
|
|
|
* Default quality is set to 100.
|
|
|
|
* @param {string} filename. Name of the file as stored on the storage
|
|
|
|
*/
|
|
|
|
static save(format?: string, quality?: number, filename?: string): Promise<any> {
|
|
|
|
return new Promise<any>(
|
|
|
|
(resolve, reject) => {
|
|
|
|
navigator.screenshot.save(
|
|
|
|
(error, result) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
} else {
|
|
|
|
resolve(result);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static URI(quality?: number): Promise<any> {
|
|
|
|
return new Promise<any>(
|
|
|
|
(resolve, reject) => {
|
|
|
|
navigator.screenshot.URI(
|
|
|
|
(error, result) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
} else {
|
|
|
|
resolve(result);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
quality
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|