@react-native-ohos/react-native-system-setting 1.7.7-rc.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 (36) hide show
  1. package/API.md +58 -0
  2. package/LICENSE +21 -0
  3. package/LICENSE.md +21 -0
  4. package/RCTSystemSetting.podspec +20 -0
  5. package/README.OpenSource +11 -0
  6. package/README.md +15 -0
  7. package/SystemSetting.d.ts +81 -0
  8. package/SystemSetting.js +348 -0
  9. package/Utils.js +11 -0
  10. package/harmony/react_native_system_setting/BuildProfile.ets +6 -0
  11. package/harmony/react_native_system_setting/Index.ets +27 -0
  12. package/harmony/react_native_system_setting/build-profile.json5 +31 -0
  13. package/harmony/react_native_system_setting/consumer-rules.txt +0 -0
  14. package/harmony/react_native_system_setting/hvigorfile.ts +6 -0
  15. package/harmony/react_native_system_setting/obfuscation-rules.txt +18 -0
  16. package/harmony/react_native_system_setting/oh-package.json5 +11 -0
  17. package/harmony/react_native_system_setting/src/main/cpp/CMakeLists.txt +7 -0
  18. package/harmony/react_native_system_setting/src/main/cpp/RNSystemSettingPackage.h +76 -0
  19. package/harmony/react_native_system_setting/src/main/cpp/ReactNativeSystemSetting.cpp +54 -0
  20. package/harmony/react_native_system_setting/src/main/cpp/ReactNativeSystemSetting.h +21 -0
  21. package/harmony/react_native_system_setting/src/main/ets/Logger.ts +64 -0
  22. package/harmony/react_native_system_setting/src/main/ets/RNSystemSettingPackage.ts +52 -0
  23. package/harmony/react_native_system_setting/src/main/ets/RNSystemSettingTurboModule.ts +362 -0
  24. package/harmony/react_native_system_setting/src/main/ets/generated/components/ts.ts +5 -0
  25. package/harmony/react_native_system_setting/src/main/ets/generated/index.ets +8 -0
  26. package/harmony/react_native_system_setting/src/main/ets/generated/ts.ts +9 -0
  27. package/harmony/react_native_system_setting/src/main/ets/generated/turboModules/ReactNativeSystemSetting.ts +86 -0
  28. package/harmony/react_native_system_setting/src/main/ets/generated/turboModules/ts.ts +8 -0
  29. package/harmony/react_native_system_setting/src/main/module.json5 +9 -0
  30. package/harmony/react_native_system_setting/src/main/resources/base/element/string.json +8 -0
  31. package/harmony/react_native_system_setting/src/main/resources/en_US/element/string.json +8 -0
  32. package/harmony/react_native_system_setting/src/main/resources/zh_CN/element/string.json +8 -0
  33. package/harmony/react_native_system_setting/ts.ts +25 -0
  34. package/harmony/react_native_system_setting.har +0 -0
  35. package/package.json +47 -0
  36. package/src/ReactRNSystemSetting.ts +113 -0
