mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-07-15 08:52:59 +01:00
Addressing PR comments
Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com>
This commit is contained in:
@@ -55,13 +55,13 @@ class WifiSsidModule : Module() {
|
||||
* location-sensitive).
|
||||
*/
|
||||
private fun readWifi(): Pair<String?, Boolean> {
|
||||
val appContext = context.applicationContext
|
||||
val androidContext = context.applicationContext
|
||||
var connectedToWifi = false
|
||||
var ssid: String? = null
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
try {
|
||||
val cm = appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
|
||||
val cm = androidContext.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
|
||||
val caps = cm?.let { manager ->
|
||||
manager.activeNetwork?.let { net -> manager.getNetworkCapabilities(net) }
|
||||
}
|
||||
@@ -72,11 +72,23 @@ class WifiSsidModule : Module() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error reading Wi-Fi via ConnectivityManager", e)
|
||||
}
|
||||
} else {
|
||||
// Pre-Q (API 26–28): NetworkCapabilities/transportInfo aren't available, so
|
||||
// detect a Wi-Fi connection via the legacy active-network API. Without this,
|
||||
// connectedToWifi stays false on Android 8/9 even when connected, so the
|
||||
// "connected but SSID hidden" state never surfaces there.
|
||||
try {
|
||||
val cm = androidContext.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
|
||||
@Suppress("DEPRECATION")
|
||||
connectedToWifi = cm?.activeNetworkInfo?.type == ConnectivityManager.TYPE_WIFI
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error reading Wi-Fi via ConnectivityManager (legacy)", e)
|
||||
}
|
||||
}
|
||||
|
||||
if (ssid == null && hasFineLocationPermission()) {
|
||||
try {
|
||||
val wm = appContext.getSystemService(Context.WIFI_SERVICE) as? WifiManager
|
||||
val wm = androidContext.getSystemService(Context.WIFI_SERVICE) as? WifiManager
|
||||
@Suppress("DEPRECATION")
|
||||
ssid = wm?.connectionInfo?.ssid?.sanitize()
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -41,6 +41,10 @@ public class WifiSsidModule: Module {
|
||||
}
|
||||
pathMonitor.start(queue: monitorQueue)
|
||||
}
|
||||
|
||||
deinit {
|
||||
pathMonitor.cancel()
|
||||
}
|
||||
#endif
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
@@ -102,16 +103,25 @@ export function ServerUrlProvider({ children }: Props): React.ReactElement {
|
||||
};
|
||||
}, [ssid, permissionStatus, evaluateAndSwitchUrl]);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
effectiveServerUrl,
|
||||
isUsingLocalUrl,
|
||||
currentSSID: ssid,
|
||||
connectedToWifi,
|
||||
refreshUrlState,
|
||||
}),
|
||||
[
|
||||
effectiveServerUrl,
|
||||
isUsingLocalUrl,
|
||||
ssid,
|
||||
connectedToWifi,
|
||||
refreshUrlState,
|
||||
],
|
||||
);
|
||||
|
||||
return (
|
||||
<ServerUrlContext.Provider
|
||||
value={{
|
||||
effectiveServerUrl,
|
||||
isUsingLocalUrl,
|
||||
currentSSID: ssid,
|
||||
connectedToWifi,
|
||||
refreshUrlState,
|
||||
}}
|
||||
>
|
||||
<ServerUrlContext.Provider value={value}>
|
||||
{children}
|
||||
</ServerUrlContext.Provider>
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { Platform } from "react-native";
|
||||
@@ -129,16 +130,19 @@ export function WifiSsidProvider({ children }: Props): React.ReactElement {
|
||||
return () => clearInterval(interval);
|
||||
}, [permissionStatus, fetchSSID]);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
ssid,
|
||||
connectedToWifi,
|
||||
permissionStatus,
|
||||
requestPermission,
|
||||
isLoading,
|
||||
}),
|
||||
[ssid, connectedToWifi, permissionStatus, requestPermission, isLoading],
|
||||
);
|
||||
|
||||
return (
|
||||
<WifiSsidContext.Provider
|
||||
value={{
|
||||
ssid,
|
||||
connectedToWifi,
|
||||
permissionStatus,
|
||||
requestPermission,
|
||||
isLoading,
|
||||
}}
|
||||
>
|
||||
<WifiSsidContext.Provider value={value}>
|
||||
{children}
|
||||
</WifiSsidContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user