From d63dbda7d9cedbb8b0ee4953a8873edf29e49986 Mon Sep 17 00:00:00 2001 From: Gilles StCyr Date: Fri, 7 May 2021 16:45:22 -0600 Subject: [PATCH 1/5] Update SystemSetting.js - fix the 'complete' callback on swith(Wifi|Bluetooth)Silence methods --- SystemSetting.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/SystemSetting.js b/SystemSetting.js index d6cdd11..5d5ce21 100644 --- a/SystemSetting.js +++ b/SystemSetting.js @@ -141,9 +141,12 @@ export default class SystemSetting { return (result) > 0 } - static switchWifiSilence(complete) { + static async switchWifiSilence(complete) { if (Utils.isAndroid) { - SystemSetting.listenEvent(complete) + let listener = await SystemSetting.addWifiListener(() => { + SystemSetting.removeListener(listener); + complete(); + }); SystemSettingNative.switchWifiSilence() } else { SystemSetting.switchWifi(complete) @@ -181,9 +184,12 @@ export default class SystemSetting { SystemSettingNative.switchBluetooth() } - static switchBluetoothSilence(complete) { + static async switchBluetoothSilence(complete) { if (Utils.isAndroid) { - SystemSetting.listenEvent(complete) + let listener = await SystemSetting.addBluetoothListener(() => { + SystemSetting.removeListener(listener); + complete(); + }) SystemSettingNative.switchBluetoothSilence() } else { SystemSettingNative.switchBluetooth(complete) @@ -268,4 +274,4 @@ export default class SystemSetting { complete() }) } -} \ No newline at end of file +} From d683cd64cc2c5f55f11ff1231ff455001580e159 Mon Sep 17 00:00:00 2001 From: Gilles StCyr Date: Tue, 7 Jun 2022 10:16:14 -0600 Subject: [PATCH 2/5] Update SystemSetting.java fix get app brightness hanging --- .../src/main/java/com/ninty/system/setting/SystemSetting.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/ninty/system/setting/SystemSetting.java b/android/src/main/java/com/ninty/system/setting/SystemSetting.java index dedd524..844fdab 100644 --- a/android/src/main/java/com/ninty/system/setting/SystemSetting.java +++ b/android/src/main/java/com/ninty/system/setting/SystemSetting.java @@ -246,6 +246,7 @@ public void run() { public void getAppBrightness(Promise promise) { final Activity curActivity = getCurrentActivity(); if (curActivity == null) { + promise.reject("-1", "cannot get app brightness: current activity is null"); return; } try { From 8324b1ea710fb1d276ead09ee8b29ad810c5dee0 Mon Sep 17 00:00:00 2001 From: Gilles StCyr Date: Tue, 7 Jun 2022 10:18:06 -0600 Subject: [PATCH 3/5] Update SystemSetting.java - listener stubs for new RN versions --- .../java/com/ninty/system/setting/SystemSetting.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/android/src/main/java/com/ninty/system/setting/SystemSetting.java b/android/src/main/java/com/ninty/system/setting/SystemSetting.java index 844fdab..b119117 100644 --- a/android/src/main/java/com/ninty/system/setting/SystemSetting.java +++ b/android/src/main/java/com/ninty/system/setting/SystemSetting.java @@ -598,4 +598,14 @@ public void onReceive(Context context, Intent intent) { } } } + + @ReactMethod + public void addListener(String eventName) { + // Keep: Required for RN built in Event Emitter Calls. + } + + @ReactMethod + public void removeListeners(Integer count) { + // Keep: Required for RN built in Event Emitter Calls. + } } From 4d6cd2bfc5618b587974325f84bfbc2a0f7b996b Mon Sep 17 00:00:00 2001 From: Gilles StCyr Date: Tue, 7 Jun 2022 10:19:03 -0600 Subject: [PATCH 4/5] Update RTCSystemSetting.m - listener stubs for ios --- ios/RTCSystemSetting.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ios/RTCSystemSetting.m b/ios/RTCSystemSetting.m index 3f2e874..525922a 100644 --- a/ios/RTCSystemSetting.m +++ b/ios/RTCSystemSetting.m @@ -165,6 +165,14 @@ +(BOOL)requiresMainQueueSetup{ } } +RCT_EXPORT_METHOD(addListener : (NSString *)eventName) { + // Keep: Required for RN built in Event Emitter Calls. +} + +RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) { + // Keep: Required for RN built in Event Emitter Calls. +} + -(void)showVolumeUI:(BOOL)flag{ if(flag && [volumeView superview]){ [volumeView removeFromSuperview]; From 9f1d84f085c8ec680fac506c868f57c2408f0b59 Mon Sep 17 00:00:00 2001 From: Gilles StCyr Date: Tue, 7 Jun 2022 10:22:40 -0600 Subject: [PATCH 5/5] Update package.json - update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 80bb4b1..1f33b91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-system-setting", - "version": "1.7.6", + "version": "1.7.7", "description": "provide some system setting APIs. Volume, brightness, wifi, location, bluetooth, airplane...", "main": "SystemSetting.js", "types": "SystemSetting.d.ts",