package/API.md ADDED
@@ -0,0 +1,58 @@
1
+ ## API
2
+
3
+ **All are static method, and all GET mothods return a promise**
4
+
5
+ **Maybe [codes](https://github.com/c19354837/react-native-system-setting/blob/master/SystemSetting.js) is best document**
6
+
7
+ > Some APIs are marked with an asterisk at the beginning, and it means you need declare permission for Androidn since V1.5.0, see [Android Permission](https://github.com/c19354837/react-native-system-setting#android-permission)
8
+ >
9
+ > Some APIs which start with `swtich` or containt `bluetooth` are disabled for iOS since V1.7.0, you can [enable it](https://github.com/c19354837/react-native-system-setting/blob/master/iOS.md#ios) in a few steps.
10
+
11
+ method | description
12
+ ------ | -----------
13
+ **Volume**|
14
+ getVolume(type:string) => Promise | Get the system volume. <br><br>`type` must be one of `music`, `call`, `system`, `ring`, `alarm`, `notification`, default is `music`
15
+ setVolume(val:float, config:object) | Set the system volume by specified value, from 0 to 1. 0 for mute, and 1 is max volume.<br><br> `config` can be `{type: 'music', playSound:true, showUI:true}`<br><br> `type` : must be one of `music`, `call`, `system`, `ring`, `alarm`, `notification`, default is `music`.(Android only) <br>`playSound`: Whether to play a sound when changing the volume, default is `false`(Android only)<br>`showUI`: Show a toast containing the current volume, default is `false`(Android & iOS)<br><br> **since 1.2.2**
16
+ addVolumeListener(callback) | Listen the volume changing, and it will return the listener. More info see [the example](https://github.com/c19354837/react-native-system-setting/blob/master/examples/SystemSettingExample/index.js#L42)
17
+ removeVolumeListener(listener)| Remove listener when it no longer needed.
18
+ ---|---
19
+ **Brightness**|
20
+ getBrightness() => Promise | Get the system brightness.
21
+ setBrightness(val:float) => Promise | Set the system brightness by specified value, from 0 to 1. 0 for brightless, and 1 is max.<br><br>Return false if permission deny ( iOS always be true
22
+ \* setBrightnessForce(val:float) => Promise| In Android, if the screen mode is auto, SystemSetting.setBrightness() will not work. You can call this to change the screen mode to MANUAL first. <br><br>Return false if permission deny ( iOS always be true
23
+ \* setAppBrightness(val:float)| For Android, `setBrightness()` or `setBrightnessForce()` will change the system's brightness, while this just changes the app's brightness, and it has no permission trouble.<br><br> For iOS, it's same with `setBrightness()`.
24
+ getAppBrightness() => Promise | Get the app brightness, and it will returns system brightness if you haven't call `setAppBrightness(val)` yet. (iOS allways returns system brightness)
25
+ getScreenMode() => Promise| (Only for Android, iOS will return -1). Get the screen mode, 0 is manual, while 1 is automatic.
26
+ \* setScreenMode(mode:int) => Promise|(Only for Android, iOS cannot change it). Change the screen mode, 0 is manual, while 1 is automatic.<br><br>Return false if permission deny ( iOS always be true
27
+ grantWriteSettingPermission()| open app setting page. It's user-friendly when you need some permission. Normally, you can call it if `setScreenMode()`, `setBrightness()` or `setBrightnessForce()` return false
28
+ \* saveBrightness()|It will save current brightness and screen mode.
29
+ restoreBrightness() => Promise|Restore brightness and screen mode back to saveBrightness(). While iOS only restore the brightness, Android will restore both. <br><br>You should call this before setBrightness() or setBrightnessForce(). <br><br>It will return the saved brightness.
30
+ ---|---
31
+ **Wifi**|
32
+ \* isWifiEnabled() => Promise|Get wifi state, true if wifi is on.
33
+ switchWifi(complete)|It will open **Wifi Setting Page**, and you can change it by yourself. When come back to the app, the `complete` will be call.
34
+ \*\* switchWifiSilence(complete)|It will open wifi if the wifi is off, and close wifi when the wifi is on now. When it has done, the `complete` will be call.<br/>In android, it's done programmatically. <br><br>In iOS, I cannot do that by code for system limiting, so it just calls `switchWifi(complete)`<br><br>You need declare `android.permission.CHANGE_WIFI_STATE` in your AndroidManifest.xml, see [detail](https://github.com/c19354837/react-native-system-setting#android-permission)
35
+ addWifiListener(callback) => Promise| Listen the wifi state changing, and it will return the listener. (Android only)
36
+ ---|---
37
+ **Location**|
38
+ isLocationEnabled() => Promise|Get location state, true if location is on.
39
+ switchLocation(complete)|It will open **System Location Setting Page**, and you can change it by yourself. When come back to the app, the `complete` will be call.
40
+ addLocationListener(callback) => Promise| Listen the location state changing, and it will return the listener. (Android only)
41
+ getLocationMode() => Promise| Get current location mode code: `0` - 'off', `1` - 'gps', `2` - 'network', `3` - 'gps & network'. (Android only)
42
+ addLocationModeListener(callback) => Promise| Listen the location mode changing, and it will return the listener. (Android only)
43
+ ---|---
44
+ **Bluetooth**|
45
+ \* isBluetoothEnabled() => Promise|Get bluetooth state, true if bluetooth is on.
46
+ switchBluetooth(complete)|It will open **System Bluetooth Setting Page**, and you can change it by yourself. When come back to the app, the `complete` will be call.
47
+ \*\* switchBluetoothSilence(complete)|It will open bluetooth if the bluetooth is off, and close bluetooth when the bluetooth is on now. When it has done, the `complete` will be call.<br/>In android, it's done programmatically. <br><br>In iOS, I cannot do that by code for system limiting, so it just calls `switchBluetooth(complete)`<br><br>You need declare `android.permission.BLUETOOTH_ADMIN` in your AndroidManifest.xml, see [detail](https://github.com/c19354837/react-native-system-setting#android-permission)
48
+ addBluetoothListener(callback) => Promise| Listen the bluetooth state changing, and it will return the listener.
49
+ ---|---
50
+ **Airplane**|
51
+ isAirplaneEnabled() => Promise|Get airplane state, true if airplane is on. <br><br>It will always return `true` for iOS if your device has no SIM card, see [detail](https://github.com/c19354837/react-native-system-setting/issues/37)
52
+ switchAirplane(complete)|It will open **System Setting Page**, and you can change it by yourself. When come back to the app, the `complete` will be call.
53
+ addAirplaneListener(callback) => Promise| Listen the airplane state changing, and it will return the listener. (Android only)
54
+ ---|---
55
+ **Other**|
56
+ setAppStore(isAppStore:bool)| `true` means that you'll submit your app to App Store. In order to throught the App Store review, it has some side effects, see [Private API](https://github.com/c19354837/react-native-system-setting/blob/master/iOS.md#private-api).<br><br>`false` means that your app will not upload to App Store, and you can use any APIs at will.
57
+ removeListener(listener)| you can use this to remove the listener which return by `add*Listener(callback)`
58
+ openAppSystemSettings()| open app's setting page
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ninty
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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ninty
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.
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+ pjson = JSON.parse(File.read('package.json'))
3
+
4
+ Pod::Spec.new do |s|
5
+
6
+ s.name = "RCTSystemSetting"
7
+ s.version = pjson["version"]
8
+ s.homepage = pjson["homepage"]
9
+ s.summary = pjson["description"]
10
+ s.license = pjson["license"]
11
+ s.author = { "Ninty" => "c19354837@hotmail.com" }
12
+
13
+ s.ios.deployment_target = '7.0'
14
+
15
+ s.source = { :git => "https://github.com/c19354837/react-native-system-setting", :tag => "v#{s.version}" }
16
+ s.source_files = 'ios/*.{h,m}'
17
+ s.preserve_paths = "**/*.js"
18
+
19
+ s.dependency 'React'
20
+ end
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "Name": "react-native-system-setting",
4
+ "License": "MIT",
5
+ "License File": "https://github.com/c19354837/react-native-system-setting/blob/master/LICENSE.md",
6
+ "Version Number": "1.7.6",
7
+ "Owner" : "xiafeng@huawei.com",
8
+ "Upstream URL": "https://github.com/c19354837/react-native-system-setting",
9
+ "Description": "provide some system setting APIs. Volume, brightness, wifi, location, bluetooth, airplane..."
10
+ }
11
+ ]
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+
2
+ # @react-native-ohos/react-native-system-setting
3
+
4
+ 本项目基于 [react-native-system-setting](https://github.com/c19354837/react-native-system-setting)
5
+
6
+ ## 文档地址 / Documentation URL
7
+
8
+ [中文 / Chinese](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-system-setting.md)
9
+
10
+ [英文 / English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-system-setting.md)
11
+
12
+ ## 请悉知 / Acknowledgements
13
+
14
+ 本项目基于 [The MIT License (MIT)](https://github.com/c19354837/react-native-system-setting/blob/master/LICENSE.md) ,请自由地享受和参与开源。
15
+
@@ -0,0 +1,81 @@
1
+ export {};
2
+
3
+ export interface EmitterSubscription {
4
+ remove: () => void;
5
+ }
6
+
7
+ type CompleteFunc = () => void
8
+
9
+ type VolumeType =
10
+ | "call"
11
+ | "system"
12
+ | "ring"
13
+ | "music"
14
+ | "alarm"
15
+ | "notification";
16
+
17
+ interface VolumeConfig {
18
+ type?: VolumeType;
19
+ playSound?: boolean;
20
+ showUI?: boolean;
21
+ }
22
+
23
+ interface VolumeData {
24
+ value: number;
25
+ call?: number;
26
+ system?: number;
27
+ ring?: number;
28
+ music?: number;
29
+ alarm?: number;
30
+ notification?: number;
31
+ }
32
+
33
+ interface SystemSetting {
34
+ getBrightness: () => Promise<number>;
35
+ setBrightness: (val: number) => Promise<boolean>;
36
+ setBrightnessForce: (val: number) => Promise<boolean>;
37
+ getAppBrightness: () => Promise<number>;
38
+ setAppBrightness: (val: number) => Promise<true>;
39
+ grantWriteSettingPremission: () => void;
40
+ getScreenMode: () => Promise<number>;
41
+ setScreenMode: (val: number) => Promise<boolean>;
42
+ saveBrightness: () => Promise<void>;
43
+ restoreBrightness: () => number;
44
+ getVolume: (type?: VolumeType) => Promise<number>;
45
+ setVolume: (value: number, config?: VolumeConfig | VolumeType) => void;
46
+ addVolumeListener: (
47
+ callback: (volumeData: VolumeData) => void
48
+ ) => EmitterSubscription;
49
+ removeVolumeListener: (listener?: EmitterSubscription) => void;
50
+ isWifiEnabled: () => Promise<boolean>;
51
+ switchWifiSilence: (onComplete?: CompleteFunc) => void;
52
+ switchWifi: (onComplete?: CompleteFunc) => void;
53
+ isLocationEnabled: () => Promise<boolean>;
54
+ getLocationMode: () => Promise<number>;
55
+ switchLocation: (onComplete?: CompleteFunc) => void;
56
+ isBluetoothEnabled: () => Promise<boolean>;
57
+ switchBluetooth: (onComplete?: CompleteFunc) => void;
58
+ switchBluetoothSilence: (onComplete?: CompleteFunc) => void;
59
+ isAirplaneEnabled: () => Promise<boolean>;
60
+ switchAirplane: (onComplete?: CompleteFunc) => void;
61
+ openAppSystemSettings: () => Promise<void>;
62
+ addBluetoothListener: (
63
+ callback: (bluetoothEnabled: boolean) => void
64
+ ) => Promise<EmitterSubscription>;
65
+ addWifiListener: (
66
+ callback: (wifiEnabled: boolean) => void
67
+ ) => Promise<EmitterSubscription | null>;
68
+ addLocationListener: (
69
+ callback: (locationEnabled: boolean) => void
70
+ ) => Promise<EmitterSubscription | null>;
71
+ addLocationModeListener: (
72
+ callback: (locationMode: number) => void
73
+ ) => Promise<EmitterSubscription | null>;
74
+ addAirplaneListener: (
75
+ callback: (airplaneModeEnabled: boolean) => void
76
+ ) => Promise<EmitterSubscription | null>;
77
+ removeListener: (listener?: EmitterSubscription) => void;
78
+ }
79
+
80
+ declare const systemSetting: SystemSetting;
81
+ export default systemSetting;
@@ -0,0 +1,348 @@
1
+ import { NativeModules, NativeEventEmitter, Linking, Platform, TurboModuleRegistry, DeviceEventEmitter } from 'react-native'
2
+
3
+ import Utils from './Utils'
4
+
5
+ const SystemSettingNative = TurboModuleRegistry ? TurboModuleRegistry.get('ReactNativeSystemSetting') : NativeModules.SystemSetting
6
+
7
+ const SCREEN_BRIGHTNESS_MODE_UNKNOW = -1
8
+ const SCREEN_BRIGHTNESS_MODE_MANUAL = 0
9
+ const SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1
10
+
11
+ const isHarmony = Platform.OS === 'harmony'
12
+
13
+ const eventEmitter = new NativeEventEmitter(SystemSettingNative)
14
+
15
+ export default class SystemSetting {
16
+ static saveBrightnessVal = -1
17
+ static saveScreenModeVal = SCREEN_BRIGHTNESS_MODE_AUTOMATIC
18
+
19
+ /**
20
+ * @deprecated
21
+ */
22
+ static setAppStore() {
23
+ console.warn("You don't need call setAppStore() anymore since V1.7.0")
24
+ }
25
+
26
+ static async getBrightness() {
27
+ if (!isHarmony) {
28
+ return await SystemSettingNative.getBrightness()
29
+ } else {
30
+ return await SystemSetting.getAppBrightness()
31
+ }
32
+
33
+ }
34
+
35
+ static async setBrightness(val) {
36
+ try {
37
+ if (!isHarmony) {
38
+ await SystemSettingNative.setBrightness(val)
39
+ return true
40
+ } else {
41
+ await SystemSetting.setAppBrightness(val)
42
+ }
43
+
44
+ } catch (e) {
45
+ return false
46
+ }
47
+ }
48
+
49
+ static async setBrightnessForce(val) {
50
+ if (Utils.isAndroid) {
51
+ const success = await SystemSetting.setScreenMode(SCREEN_BRIGHTNESS_MODE_MANUAL)
52
+ if (!success) {
53
+ return false
54
+ }
55
+ }
56
+ return await SystemSetting.setBrightness(val)
57
+ }
58
+
59
+ static setAppBrightness(val) {
60
+ if (Utils.isAndroid || isHarmony) {
61
+ SystemSettingNative.setAppBrightness(val)
62
+ } else {
63
+ SystemSetting.setBrightness(val)
64
+ }
65
+ return Promise.resolve(true)
66
+ }
67
+
68
+ static async getAppBrightness() {
69
+ if (Utils.isAndroid || isHarmony) {
70
+ return SystemSettingNative.getAppBrightness()
71
+ } else {
72
+ return SystemSetting.getBrightness()
73
+ }
74
+ }
75
+
76
+ /**
77
+ * @deprecated use grantWriteSettingPermission instead
78
+ */
79
+ static grantWriteSettingPremission() {
80
+ __DEV__ && console.warn('grantWriteSettingPremission has been renamed to grantWriteSettingPermission, see https://github.com/c19354837/react-native-system-setting/pull/98')
81
+ SystemSetting.grantWriteSettingPermission()
82
+ }
83
+
84
+ /**
85
+ * since v1.7.4
86
+ */
87
+ static grantWriteSettingPermission() {
88
+ if (Utils.isAndroid) {
89
+ SystemSettingNative.openWriteSetting()
90
+ }
91
+ }
92
+
93
+ static async getScreenMode() {
94
+ if (Utils.isAndroid) {
95
+ return await SystemSettingNative.getScreenMode()
96
+ }
97
+ return -1 // cannot get iOS screen mode
98
+ }
99
+
100
+ static async setScreenMode(val) {
101
+ if (Utils.isAndroid || isHarmony) {
102
+ try {
103
+ await SystemSettingNative.setScreenMode(val)
104
+ } catch (e) {
105
+ return false
106
+ }
107
+ }
108
+ return true
109
+ }
110
+
111
+ static async saveBrightness() {
112
+ if (!isHarmony) {
113
+ SystemSetting.saveBrightnessVal = await SystemSetting.getBrightness()
114
+ SystemSetting.saveScreenModeVal = await SystemSetting.getScreenMode()
115
+ } else {
116
+ SystemSetting.saveBrightnessVal = await SystemSetting.getAppBrightness()
117
+ }
118
+ }
119
+
120
+ static restoreBrightness() {
121
+ if (SystemSetting.saveBrightnessVal == -1) {
122
+ console.warn('you should call saveBrightness() at least once')
123
+ } else {
124
+ if (!isHarmony) {
125
+ SystemSetting.setBrightness(SystemSetting.saveBrightnessVal)
126
+ SystemSetting.setScreenMode(SystemSetting.saveScreenModeVal)
127
+ } else {
128
+ SystemSettingNative.setAppBrightness(SystemSetting.saveBrightnessVal)
129
+ }
130
+ }
131
+ return SystemSetting.saveBrightnessVal
132
+ }
133
+
134
+ static async getVolume(type = 'music') {
135
+ if (!isHarmony) {
136
+ return await SystemSettingNative.getVolume(type)
137
+ } else {
138
+ const vol = await SystemSettingNative.getVolume(type)
139
+ if (Object.prototype.toString.call(vol) === '[object Number]') {
140
+ return Math.round(vol / 15 * 100) / 100
141
+ }
142
+ }
143
+ }
144
+
145
+ static setVolume(val, config = {}) {
146
+ if (typeof (config) === 'string') {
147
+ console.log('setVolume(val, type) is deprecated since 1.2.2, use setVolume(val, config) instead')
148
+ config = { type: config }
149
+ }
150
+ config = Object.assign({
151
+ playSound: false,
152
+ type: 'music',
153
+ showUI: false
154
+ }, config)
155
+ SystemSettingNative.setVolume(val, config)
156
+ }
157
+
158
+ static addVolumeListener(callback) {
159
+ if (!isHarmony) {
160
+ return eventEmitter.addListener('EventVolume', callback)
161
+ } else {
162
+ SystemSettingNative.addVolumeListener()
163
+ const obj = DeviceEventEmitter.addListener('EventVolume', e => {
164
+ callback(e)
165
+ })
166
+ obj.type = 'volume'
167
+ return obj
168
+ }
169
+ }
170
+
171
+ static removeVolumeListener(listener) {
172
+
173
+ listener && listener.remove()
174
+ }
175
+
176
+ static async isWifiEnabled() {
177
+ const result = await SystemSettingNative.isWifiEnabled()
178
+ if (!isHarmony) {
179
+ return (result) > 0
180
+ } else {
181
+ return result
182
+ }
183
+
184
+ }
185
+
186
+ static switchWifiSilence(complete) {
187
+ if (Utils.isAndroid) {
188
+ SystemSetting.listenEvent(complete)
189
+ SystemSettingNative.switchWifiSilence()
190
+ } else {
191
+ SystemSetting.switchWifi(complete)
192
+ }
193
+ }
194
+
195
+ static switchWifi(complete) {
196
+ if (!isHarmony) {
197
+ SystemSetting.listenEvent(complete)
198
+ SystemSettingNative.switchWifi()
199
+ } else {
200
+ SystemSettingNative.switchWifi(complete)
201
+ }
202
+ }
203
+
204
+ static async isLocationEnabled() {
205
+ return await SystemSettingNative.isLocationEnabled()
206
+ }
207
+
208
+ static async getLocationMode() {
209
+ if (Utils.isAndroid) {
210
+ return await SystemSettingNative.getLocationMode()
211
+ } else {
212
+ return await SystemSetting.isLocationEnabled() ? 1 : 0
213
+ }
214
+ }
215
+
216
+ static switchLocation(complete) {
217
+ if (!isHarmony) {
218
+ SystemSetting.listenEvent(complete)
219
+ SystemSettingNative.switchLocation()
220
+ } else {
221
+ SystemSettingNative.switchLocation(complete)
222
+ }
223
+ }
224
+
225
+ static async isBluetoothEnabled() {
226
+ return await SystemSettingNative.isBluetoothEnabled()
227
+ }
228
+
229
+ static switchBluetooth(complete) {
230
+ if (!isHarmony) {
231
+ SystemSetting.listenEvent(complete)
232
+ SystemSettingNative.switchBluetooth()
233
+ } else {
234
+ SystemSettingNative.switchBluetooth(complete)
235
+ }
236
+
237
+ }
238
+
239
+ static switchBluetoothSilence(complete) {
240
+ if (Utils.isAndroid) {
241
+ SystemSetting.listenEvent(complete)
242
+ SystemSettingNative.switchBluetoothSilence()
243
+ } else if (isHarmony) {
244
+ SystemSettingNative.switchBluetoothSilence(complete)
245
+ } else {
246
+ SystemSettingNative.switchBluetooth(complete)
247
+ }
248
+ }
249
+
250
+ static async isAirplaneEnabled() {
251
+ return await SystemSettingNative.isAirplaneEnabled()
252
+ }
253
+
254
+ static switchAirplane(complete) {
255
+ SystemSetting.listenEvent(complete)
256
+ SystemSettingNative.switchAirplane()
257
+ }
258
+
259
+ static async openAppSystemSettings() {
260
+ switch (Platform.OS) {
261
+ case 'ios': {
262
+ const settingsLink = 'app-settings:';
263
+ const supported = await Linking.canOpenURL(settingsLink)
264
+ if (supported) await Linking.openURL(settingsLink);
265
+ break;
266
+ }
267
+ case 'android':
268
+ await SystemSettingNative.openAppSystemSettings()
269
+ break;
270
+ case 'harmony':
271
+ SystemSettingNative.openAppSystemSettings()
272
+ break;
273
+ default:
274
+ throw new Error('unknown platform')
275
+ break;
276
+ }
277
+ }
278
+
279
+ static async addBluetoothListener(callback) {
280
+ if (!isHarmony) {
281
+ return await SystemSetting._addListener(false, 'bluetooth', 'EventBluetoothChange', callback)
282
+ } else {
283
+ SystemSettingNative.addBluetoothListener()
284
+ const obj = DeviceEventEmitter.addListener('EventBluetooth', e => {
285
+ callback(e)
286
+ })
287
+ obj.type = 'bluetooth'
288
+ return obj
289
+ }
290
+ }
291
+
292
+ static async addWifiListener(callback) {
293
+ return await SystemSetting._addListener(true, 'wifi', 'EventWifiChange', callback)
294
+ }
295
+
296
+ static async addLocationListener(callback) {
297
+ return await SystemSetting._addListener(true, 'location', 'EventLocationChange', callback)
298
+ }
299
+
300
+ static async addLocationModeListener(callback) {
301
+ return await SystemSetting._addListener(true, 'locationMode', 'EventLocationModeChange', callback)
302
+ }
303
+
304
+ static async addAirplaneListener(callback) {
305
+ return await SystemSetting._addListener(true, 'airplane', 'EventAirplaneChange', callback)
306
+ }
307
+
308
+ static async _addListener(androidOnly, type, eventName, callback) {
309
+ if (!androidOnly || Utils.isAndroid) {
310
+ const result = await SystemSetting._activeListener(type)
311
+ if (result) {
312
+ return eventEmitter.addListener(eventName, callback)
313
+ }
314
+ }
315
+ return null
316
+ }
317
+
318
+ static async _activeListener(name) {
319
+ try {
320
+ await SystemSettingNative.activeListener(name)
321
+ } catch (e) {
322
+ console.warn(e.message)
323
+ return false;
324
+ }
325
+ return true;
326
+ }
327
+
328
+ static removeListener(listener) {
329
+ if (!isHarmony) {
330
+ listener && listener.remove()
331
+ } else {
332
+ if (listener.type === 'bluetooth') {
333
+ SystemSettingNative.removeListener('bluetooth')
334
+ listener && listener.remove()
335
+ }
336
+ }
337
+
338
+ }
339
+
340
+ static listenEvent(complete) {
341
+ if (!complete) return
342
+
343
+ const listener = eventEmitter.addListener('EventEnterForeground', () => {
344
+ listener.remove()
345
+ complete()
346
+ })
347
+ }
348
+ }
package/Utils.js ADDED
@@ -0,0 +1,11 @@
1
+ /* @flow */
2
+
3
+ import {
4
+ Platform
5
+ } from 'react-native';
6
+
7
+ export default class Utils {
8
+ static isAndroid = Platform.OS === 'android'
9
+
10
+ static isIOS = Platform.OS === 'ios'
11
+ }
@@ -0,0 +1,6 @@
1
+ export default class BuildProfile {
2
+ static readonly HAR_VERSION = '1.0.0';
3
+ static readonly BUILD_MODE_NAME = 'debug';
4
+ static readonly DEBUG = true;
5
+ static readonly TARGET_NAME = 'default';
6
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export * from './ts';
26
+ export * from "./src/main/ets/RNSystemSettingPackage";
27
+ export * from "./src/main/ets/RNSystemSettingTurboModule";
@@ -0,0 +1,31 @@
1
+ {
2
+ "apiType": "stageMode",
3
+ "buildOption": {
4
+ },
5
+ "buildOptionSet": [
6
+ {
7
+ "name": "release",
8
+ "arkOptions": {
9
+ "obfuscation": {
10
+ "ruleOptions": {
11
+ "enable": true,
12
+ "files": [
13
+ "./obfuscation-rules.txt"
14
+ ]
15
+ },
16
+ "consumerFiles": [
17
+ "./consumer-rules.txt"
18
+ ]
19
+ }
20
+ },
21
+ },
22
+ ],
23
+ "targets": [
24
+ {
25
+ "name": "default"
26
+ },
27
+ {
28
+ "name": "ohosTest"
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,6 @@
1
+ import { harTasks } from '@ohos/hvigor-ohos-plugin';
2
+
3
+ export default {
4
+ system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
6
+ }