From 3ec25fa63b0b955352a4a1b14a2a7d82018a033e Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 16:56:29 -0500 Subject: [PATCH] feat(plugin): add flashlight plugin --- src/plugins/flashlight.ts | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/plugins/flashlight.ts diff --git a/src/plugins/flashlight.ts b/src/plugins/flashlight.ts new file mode 100644 index 000000000..9cd9f23c2 --- /dev/null +++ b/src/plugins/flashlight.ts @@ -0,0 +1,90 @@ +import {Plugin, Cordova} from './plugin'; + +/** + * @name Flashlight + * @description This plugin allows you to switch the flashlight / torch of the device on and off. + * + * Requires Cordova plugin: `cordova-plugin-flashlight`. For more info, please see the [Flashlight plugin docs](https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin). + * + * @usage + * ```js + * ``` + */ +@Plugin({ + plugin: 'https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin.git', + pluginRef: 'window.plugins.flashlight' +}) +export class Flashlight { + + + /** + * Checks if the flash light is available + * @returns {Promise} Returns a promise that resolves with a boolean stating if the flash light is available. + */ + @Cordova() + static available() : Promise{ + // This Promise is replaced by one from the @Cordova decorator that wraps + // the plugin's callbacks. We provide a dummy one here so TypeScript + // knows that the correct return type is Promise, because there's no way + // for it to know the return type from a decorator. + // See https://github.com/Microsoft/TypeScript/issues/4881 + + return new Promise((res,rej)=>{}); + } + + /** + * Switches the flashlight on + * @returns {Promise} + */ + @Cordova() + static switchOn() : Promise{ + // This Promise is replaced by one from the @Cordova decorator that wraps + // the plugin's callbacks. We provide a dummy one here so TypeScript + // knows that the correct return type is Promise, because there's no way + // for it to know the return type from a decorator. + // See https://github.com/Microsoft/TypeScript/issues/4881 + + return new Promise((res,rej)=>{}); + } + + /** + * Switches the flash light off + * @returns {Promise} + */ + @Cordova() + static switchOff() : Promise{ + // This Promise is replaced by one from the @Cordova decorator that wraps + // the plugin's callbacks. We provide a dummy one here so TypeScript + // knows that the correct return type is Promise, because there's no way + // for it to know the return type from a decorator. + // See https://github.com/Microsoft/TypeScript/issues/4881 + + return new Promise((res,rej)=>{}); + } + + /** + * Toggles the flashlight + * @returns {Promise} + */ + @Cordova() + static toggle() : Promise { + // This Promise is replaced by one from the @Cordova decorator that wraps + // the plugin's callbacks. We provide a dummy one here so TypeScript + // knows that the correct return type is Promise, because there's no way + // for it to know the return type from a decorator. + // See https://github.com/Microsoft/TypeScript/issues/4881 + + return new Promise((res,rej)=>{}); + } + + + /** + * Checks if the flash light is turned on. + * Returns a boolean + */ + @Cordova({ + sync: true + }) + static isSwitchedOn() {} + +} \ No newline at end of file