@capgo/capacitor-flash 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorFlash'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '12.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # capacitor-flash
2
+
3
+ Switch the Flashlight / Torch of your device.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @capgo/capacitor-flash
9
+ npx cap sync
10
+ ```
11
+
12
+ ## iOS
13
+
14
+ Works out of the box
15
+
16
+ ## Android
17
+
18
+ 1. Declare permissions in your app's `AndroidManifest.xml` file
19
+
20
+ ```xml
21
+ <!-- Permissions: Allows access to flashlight -->
22
+ <uses-permission android:name="android.permission.CAMERA" android:maxSdkVersion="23" />
23
+ <uses-permission android:name="android.permission.FLASHLIGHT" />
24
+
25
+ <!-- Actual Hardware Features Used-->
26
+ <uses-feature android:name="android.hardware.camera.flash" android:required="true" />
27
+ ```
28
+
29
+ ## API
30
+
31
+ <docgen-index>
32
+
33
+ * [`isAvailable()`](#isavailable)
34
+ * [`switchOn(...)`](#switchon)
35
+ * [`switchOff()`](#switchoff)
36
+ * [`isSwitchedOn()`](#isswitchedon)
37
+ * [`toggle()`](#toggle)
38
+
39
+ </docgen-index>
40
+
41
+ <docgen-api>
42
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
43
+
44
+ ### isAvailable()
45
+
46
+ ```typescript
47
+ isAvailable() => Promise<{ value: boolean; }>
48
+ ```
49
+
50
+ Checks if flashlight is available
51
+
52
+ **Returns:** <code>Promise&lt;{ value: boolean; }&gt;</code>
53
+
54
+ --------------------
55
+
56
+
57
+ ### switchOn(...)
58
+
59
+ ```typescript
60
+ switchOn(options: { intensity?: number; }) => Promise<void>
61
+ ```
62
+
63
+ Turns the flashlight on
64
+
65
+ | Param | Type |
66
+ | ------------- | ------------------------------------ |
67
+ | **`options`** | <code>{ intensity?: number; }</code> |
68
+
69
+ --------------------
70
+
71
+
72
+ ### switchOff()
73
+
74
+ ```typescript
75
+ switchOff() => Promise<void>
76
+ ```
77
+
78
+ Turns the flashlight off
79
+
80
+ --------------------
81
+
82
+
83
+ ### isSwitchedOn()
84
+
85
+ ```typescript
86
+ isSwitchedOn() => Promise<{ value: boolean; }>
87
+ ```
88
+
89
+ Checks if the flashlight is turned on or off
90
+
91
+ **Returns:** <code>Promise&lt;{ value: boolean; }&gt;</code>
92
+
93
+ --------------------
94
+
95
+
96
+ ### toggle()
97
+
98
+ ```typescript
99
+ toggle() => Promise<{ value: boolean; }>
100
+ ```
101
+
102
+ Toggle the flashlight
103
+
104
+ **Returns:** <code>Promise&lt;{ value: boolean; }&gt;</code>
105
+
106
+ --------------------
107
+
108
+ </docgen-api>
@@ -0,0 +1,58 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ jcenter()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:4.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
22
+ defaultConfig {
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
25
+ versionCode 1
26
+ versionName "1.0"
27
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28
+ }
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ }
34
+ }
35
+ lintOptions {
36
+ abortOnError false
37
+ }
38
+ compileOptions {
39
+ sourceCompatibility JavaVersion.VERSION_1_8
40
+ targetCompatibility JavaVersion.VERSION_1_8
41
+ }
42
+ }
43
+
44
+ repositories {
45
+ google()
46
+ jcenter()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="ee.forgr.plugin.capacitor_flash">
3
+ </manifest>
@@ -0,0 +1,150 @@
1
+ package ee.forgr.plugin.capacitor_flash;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.getcapacitor.PermissionState;
5
+ import com.getcapacitor.Plugin;
6
+ import com.getcapacitor.PluginCall;
7
+ import com.getcapacitor.PluginMethod;
8
+ import com.getcapacitor.annotation.CapacitorPlugin;
9
+ import com.getcapacitor.annotation.Permission;
10
+ import com.getcapacitor.annotation.PermissionCallback;
11
+
12
+ import android.Manifest;
13
+ import android.content.Context;
14
+ import android.hardware.camera2.CameraAccessException;
15
+ import android.hardware.camera2.CameraCharacteristics;
16
+ import android.hardware.camera2.CameraManager;
17
+ import android.os.Build;
18
+
19
+ import androidx.annotation.RequiresApi;
20
+
21
+ @CapacitorPlugin(
22
+ name = "CapacitorFlash",
23
+ permissions = {
24
+ @Permission(
25
+ alias = "camera",
26
+ strings = { Manifest.permission.CAMERA }
27
+ )
28
+ }
29
+ )
30
+ public class CapacitorFlashPlugin extends Plugin {
31
+
32
+ private String cameraId;
33
+ boolean isFlashStateOn = false;
34
+
35
+ private CameraManager cameraManager;
36
+
37
+
38
+ @Override
39
+ public void load() {
40
+ cameraManager = (CameraManager) this.bridge.getContext().getSystemService(Context.CAMERA_SERVICE);
41
+ try {
42
+
43
+ if (cameraManager != null) {
44
+ cameraId = cameraManager.getCameraIdList()[0];
45
+ }
46
+
47
+ } catch (CameraAccessException e) {
48
+ e.printStackTrace();
49
+ }
50
+ }
51
+
52
+
53
+ @PluginMethod
54
+ public void isAvailable(PluginCall call) {
55
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && getPermissionState("camera") != PermissionState.GRANTED) {
56
+ requestPermissionForAlias("camera", call, "cameraPermsCallback");
57
+ } else {
58
+ getAvailibility(call);
59
+ }
60
+ }
61
+
62
+ @PermissionCallback
63
+ private void getAvailibility(PluginCall call) {
64
+ JSObject ret = new JSObject();
65
+ if (cameraManager == null) {
66
+ ret.put("value", false);
67
+ call.resolve(ret);
68
+ return;
69
+ }
70
+ try {
71
+ boolean flashAvailable = cameraManager
72
+ .getCameraCharacteristics(cameraId)
73
+ .get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
74
+ ret.put("value", flashAvailable);
75
+ } catch (CameraAccessException e) {
76
+ e.printStackTrace();
77
+ ret.put("value", false);
78
+ }
79
+ call.resolve(ret);
80
+ }
81
+
82
+ @RequiresApi(api = Build.VERSION_CODES.M)
83
+ @PluginMethod
84
+ public void switchOn(PluginCall call) {
85
+ String value = call.getString("instensity"); // cannot be use in android
86
+ JSObject ret = new JSObject();
87
+ if (cameraManager == null) {
88
+ ret.put("value", false);
89
+ call.resolve(ret);
90
+ return;
91
+ }
92
+ try {
93
+ cameraManager.setTorchMode(cameraId, true);
94
+ isFlashStateOn = true;
95
+ ret.put("value", true);
96
+ } catch (Exception e) {
97
+ e.printStackTrace();
98
+ ret.put("value", false);
99
+ }
100
+ call.resolve(ret);
101
+ }
102
+
103
+ @RequiresApi(api = Build.VERSION_CODES.M)
104
+ @PluginMethod
105
+ public void switchOff(PluginCall call) {
106
+ JSObject ret = new JSObject();
107
+ if (cameraManager == null) {
108
+ ret.put("value", false);
109
+ call.resolve(ret);
110
+ return;
111
+ }
112
+ try {
113
+ cameraManager.setTorchMode(cameraId, false);
114
+ isFlashStateOn = false;
115
+ ret.put("value", true);
116
+ } catch (Exception e) {
117
+ e.printStackTrace();
118
+ ret.put("value", false);
119
+ }
120
+ call.resolve(ret);
121
+ }
122
+
123
+ @PluginMethod
124
+ public void isSwitchedOn(PluginCall call) {
125
+ JSObject ret = new JSObject();
126
+ ret.put("value", isFlashStateOn);
127
+ call.resolve(ret);
128
+ }
129
+
130
+ @RequiresApi(api = Build.VERSION_CODES.M)
131
+ @PluginMethod
132
+ public void toggle(PluginCall call) {
133
+ JSObject ret = new JSObject();
134
+ if (cameraManager == null) {
135
+ ret.put("value", false);
136
+ call.resolve(ret);
137
+ return;
138
+ }
139
+ try {
140
+ isFlashStateOn = !isFlashStateOn;
141
+ cameraManager.setTorchMode(cameraId, isFlashStateOn);
142
+ ret.put("value", isFlashStateOn);
143
+ } catch (Exception e) {
144
+ e.printStackTrace();
145
+ ret.put("value", false);
146
+ }
147
+ call.resolve(ret);
148
+ }
149
+
150
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "api": {
3
+ "name": "CapacitorFlashPlugin",
4
+ "slug": "capacitorflashplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "isAvailable",
10
+ "signature": "() => Promise<{ value: boolean; }>",
11
+ "parameters": [],
12
+ "returns": "Promise<{ value: boolean; }>",
13
+ "tags": [
14
+ {
15
+ "name": "returns",
16
+ "text": "true if flashlight is available and false if not"
17
+ }
18
+ ],
19
+ "docs": "Checks if flashlight is available",
20
+ "complexTypes": [],
21
+ "slug": "isavailable"
22
+ },
23
+ {
24
+ "name": "switchOn",
25
+ "signature": "(options: { intensity?: number; }) => Promise<void>",
26
+ "parameters": [
27
+ {
28
+ "name": "options",
29
+ "docs": "",
30
+ "type": "{ intensity?: number | undefined; }"
31
+ }
32
+ ],
33
+ "returns": "Promise<void>",
34
+ "tags": [
35
+ {
36
+ "name": "returns",
37
+ "text": "an empty Promise"
38
+ },
39
+ {
40
+ "name": "param",
41
+ "text": "intensity The intensity of the light between 0.0 and 1.0"
42
+ }
43
+ ],
44
+ "docs": "Turns the flashlight on",
45
+ "complexTypes": [],
46
+ "slug": "switchon"
47
+ },
48
+ {
49
+ "name": "switchOff",
50
+ "signature": "() => Promise<void>",
51
+ "parameters": [],
52
+ "returns": "Promise<void>",
53
+ "tags": [
54
+ {
55
+ "name": "rejects",
56
+ "text": "PluginResultError"
57
+ }
58
+ ],
59
+ "docs": "Turns the flashlight off",
60
+ "complexTypes": [],
61
+ "slug": "switchoff"
62
+ },
63
+ {
64
+ "name": "isSwitchedOn",
65
+ "signature": "() => Promise<{ value: boolean; }>",
66
+ "parameters": [],
67
+ "returns": "Promise<{ value: boolean; }>",
68
+ "tags": [
69
+ {
70
+ "name": "returns",
71
+ "text": "True of flaslight is turned on and false if not"
72
+ }
73
+ ],
74
+ "docs": "Checks if the flashlight is turned on or off",
75
+ "complexTypes": [],
76
+ "slug": "isswitchedon"
77
+ },
78
+ {
79
+ "name": "toggle",
80
+ "signature": "() => Promise<{ value: boolean; }>",
81
+ "parameters": [],
82
+ "returns": "Promise<{ value: boolean; }>",
83
+ "tags": [
84
+ {
85
+ "name": "returns",
86
+ "text": "True if that worked and false if not"
87
+ }
88
+ ],
89
+ "docs": "Toggle the flashlight",
90
+ "complexTypes": [],
91
+ "slug": "toggle"
92
+ }
93
+ ],
94
+ "properties": []
95
+ },
96
+ "interfaces": [],
97
+ "enums": [],
98
+ "typeAliases": [],
99
+ "pluginConfigs": []
100
+ }
@@ -0,0 +1,36 @@
1
+ export interface CapacitorFlashPlugin {
2
+ /**
3
+ * Checks if flashlight is available
4
+ * @returns {Promise<{ value: boolean }>} true if flashlight is available and false if not
5
+ */
6
+ isAvailable(): Promise<{
7
+ value: boolean;
8
+ }>;
9
+ /**
10
+ * Turns the flashlight on
11
+ * @returns {Promise<void>} an empty Promise
12
+ * @param intensity The intensity of the light between 0.0 and 1.0
13
+ */
14
+ switchOn(options: {
15
+ intensity?: number;
16
+ }): Promise<void>;
17
+ /**
18
+ * Turns the flashlight off
19
+ * @rejects PluginResultError
20
+ */
21
+ switchOff(): Promise<void>;
22
+ /**
23
+ * Checks if the flashlight is turned on or off
24
+ * @returns {Promise<{ value: boolean }>} True of flaslight is turned on and false if not
25
+ */
26
+ isSwitchedOn(): Promise<{
27
+ value: boolean;
28
+ }>;
29
+ /**
30
+ * Toggle the flashlight
31
+ * @returns {Promise<{ value: boolean }>} True if that worked and false if not
32
+ */
33
+ toggle(): Promise<{
34
+ value: boolean;
35
+ }>;
36
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { CapacitorFlashPlugin } from './definitions';
2
+ declare const CapacitorFlash: CapacitorFlashPlugin;
3
+ export * from './definitions';
4
+ export { CapacitorFlash };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const CapacitorFlash = registerPlugin('CapacitorFlash', {
3
+ web: () => import('./web').then(m => new m.CapacitorFlashWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { CapacitorFlash };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CACnC,gBAAgB,EAChB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAChE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { CapacitorFlashPlugin } from './definitions';
3
+ export declare class CapacitorFlashWeb extends WebPlugin implements CapacitorFlashPlugin {
4
+ isAvailable(): Promise<{
5
+ value: boolean;
6
+ }>;
7
+ switchOn(_options: {
8
+ intensity?: number;
9
+ }): Promise<void>;
10
+ switchOff(): Promise<void>;
11
+ isSwitchedOn(): Promise<{
12
+ value: boolean;
13
+ }>;
14
+ toggle(): Promise<{
15
+ value: boolean;
16
+ }>;
17
+ }
@@ -0,0 +1,25 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class CapacitorFlashWeb extends WebPlugin {
3
+ isAvailable() {
4
+ return Promise.resolve({ value: false });
5
+ }
6
+ ;
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ switchOn(_options) {
9
+ throw new Error("Method not implemented.");
10
+ }
11
+ ;
12
+ switchOff() {
13
+ throw new Error("Method not implemented.");
14
+ }
15
+ ;
16
+ isSwitchedOn() {
17
+ throw new Error("Method not implemented.");
18
+ }
19
+ ;
20
+ toggle() {
21
+ throw new Error("Method not implemented.");
22
+ }
23
+ ;
24
+ }
25
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,iBACX,SAAQ,SAAS;IAGjB,WAAW;QACT,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC,CAAA;IACzC,CAAC;IAAA,CAAC;IAEF,6DAA6D;IAC7D,QAAQ,CAAC,QAAgC;QACrC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAAA,CAAC;IAEJ,SAAS;QACL,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAAA,CAAC;IAEJ,YAAY;QACR,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAAA,CAAC;IAEJ,MAAM;QACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAAA,CAAC;CACL"}
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@capacitor/core');
6
+
7
+ const CapacitorFlash = core.registerPlugin('CapacitorFlash', {
8
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorFlashWeb()),
9
+ });
10
+
11
+ class CapacitorFlashWeb extends core.WebPlugin {
12
+ isAvailable() {
13
+ return Promise.resolve({ value: false });
14
+ }
15
+ ;
16
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
+ switchOn(_options) {
18
+ throw new Error("Method not implemented.");
19
+ }
20
+ ;
21
+ switchOff() {
22
+ throw new Error("Method not implemented.");
23
+ }
24
+ ;
25
+ isSwitchedOn() {
26
+ throw new Error("Method not implemented.");
27
+ }
28
+ ;
29
+ toggle() {
30
+ throw new Error("Method not implemented.");
31
+ }
32
+ ;
33
+ }
34
+
35
+ var web = /*#__PURE__*/Object.freeze({
36
+ __proto__: null,
37
+ CapacitorFlashWeb: CapacitorFlashWeb
38
+ });
39
+
40
+ exports.CapacitorFlash = CapacitorFlash;
41
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorFlash = registerPlugin('CapacitorFlash', {\n web: () => import('./web').then(m => new m.CapacitorFlashWeb()),\n});\nexport * from './definitions';\nexport { CapacitorFlash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorFlashWeb extends WebPlugin {\n isAvailable() {\n return Promise.resolve({ value: false });\n }\n ;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n switchOn(_options) {\n throw new Error(\"Method not implemented.\");\n }\n ;\n switchOff() {\n throw new Error(\"Method not implemented.\");\n }\n ;\n isSwitchedOn() {\n throw new Error(\"Method not implemented.\");\n }\n ;\n toggle() {\n throw new Error(\"Method not implemented.\");\n }\n ;\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;AACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;AACjD,IAAI,WAAW,GAAG;AAClB,QAAQ,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACjD,KAAK;AACL;AACA;AACA,IAAI,QAAQ,CAAC,QAAQ,EAAE;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL;AACA,IAAI,SAAS,GAAG;AAChB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL;AACA,IAAI,YAAY,GAAG;AACnB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL;AACA,IAAI,MAAM,GAAG;AACb,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL;AACA;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,44 @@
1
+ var capacitorCapacitorFlash = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const CapacitorFlash = core.registerPlugin('CapacitorFlash', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorFlashWeb()),
6
+ });
7
+
8
+ class CapacitorFlashWeb extends core.WebPlugin {
9
+ isAvailable() {
10
+ return Promise.resolve({ value: false });
11
+ }
12
+ ;
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ switchOn(_options) {
15
+ throw new Error("Method not implemented.");
16
+ }
17
+ ;
18
+ switchOff() {
19
+ throw new Error("Method not implemented.");
20
+ }
21
+ ;
22
+ isSwitchedOn() {
23
+ throw new Error("Method not implemented.");
24
+ }
25
+ ;
26
+ toggle() {
27
+ throw new Error("Method not implemented.");
28
+ }
29
+ ;
30
+ }
31
+
32
+ var web = /*#__PURE__*/Object.freeze({
33
+ __proto__: null,
34
+ CapacitorFlashWeb: CapacitorFlashWeb
35
+ });
36
+
37
+ exports.CapacitorFlash = CapacitorFlash;
38
+
39
+ Object.defineProperty(exports, '__esModule', { value: true });
40
+
41
+ return exports;
42
+
43
+ })({}, capacitorExports);
44
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorFlash = registerPlugin('CapacitorFlash', {\n web: () => import('./web').then(m => new m.CapacitorFlashWeb()),\n});\nexport * from './definitions';\nexport { CapacitorFlash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorFlashWeb extends WebPlugin {\n isAvailable() {\n return Promise.resolve({ value: false });\n }\n ;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n switchOn(_options) {\n throw new Error(\"Method not implemented.\");\n }\n ;\n switchOff() {\n throw new Error(\"Method not implemented.\");\n }\n ;\n isSwitchedOn() {\n throw new Error(\"Method not implemented.\");\n }\n ;\n toggle() {\n throw new Error(\"Method not implemented.\");\n }\n ;\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;IACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;IACjD,IAAI,WAAW,GAAG;IAClB,QAAQ,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,KAAK;IACL;IACA;IACA,IAAI,QAAQ,CAAC,QAAQ,EAAE;IACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL;IACA,IAAI,SAAS,GAAG;IAChB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL;IACA,IAAI,YAAY,GAAG;IACnB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL;IACA,IAAI,MAAM,GAAG;IACb,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL;IACA;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,65 @@
1
+ import Foundation
2
+ import AVFoundation
3
+
4
+ @objc public class CapacitorFlash: NSObject {
5
+
6
+ @objc public func isAvailable() -> Bool {
7
+ let device = AVCaptureDevice.default(for: AVMediaType.video)
8
+ return ((device?.hasTorch) != nil)
9
+ }
10
+
11
+ @objc public func switchOn(intensity: Float = 1.0) -> Bool {
12
+ guard self.isAvailable()
13
+ else { return false }
14
+
15
+ let device = AVCaptureDevice.default(for: AVMediaType.video)
16
+
17
+ do {
18
+ try device!.lockForConfiguration()
19
+ try device?.setTorchModeOn(level: intensity)
20
+ device?.torchMode = .on
21
+ device?.unlockForConfiguration()
22
+ return true
23
+ } catch {
24
+ print("Torch could not be used")
25
+ return false
26
+ }
27
+ }
28
+
29
+ @objc public func switchOff() -> Bool {
30
+ guard self.isAvailable()
31
+ else { return false }
32
+
33
+ let device = AVCaptureDevice.default(for: AVMediaType.video)
34
+
35
+ do {
36
+ try device?.lockForConfiguration()
37
+ device?.torchMode = .off
38
+ device?.unlockForConfiguration()
39
+ return true
40
+ } catch {
41
+ print("Torch could not be used")
42
+ return false
43
+ }
44
+ }
45
+
46
+ @objc public func isSwitchedOn() -> Bool {
47
+ guard self.isAvailable()
48
+ else { return false }
49
+
50
+ let device = AVCaptureDevice.default(for: AVMediaType.video)
51
+ return (device?.torchMode == AVCaptureDevice.TorchMode.on)
52
+ }
53
+
54
+ @objc public func toggle() -> Bool {
55
+ guard self.isAvailable()
56
+ else { return false }
57
+
58
+ let device = AVCaptureDevice.default(for: AVMediaType.video)
59
+ if (device?.torchMode == AVCaptureDevice.TorchMode.on) {
60
+ return self.switchOff()
61
+ } else {
62
+ return self.switchOn()
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,10 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ //! Project version number for Plugin.
4
+ FOUNDATION_EXPORT double PluginVersionNumber;
5
+
6
+ //! Project version string for Plugin.
7
+ FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
+
9
+ // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
+
@@ -0,0 +1,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Capacitor/Capacitor.h>
3
+
4
+ // Define the plugin using the CAP_PLUGIN Macro, and
5
+ // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
+ CAP_PLUGIN(CapacitorFlashPlugin, "CapacitorFlash",
7
+ CAP_PLUGIN_METHOD(isAvailable, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(switchOn, CAPPluginReturnPromise);
9
+ CAP_PLUGIN_METHOD(switchOff, CAPPluginReturnPromise);
10
+ CAP_PLUGIN_METHOD(isSwitchedOn, CAPPluginReturnPromise);
11
+ CAP_PLUGIN_METHOD(toggle, CAPPluginReturnPromise);
12
+ )
@@ -0,0 +1,42 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ /**
5
+ * Please read the Capacitor iOS Plugin Development Guide
6
+ * here: https://capacitorjs.com/docs/plugins/ios
7
+ */
8
+ @objc(CapacitorFlashPlugin)
9
+ public class CapacitorFlashPlugin: CAPPlugin {
10
+ private let implementation = CapacitorFlash()
11
+
12
+ @objc func isAvailable(_ call: CAPPluginCall) {
13
+ call.resolve([
14
+ "value": implementation.isAvailable()
15
+ ])
16
+ }
17
+
18
+ @objc func switchOn(_ call: CAPPluginCall) {
19
+ let intensity = call.getFloat("intensity") ?? 1.0
20
+ call.resolve([
21
+ "value": implementation.switchOn(intensity: intensity)
22
+ ])
23
+ }
24
+
25
+ @objc func switchOff(_ call: CAPPluginCall) {
26
+ call.resolve([
27
+ "value": implementation.switchOff()
28
+ ])
29
+ }
30
+
31
+ @objc func isSwitchedOn(_ call: CAPPluginCall) {
32
+ call.resolve([
33
+ "value": implementation.isSwitchedOn()
34
+ ])
35
+ }
36
+
37
+ @objc func toggle(_ call: CAPPluginCall) {
38
+ call.resolve([
39
+ "value": implementation.toggle()
40
+ ])
41
+ }
42
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>NSPrincipalClass</key>
22
+ <string></string>
23
+ </dict>
24
+ </plist>
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@capgo/capacitor-flash",
3
+ "version": "1.2.0",
4
+ "description": "Switch the Flashlight / Torch of your device.",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Plugin/",
14
+ "CapacitorFlash.podspec"
15
+ ],
16
+ "author": "Martin Donadieu",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/riderx/capacitor-flash.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/riderx/capacitor-flash/issues"
24
+ },
25
+ "keywords": [
26
+ "capacitor",
27
+ "flashlight",
28
+ "flash",
29
+ "light",
30
+ "plugin",
31
+ "native"
32
+ ],
33
+ "scripts": {
34
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
35
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
36
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
37
+ "verify:web": "npm run build",
38
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
39
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
40
+ "eslint": "eslint . --ext ts",
41
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
42
+ "swiftlint": "node-swiftlint",
43
+ "docgen": "docgen --api CapacitorFlashPlugin --output-readme README.md --output-json dist/docs.json",
44
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
45
+ "clean": "rimraf ./dist",
46
+ "watch": "tsc --watch",
47
+ "prepublishOnly": "npm run build"
48
+ },
49
+ "devDependencies": {
50
+ "@capacitor/android": "^3.0.0",
51
+ "@capacitor/core": "^3.0.0",
52
+ "@capacitor/docgen": "0.0.18",
53
+ "@capacitor/ios": "^3.0.0",
54
+ "@ionic/eslint-config": "^0.3.0",
55
+ "@ionic/prettier-config": "^1.0.1",
56
+ "@ionic/swiftlint-config": "^1.1.2",
57
+ "eslint": "^7.11.0",
58
+ "prettier": "~2.2.0",
59
+ "prettier-plugin-java": "~1.0.0",
60
+ "rimraf": "^3.0.2",
61
+ "rollup": "^2.32.0",
62
+ "swiftlint": "^1.0.1",
63
+ "typescript": "~4.0.3"
64
+ },
65
+ "peerDependencies": {
66
+ "@capacitor/core": "^3.0.0"
67
+ },
68
+ "prettier": "@ionic/prettier-config",
69
+ "swiftlint": "@ionic/swiftlint-config",
70
+ "eslintConfig": {
71
+ "extends": "@ionic/eslint-config/recommended"
72
+ },
73
+ "capacitor": {
74
+ "ios": {
75
+ "src": "ios"
76
+ },
77
+ "android": {
78
+ "src": "android"
79
+ }
80
+ }
81
+ }