@capawesome/capacitor-screen-brightness 0.0.1

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.
Files changed (39) hide show
  1. package/CapawesomeCapacitorScreenBrightness.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +185 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/ScreenBrightness.java +69 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/ScreenBrightnessPlugin.java +111 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/classes/CustomException.java +20 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/classes/CustomExceptions.java +7 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/classes/options/SetBrightnessOptions.java +28 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/classes/results/GetBrightnessResult.java +22 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/interfaces/Callback.java +7 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/interfaces/EmptyCallback.java +5 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/interfaces/NonEmptyResultCallback.java +7 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenbrightness/interfaces/Result.java +7 -0
  17. package/android/src/main/res/.gitkeep +0 -0
  18. package/dist/docs.json +131 -0
  19. package/dist/esm/definitions.d.ts +60 -0
  20. package/dist/esm/definitions.js +2 -0
  21. package/dist/esm/definitions.js.map +1 -0
  22. package/dist/esm/index.d.ts +4 -0
  23. package/dist/esm/index.js +7 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/web.d.ts +7 -0
  26. package/dist/esm/web.js +13 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +27 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +30 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Plugin/Classes/Options/SetBrightnessOptions.swift +20 -0
  33. package/ios/Plugin/Classes/Results/GetBrightnessResult.swift +16 -0
  34. package/ios/Plugin/Enums/CustomError.swift +17 -0
  35. package/ios/Plugin/Info.plist +24 -0
  36. package/ios/Plugin/Protocols/Result.swift +5 -0
  37. package/ios/Plugin/ScreenBrightness.swift +26 -0
  38. package/ios/Plugin/ScreenBrightnessPlugin.swift +72 -0
  39. package/package.json +91 -0
