@react-native-ohos/react-native-system-setting 1.7.7-rc.1 → 1.8.0-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 (93) hide show
  1. package/API.md +57 -57
  2. package/LICENSE.md +21 -21
  3. package/RCTSystemSetting.podspec +20 -20
  4. package/README.OpenSource +10 -10
  5. package/README.md +15 -15
  6. package/SystemSetting.d.ts +81 -81
  7. package/SystemSetting.js +347 -347
  8. package/Utils.js +11 -11
  9. package/harmony/react_native_system_setting/BuildProfile.ets +15 -4
  10. package/harmony/react_native_system_setting/Index.ets +27 -27
  11. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/.ts_checker_cache +3265 -0
  12. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/.tsbuildinfo +1 -0
  13. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/.tsbuildinfo.linter +1 -0
  14. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/compileInfo.json +1 -0
  15. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/Index.ets-2fddbfa85232e8c40c1136f190876ccc.msgpack +0 -0
  16. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/Logger.ts-8e34cf7fa6426785b8ad5585899ed6b1.msgpack +0 -0
  17. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/RNSystemSettingPackage.ts-30c76849c83af152019669e58dba3868.msgpack +0 -0
  18. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/RNSystemSettingTurboModule.ts-7a1b45b73925f478da2aa3d03fb615f7.msgpack +1139 -1
  19. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/ReactNativeSystemSetting.ts-8877d7ca6db401765ea2eea734a446fa.msgpack +0 -0
  20. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/index.ets-bee9eb0a0c5d135a91e741ea4b9a65c8.msgpack +0 -0
  21. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/ts.ts-3cbe49cf5f58ba5b139d5dfafe202b93.msgpack +0 -0
  22. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/ts.ts-4dbe8955872e62aac8fffa74b038b1db.msgpack +0 -0
  23. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/ts.ts-9f780c638fd01ebe14b69a7714c4c148.msgpack +0 -0
  24. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/modules/ts.ts-b18f20d502073e5ca84a0eac4a01ef96.msgpack +0 -0
  25. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/other/pkgName2SourceRoots.msgpack +1 -0
  26. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/compiler.cache/plugins/plugins.msgpack +0 -0
  27. package/harmony/react_native_system_setting/build/default/cache/default/default@HarCompileArkTS/esmodule/debug/dep_info.json +1 -0
  28. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/BuildProfile.ets +17 -0
  29. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/Index.ets +27 -0
  30. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/ResourceTable.txt +1 -0
  31. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/build-profile.json5 +31 -0
  32. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/consumer-rules.txt +0 -0
  33. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/hvigorfile.ts +6 -0
  34. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/obfuscation-rules.txt +18 -0
  35. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/oh-package-lock.json5 +19 -0
  36. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/oh-package.json5 +1 -0
  37. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/cpp/CMakeLists.txt +7 -0
  38. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/cpp/RNSystemSettingPackage.h +76 -0
  39. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/cpp/ReactNativeSystemSetting.cpp +54 -0
  40. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/cpp/ReactNativeSystemSetting.h +21 -0
  41. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/Logger.ts +64 -0
  42. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/RNSystemSettingPackage.ts +52 -0
  43. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/RNSystemSettingTurboModule.ts +362 -0
  44. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/generated/components/ts.ts +5 -0
  45. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/generated/index.ets +8 -0
  46. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/generated/ts.ts +9 -0
  47. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/generated/turboModules/ReactNativeSystemSetting.ts +86 -0
  48. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/ets/generated/turboModules/ts.ts +8 -0
  49. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/module.json +28 -0
  50. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/resources/base/element/string.json +8 -0
  51. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/resources/en_US/element/string.json +8 -0
  52. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/src/main/resources/zh_CN/element/string.json +8 -0
  53. package/harmony/react_native_system_setting/build/default/cache/default/default@PackageHar/ts.ts +25 -0
  54. package/harmony/react_native_system_setting/build/default/generated/pm/default/oh-package.json5 +1 -0
  55. package/harmony/react_native_system_setting/build/default/generated/r/default/ResourceTable.h +24 -0
  56. package/harmony/react_native_system_setting/build/default/intermediates/loader/default/loader.json +30 -0
  57. package/harmony/react_native_system_setting/build/default/intermediates/merge_profile/default/module.json +25 -0
  58. package/harmony/react_native_system_setting/build/default/intermediates/patch/default/base_native_libs.json +1 -0
  59. package/harmony/react_native_system_setting/build/default/intermediates/process_profile/default/module.json +28 -0
  60. package/harmony/react_native_system_setting/build/default/intermediates/res/default/ResourceTable.txt +1 -0
  61. package/harmony/react_native_system_setting/build/default/intermediates/res/default/ark_module.json +1 -0
  62. package/harmony/react_native_system_setting/build/default/intermediates/res/default/ids_map/id_defined.json +7 -0
  63. package/harmony/react_native_system_setting/build/default/intermediates/res/default/module.json +26 -0
  64. package/harmony/react_native_system_setting/build/default/intermediates/res/default/opt-compression.json +1 -0
  65. package/harmony/react_native_system_setting/build/default/intermediates/res/default/resConfig.json +1 -0
  66. package/harmony/react_native_system_setting/build/default/intermediates/res/default/resources/rawfile/rnoh.profdata +0 -0
  67. package/harmony/react_native_system_setting/build/default/intermediates/res/default/resources.index +0 -0
  68. package/harmony/react_native_system_setting/build/default/outputs/default/react_native_system_setting.har +0 -0
  69. package/harmony/react_native_system_setting/build-profile.json5 +31 -31
  70. package/harmony/react_native_system_setting/hvigorfile.ts +6 -6
  71. package/harmony/react_native_system_setting/obfuscation-rules.txt +17 -17
  72. package/harmony/react_native_system_setting/oh-package-lock.json5 +19 -0
  73. package/harmony/react_native_system_setting/oh-package.json5 +10 -10
  74. package/harmony/react_native_system_setting/src/main/cpp/RNSystemSettingPackage.h +76 -76
  75. package/harmony/react_native_system_setting/src/main/cpp/ReactNativeSystemSetting.cpp +54 -54
  76. package/harmony/react_native_system_setting/src/main/cpp/ReactNativeSystemSetting.h +21 -21
  77. package/harmony/react_native_system_setting/src/main/ets/Logger.ts +63 -63
  78. package/harmony/react_native_system_setting/src/main/ets/RNSystemSettingPackage.ts +51 -51
  79. package/harmony/react_native_system_setting/src/main/ets/RNSystemSettingTurboModule.ts +361 -361
  80. package/harmony/react_native_system_setting/src/main/ets/generated/components/ts.ts +5 -5
  81. package/harmony/react_native_system_setting/src/main/ets/generated/index.ets +8 -8
  82. package/harmony/react_native_system_setting/src/main/ets/generated/ts.ts +9 -9
  83. package/harmony/react_native_system_setting/src/main/ets/generated/turboModules/ReactNativeSystemSetting.ts +86 -86
  84. package/harmony/react_native_system_setting/src/main/ets/generated/turboModules/ts.ts +8 -8
  85. package/harmony/react_native_system_setting/src/main/module.json5 +9 -9
  86. package/harmony/react_native_system_setting/src/main/resources/base/element/string.json +8 -8
  87. package/harmony/react_native_system_setting/src/main/resources/en_US/element/string.json +8 -8
  88. package/harmony/react_native_system_setting/src/main/resources/zh_CN/element/string.json +8 -8
  89. package/harmony/react_native_system_setting/ts.ts +24 -24
  90. package/harmony/react_native_system_setting.har +0 -0
  91. package/package.json +46 -46
  92. package/src/ReactRNSystemSetting.ts +112 -112
  93. package/LICENSE +0 -21
package/SystemSetting.js CHANGED
@@ -1,348 +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
- }
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
348
  }