@@ -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 = 'CapawesomeCapacitorScreenBrightness'
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 = '15.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robin Genz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapawesomeCapacitorScreenBrightness",
6
+ platforms: [.iOS(.v15)],
7
+ products: [
8
+ .library(
9
+ name: "CapawesomeCapacitorScreenBrightness",
10
+ targets: ["ScreenBrightnessPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "ScreenBrightnessPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Plugin"),
23
+ .testTarget(
24
+ name: "ScreenBrightnessPluginTests",
25
+ dependencies: ["ScreenBrightnessPlugin"],
26
+ path: "ios/PluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # @capawesome/capacitor-screen-brightness
2
+
3
+ Capacitor plugin for reading and controlling the screen brightness.
4
+
5
+ <div class="capawesome-z29o10a">
6
+ <a href="https://cloud.capawesome.io/" target="_blank">
7
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
8
+ </a>
9
+ </div>
10
+
11
+ ## Features
12
+
13
+ - ☀️ **Read brightness**: Read the current screen brightness.
14
+ - 🔆 **Set brightness**: Set the screen brightness, e.g. to boost it for barcode or ticket display.
15
+ - 🔄 **Reset brightness**: Hand the brightness control back to the operating system.
16
+ - 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
17
+ - 🔁 **Up-to-date**: Always supports the latest Capacitor version.
18
+
19
+ Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
20
+
21
+ ## Newsletter
22
+
23
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
24
+
25
+ ## Compatibility
26
+
27
+ | Plugin Version | Capacitor Version | Status |
28
+ | -------------- | ----------------- | -------------- |
29
+ | 0.x.x | >=8.x.x | Active support |
30
+
31
+ ## Installation
32
+
33
+ You can use our **AI-Assisted Setup** to install the plugin.
34
+ Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
35
+
36
+ ```bash
37
+ npx skills add capawesome-team/skills --skill capacitor-plugins
38
+ ```
39
+
40
+ Then use the following prompt:
41
+
42
+ ```
43
+ Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-screen-brightness` plugin in my project.
44
+ ```
45
+
46
+ If you prefer **Manual Setup**, install the plugin by running the following commands:
47
+
48
+ ```bash
49
+ npm install @capawesome/capacitor-screen-brightness
50
+ npx cap sync
51
+ ```
52
+
53
+ This plugin is available on **Android** and **iOS**. On Web, all methods reject as unimplemented.
54
+
55
+ ## Configuration
56
+
57
+ No configuration required for this plugin.
58
+
59
+ ## Usage
60
+
61
+ ```typescript
62
+ import { ScreenBrightness } from '@capawesome/capacitor-screen-brightness';
63
+
64
+ const getBrightness = async () => {
65
+ const { brightness } = await ScreenBrightness.getBrightness();
66
+ return brightness;
67
+ };
68
+
69
+ const setBrightness = async () => {
70
+ await ScreenBrightness.setBrightness({ brightness: 1 });
71
+ };
72
+
73
+ const resetBrightness = async () => {
74
+ await ScreenBrightness.resetBrightness();
75
+ };
76
+ ```
77
+
78
+ ## API
79
+
80
+ <docgen-index>
81
+
82
+ * [`getBrightness()`](#getbrightness)
83
+ * [`resetBrightness()`](#resetbrightness)
84
+ * [`setBrightness(...)`](#setbrightness)
85
+ * [Interfaces](#interfaces)
86
+
87
+ </docgen-index>
88
+
89
+ <docgen-api>
90
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
91
+
92
+ ### getBrightness()
93
+
94
+ ```typescript
95
+ getBrightness() => Promise<GetBrightnessResult>
96
+ ```
97
+
98
+ Get the current screen brightness.
99
+
100
+ Only available on Android and iOS.
101
+
102
+ **Returns:** <code>Promise&lt;<a href="#getbrightnessresult">GetBrightnessResult</a>&gt;</code>
103
+
104
+ **Since:** 0.1.0
105
+
106
+ --------------------
107
+
108
+
109
+ ### resetBrightness()
110
+
111
+ ```typescript
112
+ resetBrightness() => Promise<void>
113
+ ```
114
+
115
+ Reset the screen brightness to the system default.
116
+
117
+ This hands the brightness control back to the operating system.
118
+
119
+ Only available on Android.
120
+
121
+ **Since:** 0.1.0
122
+
123
+ --------------------
124
+
125
+
126
+ ### setBrightness(...)
127
+
128
+ ```typescript
129
+ setBrightness(options: SetBrightnessOptions) => Promise<void>
130
+ ```
131
+
132
+ Set the screen brightness.
133
+
134
+ On Android, only the brightness of the current app window is changed.
135
+ The change is reverted automatically as soon as the app is closed.
136
+
137
+ On iOS, this changes the **system** brightness and the change persists
138
+ after the app is closed.
139
+
140
+ Only available on Android and iOS.
141
+
142
+ | Param | Type |
143
+ | ------------- | --------------------------------------------------------------------- |
144
+ | **`options`** | <code><a href="#setbrightnessoptions">SetBrightnessOptions</a></code> |
145
+
146
+ **Since:** 0.1.0
147
+
148
+ --------------------
149
+
150
+
151
+ ### Interfaces
152
+
153
+
154
+ #### GetBrightnessResult
155
+
156
+ | Prop | Type | Description | Since |
157
+ | ---------------- | ------------------- | --------------------------------------------------------------------------------------- | ----- |
158
+ | **`brightness`** | <code>number</code> | The current screen brightness as a value between `0.0` (darkest) and `1.0` (brightest). | 0.1.0 |
159
+
160
+
161
+ #### SetBrightnessOptions
162
+
163
+ | Prop | Type | Description | Since |
164
+ | ---------------- | ------------------- | -------------------------------------------------------------------------------------- | ----- |
165
+ | **`brightness`** | <code>number</code> | The screen brightness to set as a value between `0.0` (darkest) and `1.0` (brightest). | 0.1.0 |
166
+
167
+ </docgen-api>
168
+
169
+ ## Platform Notes
170
+
171
+ ### Android
172
+
173
+ Setting the brightness only affects the **current app window** and does not require the `WRITE_SETTINGS` permission. The change is reverted automatically as soon as the app is closed. Use `resetBrightness()` to hand the brightness control back to the operating system while the app is running.
174
+
175
+ ### iOS
176
+
177
+ Setting the brightness changes the **system** brightness and the change **persists** after the app is closed. There is no system API to hand the brightness control back to the operating system, so `resetBrightness()` is not available on iOS and rejects as unimplemented.
178
+
179
+ ## Changelog
180
+
181
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/screen-brightness/CHANGELOG.md).
182
+
183
+ ## License
184
+
185
+ See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/screen-brightness/LICENSE).
@@ -0,0 +1,58 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace = "io.capawesome.capacitorjs.plugins.screenbrightness"
22
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError = false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
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,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,69 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness;
2
+
3
+ import android.app.Activity;
4
+ import android.provider.Settings;
5
+ import android.view.Window;
6
+ import android.view.WindowManager;
7
+ import androidx.annotation.NonNull;
8
+ import io.capawesome.capacitorjs.plugins.screenbrightness.classes.options.SetBrightnessOptions;
9
+ import io.capawesome.capacitorjs.plugins.screenbrightness.classes.results.GetBrightnessResult;
10
+ import io.capawesome.capacitorjs.plugins.screenbrightness.interfaces.EmptyCallback;
11
+ import io.capawesome.capacitorjs.plugins.screenbrightness.interfaces.NonEmptyResultCallback;
12
+
13
+ public class ScreenBrightness {
14
+
15
+ private static final int MAXIMUM_SYSTEM_BRIGHTNESS = 255;
16
+
17
+ @NonNull
18
+ private final ScreenBrightnessPlugin plugin;
19
+
20
+ public ScreenBrightness(@NonNull ScreenBrightnessPlugin plugin) {
21
+ this.plugin = plugin;
22
+ }
23
+
24
+ public void getBrightness(@NonNull NonEmptyResultCallback<GetBrightnessResult> callback) {
25
+ runOnUiThread(() -> {
26
+ float brightness = getWindow().getAttributes().screenBrightness;
27
+ if (brightness < 0) {
28
+ brightness = getSystemBrightness();
29
+ }
30
+ callback.success(new GetBrightnessResult(brightness));
31
+ });
32
+ }
33
+
34
+ public void resetBrightness(@NonNull EmptyCallback callback) {
35
+ runOnUiThread(() -> {
36
+ Window window = getWindow();
37
+ WindowManager.LayoutParams attributes = window.getAttributes();
38
+ attributes.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
39
+ window.setAttributes(attributes);
40
+ callback.success();
41
+ });
42
+ }
43
+
44
+ public void setBrightness(@NonNull SetBrightnessOptions options, @NonNull EmptyCallback callback) {
45
+ float brightness = options.getBrightness();
46
+ runOnUiThread(() -> {
47
+ Window window = getWindow();
48
+ WindowManager.LayoutParams attributes = window.getAttributes();
49
+ attributes.screenBrightness = brightness;
50
+ window.setAttributes(attributes);
51
+ callback.success();
52
+ });
53
+ }
54
+
55
+ private float getSystemBrightness() {
56
+ int brightness = Settings.System.getInt(plugin.getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0);
57
+ return (float) brightness / MAXIMUM_SYSTEM_BRIGHTNESS;
58
+ }
59
+
60
+ @NonNull
61
+ private Window getWindow() {
62
+ return plugin.getActivity().getWindow();
63
+ }
64
+
65
+ private void runOnUiThread(@NonNull Runnable runnable) {
66
+ Activity activity = plugin.getActivity();
67
+ activity.runOnUiThread(runnable);
68
+ }
69
+ }
@@ -0,0 +1,111 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.Logger;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+ import io.capawesome.capacitorjs.plugins.screenbrightness.classes.options.SetBrightnessOptions;
11
+ import io.capawesome.capacitorjs.plugins.screenbrightness.classes.results.GetBrightnessResult;
12
+ import io.capawesome.capacitorjs.plugins.screenbrightness.interfaces.EmptyCallback;
13
+ import io.capawesome.capacitorjs.plugins.screenbrightness.interfaces.NonEmptyResultCallback;
14
+ import io.capawesome.capacitorjs.plugins.screenbrightness.interfaces.Result;
15
+
16
+ @CapacitorPlugin(name = "ScreenBrightness")
17
+ public class ScreenBrightnessPlugin extends Plugin {
18
+
19
+ public static final String TAG = "ScreenBrightness";
20
+
21
+ private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
22
+
23
+ private ScreenBrightness implementation;
24
+
25
+ @Override
26
+ public void load() {
27
+ implementation = new ScreenBrightness(this);
28
+ }
29
+
30
+ @PluginMethod
31
+ public void getBrightness(PluginCall call) {
32
+ try {
33
+ NonEmptyResultCallback<GetBrightnessResult> callback = new NonEmptyResultCallback<>() {
34
+ @Override
35
+ public void success(@NonNull GetBrightnessResult result) {
36
+ resolveCall(call, result);
37
+ }
38
+
39
+ @Override
40
+ public void error(@NonNull Exception exception) {
41
+ rejectCall(call, exception);
42
+ }
43
+ };
44
+ implementation.getBrightness(callback);
45
+ } catch (Exception exception) {
46
+ rejectCall(call, exception);
47
+ }
48
+ }
49
+
50
+ @PluginMethod
51
+ public void resetBrightness(PluginCall call) {
52
+ try {
53
+ EmptyCallback callback = new EmptyCallback() {
54
+ @Override
55
+ public void success() {
56
+ resolveCall(call);
57
+ }
58
+
59
+ @Override
60
+ public void error(@NonNull Exception exception) {
61
+ rejectCall(call, exception);
62
+ }
63
+ };
64
+ implementation.resetBrightness(callback);
65
+ } catch (Exception exception) {
66
+ rejectCall(call, exception);
67
+ }
68
+ }
69
+
70
+ @PluginMethod
71
+ public void setBrightness(PluginCall call) {
72
+ try {
73
+ SetBrightnessOptions options = new SetBrightnessOptions(call);
74
+ EmptyCallback callback = new EmptyCallback() {
75
+ @Override
76
+ public void success() {
77
+ resolveCall(call);
78
+ }
79
+
80
+ @Override
81
+ public void error(@NonNull Exception exception) {
82
+ rejectCall(call, exception);
83
+ }
84
+ };
85
+ implementation.setBrightness(options, callback);
86
+ } catch (Exception exception) {
87
+ rejectCall(call, exception);
88
+ }
89
+ }
90
+
91
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
92
+ String message = exception.getMessage();
93
+ if (message == null) {
94
+ message = ERROR_UNKNOWN_ERROR;
95
+ }
96
+ Logger.error(TAG, message, exception);
97
+ call.reject(message);
98
+ }
99
+
100
+ private void resolveCall(@NonNull PluginCall call) {
101
+ call.resolve();
102
+ }
103
+
104
+ private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
105
+ if (result == null) {
106
+ call.resolve();
107
+ } else {
108
+ call.resolve(result.toJSObject());
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,20 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.classes;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ public class CustomException extends Exception {
7
+
8
+ @Nullable
9
+ private final String code;
10
+
11
+ public CustomException(@Nullable String code, @NonNull String message) {
12
+ super(message);
13
+ this.code = code;
14
+ }
15
+
16
+ @Nullable
17
+ public String getCode() {
18
+ return code;
19
+ }
20
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.classes;
2
+
3
+ public class CustomExceptions {
4
+
5
+ public static final CustomException BRIGHTNESS_INVALID = new CustomException(null, "brightness must be between 0.0 and 1.0.");
6
+ public static final CustomException BRIGHTNESS_MISSING = new CustomException(null, "brightness must be provided.");
7
+ }
@@ -0,0 +1,28 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.classes.options;
2
+
3
+ import com.getcapacitor.PluginCall;
4
+ import io.capawesome.capacitorjs.plugins.screenbrightness.classes.CustomExceptions;
5
+
6
+ public class SetBrightnessOptions {
7
+
8
+ private final float brightness;
9
+
10
+ public SetBrightnessOptions(PluginCall call) throws Exception {
11
+ this.brightness = SetBrightnessOptions.getBrightnessFromCall(call);
12
+ }
13
+
14
+ public float getBrightness() {
15
+ return brightness;
16
+ }
17
+
18
+ private static float getBrightnessFromCall(PluginCall call) throws Exception {
19
+ Double brightness = call.getDouble("brightness");
20
+ if (brightness == null) {
21
+ throw CustomExceptions.BRIGHTNESS_MISSING;
22
+ }
23
+ if (brightness < 0.0 || brightness > 1.0) {
24
+ throw CustomExceptions.BRIGHTNESS_INVALID;
25
+ }
26
+ return brightness.floatValue();
27
+ }
28
+ }
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.screenbrightness.interfaces.Result;
6
+
7
+ public class GetBrightnessResult implements Result {
8
+
9
+ private final float brightness;
10
+
11
+ public GetBrightnessResult(float brightness) {
12
+ this.brightness = brightness;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("brightness", brightness);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.interfaces;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ public interface Callback {
6
+ void error(@NonNull Exception exception);
7
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.interfaces;
2
+
3
+ public interface EmptyCallback extends Callback {
4
+ void success();
5
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.interfaces;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ public interface NonEmptyResultCallback<T extends Result> extends Callback {
6
+ void success(@NonNull T result);
7
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.screenbrightness.interfaces;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface Result {
6
+ JSObject toJSObject();
7
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,131 @@
1
+ {
2
+ "api": {
3
+ "name": "ScreenBrightnessPlugin",
4
+ "slug": "screenbrightnessplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "getBrightness",
10
+ "signature": "() => Promise<GetBrightnessResult>",
11
+ "parameters": [],
12
+ "returns": "Promise<GetBrightnessResult>",
13
+ "tags": [
14
+ {
15
+ "name": "since",
16
+ "text": "0.1.0"
17
+ }
18
+ ],
19
+ "docs": "Get the current screen brightness.\n\nOnly available on Android and iOS.",
20
+ "complexTypes": [
21
+ "GetBrightnessResult"
22
+ ],
23
+ "slug": "getbrightness"
24
+ },
25
+ {
26
+ "name": "resetBrightness",
27
+ "signature": "() => Promise<void>",
28
+ "parameters": [],
29
+ "returns": "Promise<void>",
30
+ "tags": [
31
+ {
32
+ "name": "since",
33
+ "text": "0.1.0"
34
+ }
35
+ ],
36
+ "docs": "Reset the screen brightness to the system default.\n\nThis hands the brightness control back to the operating system.\n\nOnly available on Android.",
37
+ "complexTypes": [],
38
+ "slug": "resetbrightness"
39
+ },
40
+ {
41
+ "name": "setBrightness",
42
+ "signature": "(options: SetBrightnessOptions) => Promise<void>",
43
+ "parameters": [
44
+ {
45
+ "name": "options",
46
+ "docs": "",
47
+ "type": "SetBrightnessOptions"
48
+ }
49
+ ],
50
+ "returns": "Promise<void>",
51
+ "tags": [
52
+ {
53
+ "name": "since",
54
+ "text": "0.1.0"
55
+ }
56
+ ],
57
+ "docs": "Set the screen brightness.\n\nOn Android, only the brightness of the current app window is changed.\nThe change is reverted automatically as soon as the app is closed.\n\nOn iOS, this changes the **system** brightness and the change persists\nafter the app is closed.\n\nOnly available on Android and iOS.",
58
+ "complexTypes": [
59
+ "SetBrightnessOptions"
60
+ ],
61
+ "slug": "setbrightness"
62
+ }
63
+ ],
64
+ "properties": []
65
+ },
66
+ "interfaces": [
67
+ {
68
+ "name": "GetBrightnessResult",
69
+ "slug": "getbrightnessresult",
70
+ "docs": "",
71
+ "tags": [
72
+ {
73
+ "text": "0.1.0",
74
+ "name": "since"
75
+ }
76
+ ],
77
+ "methods": [],
78
+ "properties": [
79
+ {
80
+ "name": "brightness",
81
+ "tags": [
82
+ {
83
+ "text": "0.5",
84
+ "name": "example"
85
+ },
86
+ {
87
+ "text": "0.1.0",
88
+ "name": "since"
89
+ }
90
+ ],
91
+ "docs": "The current screen brightness as a value between `0.0` (darkest) and\n`1.0` (brightest).",
92
+ "complexTypes": [],
93
+ "type": "number"
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "name": "SetBrightnessOptions",
99
+ "slug": "setbrightnessoptions",
100
+ "docs": "",
101
+ "tags": [
102
+ {
103
+ "text": "0.1.0",
104
+ "name": "since"
105
+ }
106
+ ],
107
+ "methods": [],
108
+ "properties": [
109
+ {
110
+ "name": "brightness",
111
+ "tags": [
112
+ {
113
+ "text": "0.5",
114
+ "name": "example"
115
+ },
116
+ {
117
+ "text": "0.1.0",
118
+ "name": "since"
119
+ }
120
+ ],
121
+ "docs": "The screen brightness to set as a value between `0.0` (darkest) and\n`1.0` (brightest).",
122
+ "complexTypes": [],
123
+ "type": "number"
124
+ }
125
+ ]
126
+ }
127
+ ],
128
+ "enums": [],
129
+ "typeAliases": [],
130
+ "pluginConfigs": []
131
+ }
@@ -0,0 +1,60 @@
1
+ export interface ScreenBrightnessPlugin {
2
+ /**
3
+ * Get the current screen brightness.
4
+ *
5
+ * Only available on Android and iOS.
6
+ *
7
+ * @since 0.1.0
8
+ */
9
+ getBrightness(): Promise<GetBrightnessResult>;
10
+ /**
11
+ * Reset the screen brightness to the system default.
12
+ *
13
+ * This hands the brightness control back to the operating system.
14
+ *
15
+ * Only available on Android.
16
+ *
17
+ * @since 0.1.0
18
+ */
19
+ resetBrightness(): Promise<void>;
20
+ /**
21
+ * Set the screen brightness.
22
+ *
23
+ * On Android, only the brightness of the current app window is changed.
24
+ * The change is reverted automatically as soon as the app is closed.
25
+ *
26
+ * On iOS, this changes the **system** brightness and the change persists
27
+ * after the app is closed.
28
+ *
29
+ * Only available on Android and iOS.
30
+ *
31
+ * @since 0.1.0
32
+ */
33
+ setBrightness(options: SetBrightnessOptions): Promise<void>;
34
+ }
35
+ /**
36
+ * @since 0.1.0
37
+ */
38
+ export interface GetBrightnessResult {
39
+ /**
40
+ * The current screen brightness as a value between `0.0` (darkest) and
41
+ * `1.0` (brightest).
42
+ *
43
+ * @example 0.5
44
+ * @since 0.1.0
45
+ */
46
+ brightness: number;
47
+ }
48
+ /**
49
+ * @since 0.1.0
50
+ */
51
+ export interface SetBrightnessOptions {
52
+ /**
53
+ * The screen brightness to set as a value between `0.0` (darkest) and
54
+ * `1.0` (brightest).
55
+ *
56
+ * @example 0.5
57
+ * @since 0.1.0
58
+ */
59
+ brightness: number;
60
+ }
@@ -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":"","sourcesContent":["export interface ScreenBrightnessPlugin {\n /**\n * Get the current screen brightness.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n getBrightness(): Promise<GetBrightnessResult>;\n /**\n * Reset the screen brightness to the system default.\n *\n * This hands the brightness control back to the operating system.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n resetBrightness(): Promise<void>;\n /**\n * Set the screen brightness.\n *\n * On Android, only the brightness of the current app window is changed.\n * The change is reverted automatically as soon as the app is closed.\n *\n * On iOS, this changes the **system** brightness and the change persists\n * after the app is closed.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n setBrightness(options: SetBrightnessOptions): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetBrightnessResult {\n /**\n * The current screen brightness as a value between `0.0` (darkest) and\n * `1.0` (brightest).\n *\n * @example 0.5\n * @since 0.1.0\n */\n brightness: number;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface SetBrightnessOptions {\n /**\n * The screen brightness to set as a value between `0.0` (darkest) and\n * `1.0` (brightest).\n *\n * @example 0.5\n * @since 0.1.0\n */\n brightness: number;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { ScreenBrightnessPlugin } from './definitions';
2
+ declare const ScreenBrightness: ScreenBrightnessPlugin;
3
+ export * from './definitions';
4
+ export { ScreenBrightness };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const ScreenBrightness = registerPlugin('ScreenBrightness', {
3
+ web: () => import('./web').then(m => new m.ScreenBrightnessWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { ScreenBrightness };
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,gBAAgB,GAAG,cAAc,CACrC,kBAAkB,EAClB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;CAClE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { ScreenBrightnessPlugin } from './definitions';\n\nconst ScreenBrightness = registerPlugin<ScreenBrightnessPlugin>(\n 'ScreenBrightness',\n {\n web: () => import('./web').then(m => new m.ScreenBrightnessWeb()),\n },\n);\n\nexport * from './definitions';\nexport { ScreenBrightness };\n"]}
@@ -0,0 +1,7 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { GetBrightnessResult, ScreenBrightnessPlugin } from './definitions';
3
+ export declare class ScreenBrightnessWeb extends WebPlugin implements ScreenBrightnessPlugin {
4
+ getBrightness(): Promise<GetBrightnessResult>;
5
+ resetBrightness(): Promise<void>;
6
+ setBrightness(): Promise<void>;
7
+ }
@@ -0,0 +1,13 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class ScreenBrightnessWeb extends WebPlugin {
3
+ async getBrightness() {
4
+ throw this.unimplemented('Not implemented on web.');
5
+ }
6
+ async resetBrightness() {
7
+ throw this.unimplemented('Not implemented on web.');
8
+ }
9
+ async setBrightness() {
10
+ throw this.unimplemented('Not implemented on web.');
11
+ }
12
+ }
13
+ //# 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;AAO5C,MAAM,OAAO,mBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n GetBrightnessResult,\n ScreenBrightnessPlugin,\n} from './definitions';\n\nexport class ScreenBrightnessWeb\n extends WebPlugin\n implements ScreenBrightnessPlugin\n{\n async getBrightness(): Promise<GetBrightnessResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async resetBrightness(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async setBrightness(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const ScreenBrightness = core.registerPlugin('ScreenBrightness', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.ScreenBrightnessWeb()),
7
+ });
8
+
9
+ class ScreenBrightnessWeb extends core.WebPlugin {
10
+ async getBrightness() {
11
+ throw this.unimplemented('Not implemented on web.');
12
+ }
13
+ async resetBrightness() {
14
+ throw this.unimplemented('Not implemented on web.');
15
+ }
16
+ async setBrightness() {
17
+ throw this.unimplemented('Not implemented on web.');
18
+ }
19
+ }
20
+
21
+ var web = /*#__PURE__*/Object.freeze({
22
+ __proto__: null,
23
+ ScreenBrightnessWeb: ScreenBrightnessWeb
24
+ });
25
+
26
+ exports.ScreenBrightness = ScreenBrightness;
27
+ //# 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 ScreenBrightness = registerPlugin('ScreenBrightness', {\n web: () => import('./web').then(m => new m.ScreenBrightnessWeb()),\n});\nexport * from './definitions';\nexport { ScreenBrightness };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class ScreenBrightnessWeb extends WebPlugin {\n async getBrightness() {\n throw this.unimplemented('Not implemented on web.');\n }\n async resetBrightness() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setBrightness() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,gBAAgB,GAAGA,mBAAc,CAAC,kBAAkB,EAAE;AAC5D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;AACrE,CAAC;;ACFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;AACnD,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,30 @@
1
+ var capacitorScreenBrightness = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const ScreenBrightness = core.registerPlugin('ScreenBrightness', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.ScreenBrightnessWeb()),
6
+ });
7
+
8
+ class ScreenBrightnessWeb extends core.WebPlugin {
9
+ async getBrightness() {
10
+ throw this.unimplemented('Not implemented on web.');
11
+ }
12
+ async resetBrightness() {
13
+ throw this.unimplemented('Not implemented on web.');
14
+ }
15
+ async setBrightness() {
16
+ throw this.unimplemented('Not implemented on web.');
17
+ }
18
+ }
19
+
20
+ var web = /*#__PURE__*/Object.freeze({
21
+ __proto__: null,
22
+ ScreenBrightnessWeb: ScreenBrightnessWeb
23
+ });
24
+
25
+ exports.ScreenBrightness = ScreenBrightness;
26
+
27
+ return exports;
28
+
29
+ })({}, capacitorExports);
30
+ //# 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 ScreenBrightness = registerPlugin('ScreenBrightness', {\n web: () => import('./web').then(m => new m.ScreenBrightnessWeb()),\n});\nexport * from './definitions';\nexport { ScreenBrightness };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class ScreenBrightnessWeb extends WebPlugin {\n async getBrightness() {\n throw this.unimplemented('Not implemented on web.');\n }\n async resetBrightness() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setBrightness() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,gBAAgB,GAAGA,mBAAc,CAAC,kBAAkB,EAAE;IAC5D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;IACrE,CAAC;;ICFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;IACnD,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class SetBrightnessOptions: NSObject {
5
+ let brightness: Double
6
+
7
+ init(_ call: CAPPluginCall) throws {
8
+ self.brightness = try SetBrightnessOptions.getBrightnessFromCall(call)
9
+ }
10
+
11
+ private static func getBrightnessFromCall(_ call: CAPPluginCall) throws -> Double {
12
+ guard let brightness = call.getDouble("brightness") else {
13
+ throw CustomError.brightnessMissing
14
+ }
15
+ if brightness < 0.0 || brightness > 1.0 {
16
+ throw CustomError.brightnessInvalid
17
+ }
18
+ return brightness
19
+ }
20
+ }
@@ -0,0 +1,16 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class GetBrightnessResult: NSObject, Result {
5
+ let brightness: Double
6
+
7
+ init(brightness: Double) {
8
+ self.brightness = brightness
9
+ }
10
+
11
+ @objc public func toJSObject() -> AnyObject {
12
+ var result = JSObject()
13
+ result["brightness"] = brightness
14
+ return result as AnyObject
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ import Foundation
2
+
3
+ public enum CustomError: Error {
4
+ case brightnessInvalid
5
+ case brightnessMissing
6
+ }
7
+
8
+ extension CustomError: LocalizedError {
9
+ public var errorDescription: String? {
10
+ switch self {
11
+ case .brightnessInvalid:
12
+ return NSLocalizedString("brightness must be between 0.0 and 1.0.", comment: "brightnessInvalid")
13
+ case .brightnessMissing:
14
+ return NSLocalizedString("brightness must be provided.", comment: "brightnessMissing")
15
+ }
16
+ }
17
+ }
@@ -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>
@@ -0,0 +1,5 @@
1
+ import Capacitor
2
+
3
+ @objc public protocol Result {
4
+ @objc func toJSObject() -> AnyObject
5
+ }
@@ -0,0 +1,26 @@
1
+ import Foundation
2
+ import UIKit
3
+
4
+ @objc public class ScreenBrightness: NSObject {
5
+ private let plugin: ScreenBrightnessPlugin
6
+
7
+ init(plugin: ScreenBrightnessPlugin) {
8
+ self.plugin = plugin
9
+ }
10
+
11
+ @objc public func getBrightness(completion: @escaping (GetBrightnessResult?, Error?) -> Void) {
12
+ DispatchQueue.main.async {
13
+ let brightness = Double(UIScreen.main.brightness)
14
+ let result = GetBrightnessResult(brightness: brightness)
15
+ completion(result, nil)
16
+ }
17
+ }
18
+
19
+ @objc public func setBrightness(_ options: SetBrightnessOptions, completion: @escaping (Error?) -> Void) {
20
+ let brightness = options.brightness
21
+ DispatchQueue.main.async {
22
+ UIScreen.main.brightness = CGFloat(brightness)
23
+ completion(nil)
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,72 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc(ScreenBrightnessPlugin)
5
+ public class ScreenBrightnessPlugin: CAPPlugin, CAPBridgedPlugin {
6
+ public let identifier = "ScreenBrightnessPlugin"
7
+ public let jsName = "ScreenBrightness"
8
+ public let pluginMethods: [CAPPluginMethod] = [
9
+ CAPPluginMethod(name: "getBrightness", returnType: CAPPluginReturnPromise),
10
+ CAPPluginMethod(name: "resetBrightness", returnType: CAPPluginReturnPromise),
11
+ CAPPluginMethod(name: "setBrightness", returnType: CAPPluginReturnPromise)
12
+ ]
13
+
14
+ public static let tag = "ScreenBrightnessPlugin"
15
+
16
+ private var implementation: ScreenBrightness?
17
+
18
+ override public func load() {
19
+ self.implementation = ScreenBrightness(plugin: self)
20
+ }
21
+
22
+ @objc func getBrightness(_ call: CAPPluginCall) {
23
+ implementation?.getBrightness { result, error in
24
+ if let error = error {
25
+ self.rejectCall(call, error)
26
+ return
27
+ }
28
+ self.resolveCall(call, result)
29
+ }
30
+ }
31
+
32
+ @objc func resetBrightness(_ call: CAPPluginCall) {
33
+ rejectCallAsUnimplemented(call)
34
+ }
35
+
36
+ @objc func setBrightness(_ call: CAPPluginCall) {
37
+ do {
38
+ let options = try SetBrightnessOptions(call)
39
+
40
+ implementation?.setBrightness(options) { error in
41
+ if let error = error {
42
+ self.rejectCall(call, error)
43
+ return
44
+ }
45
+ self.resolveCall(call)
46
+ }
47
+ } catch {
48
+ rejectCall(call, error)
49
+ }
50
+ }
51
+
52
+ private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
53
+ CAPLog.print("[", ScreenBrightnessPlugin.tag, "] ", error)
54
+ call.reject(error.localizedDescription)
55
+ }
56
+
57
+ private func rejectCallAsUnimplemented(_ call: CAPPluginCall) {
58
+ call.unimplemented("This method is not available on this platform.")
59
+ }
60
+
61
+ private func resolveCall(_ call: CAPPluginCall) {
62
+ call.resolve()
63
+ }
64
+
65
+ private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
66
+ if let result = result?.toJSObject() as? JSObject {
67
+ call.resolve(result)
68
+ } else {
69
+ call.resolve()
70
+ }
71
+ }
72
+ }
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@capawesome/capacitor-screen-brightness",
3
+ "version": "0.0.1",
4
+ "description": "Capacitor plugin for reading and controlling the screen brightness.",
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
+ "CapawesomeCapacitorScreenBrightness.podspec",
15
+ "Package.swift"
16
+ ],
17
+ "author": "Robin Genz <mail@robingenz.dev>",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/capawesome-team/capacitor-plugins/issues"
25
+ },
26
+ "funding": [
27
+ {
28
+ "type": "github",
29
+ "url": "https://github.com/sponsors/capawesome-team/"
30
+ },
31
+ {
32
+ "type": "opencollective",
33
+ "url": "https://opencollective.com/capawesome"
34
+ }
35
+ ],
36
+ "homepage": "https://capawesome.io/docs/plugins/screen-brightness/",
37
+ "keywords": [
38
+ "capacitor",
39
+ "plugin",
40
+ "native"
41
+ ],
42
+ "scripts": {
43
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
44
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
45
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
46
+ "verify:web": "npm run build",
47
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
48
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
49
+ "eslint": "eslint . --ext ts",
50
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
51
+ "swiftlint": "node-swiftlint",
52
+ "docgen": "docgen --api ScreenBrightnessPlugin --output-readme README.md --output-json dist/docs.json",
53
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
54
+ "clean": "rimraf ./dist",
55
+ "watch": "tsc --watch",
56
+ "ios:pod:install": "cd ios && pod install --repo-update && cd ..",
57
+ "ios:spm:install": "cd ios && swift package resolve && cd ..",
58
+ "prepublishOnly": "npm run build"
59
+ },
60
+ "devDependencies": {
61
+ "@capacitor/android": "8.0.0",
62
+ "@capacitor/cli": "8.0.0",
63
+ "@capacitor/core": "8.0.0",
64
+ "@capacitor/docgen": "0.3.1",
65
+ "@capacitor/ios": "8.0.0",
66
+ "@ionic/eslint-config": "0.4.0",
67
+ "eslint": "8.57.0",
68
+ "prettier-plugin-java": "2.6.7",
69
+ "rimraf": "6.1.2",
70
+ "rollup": "4.53.3",
71
+ "swiftlint": "2.0.0",
72
+ "typescript": "5.9.3"
73
+ },
74
+ "peerDependencies": {
75
+ "@capacitor/core": ">=8.0.0"
76
+ },
77
+ "eslintConfig": {
78
+ "extends": "@ionic/eslint-config/recommended"
79
+ },
80
+ "capacitor": {
81
+ "ios": {
82
+ "src": "ios"
83
+ },
84
+ "android": {
85
+ "src": "android"
86
+ }
87
+ },
88
+ "publishConfig": {
89
+ "access": "public"
90
+ }
91
+ }