From 991e6f2df3bbaf2841642ab03257ea09dad44949 Mon Sep 17 00:00:00 2001 From: Patrick Baxter Date: Tue, 1 Oct 2024 14:16:52 +1300 Subject: [PATCH] style improvements in device settings, add sentry features --- sidekick/App/App/public/index.html | 2 +- sidekick/App/Podfile | 2 +- sidekick/capacitor.settings.gradle | 2 +- .../nz/org/cacophony/sidekick/DevicePlugin.kt | 37 +++-- src/components/DeviceSettings.tsx | 138 ++++++++++-------- src/contexts/LogsContext.ts | 9 +- 6 files changed, 114 insertions(+), 76 deletions(-) diff --git a/sidekick/App/App/public/index.html b/sidekick/App/App/public/index.html index fca4d511..dc697113 100644 --- a/sidekick/App/App/public/index.html +++ b/sidekick/App/App/public/index.html @@ -7,7 +7,7 @@ Sidekick - + diff --git a/sidekick/App/Podfile b/sidekick/App/Podfile index b7a8c122..cd42e3b5 100755 --- a/sidekick/App/Podfile +++ b/sidekick/App/Podfile @@ -23,7 +23,7 @@ def capacitor_pods pod 'CapacitorGeolocation', :path => '../../node_modules/.pnpm/@capacitor+geolocation@6.0.0_@capacitor+core@6.1.1/node_modules/@capacitor/geolocation' pod 'CapacitorNetwork', :path => '../../node_modules/.pnpm/@capacitor+network@6.0.1_@capacitor+core@6.1.1/node_modules/@capacitor/network' pod 'CapacitorPreferences', :path => '../../node_modules/.pnpm/@capacitor+preferences@6.0.1_@capacitor+core@6.1.1/node_modules/@capacitor/preferences' - pod 'SentryCapacitor', :path => '../../node_modules/.pnpm/@sentry+capacitor@0.19.0_@capacitor+core@6.1.1/node_modules/@sentry/capacitor' + pod 'SentryCapacitor', :path => '../../node_modules/.pnpm/@sentry+capacitor@1.0.0_@capacitor+core@6.1.1/node_modules/@sentry/capacitor' pod 'CapacitorNativeSettings', :path => '../../node_modules/.pnpm/capacitor-native-settings@6.0.0_@capacitor+core@6.1.1/node_modules/capacitor-native-settings' end diff --git a/sidekick/capacitor.settings.gradle b/sidekick/capacitor.settings.gradle index e913baa7..6dd977f1 100755 --- a/sidekick/capacitor.settings.gradle +++ b/sidekick/capacitor.settings.gradle @@ -42,7 +42,7 @@ include ':capacitor-preferences' project(':capacitor-preferences').projectDir = new File('../node_modules/.pnpm/@capacitor+preferences@6.0.1_@capacitor+core@6.1.1/node_modules/@capacitor/preferences/android') include ':sentry-capacitor' -project(':sentry-capacitor').projectDir = new File('../node_modules/.pnpm/@sentry+capacitor@0.19.0_@capacitor+core@6.1.1/node_modules/@sentry/capacitor/android') +project(':sentry-capacitor').projectDir = new File('../node_modules/.pnpm/@sentry+capacitor@1.0.0_@capacitor+core@6.1.1/node_modules/@sentry/capacitor/android') include ':capacitor-native-settings' project(':capacitor-native-settings').projectDir = new File('../node_modules/.pnpm/capacitor-native-settings@6.0.0_@capacitor+core@6.1.1/node_modules/capacitor-native-settings/android') diff --git a/sidekick/shared/src/androidMain/kotlin/nz/org/cacophony/sidekick/DevicePlugin.kt b/sidekick/shared/src/androidMain/kotlin/nz/org/cacophony/sidekick/DevicePlugin.kt index f5f3710c..898160ce 100755 --- a/sidekick/shared/src/androidMain/kotlin/nz/org/cacophony/sidekick/DevicePlugin.kt +++ b/sidekick/shared/src/androidMain/kotlin/nz/org/cacophony/sidekick/DevicePlugin.kt @@ -38,14 +38,18 @@ class DevicePlugin : Plugin() { private var wifiNetwork: Network? = null var currNetworkCallback: ConnectivityManager.NetworkCallback? = null private var cm: ConnectivityManager? = null -// private lateinit var multicastLock: WifiManager.MulticastLock + private lateinit var multicastLock: WifiManager.MulticastLock private var isDiscovering: Boolean = false + // Add a flag to keep track of whether to use the multicast lock + private var useMulticastLock = false + private var multicastLockUsedInCurrentDiscovery = false + override fun load() { super.load() device = DeviceInterface(context.applicationContext.filesDir.absolutePath) val wifi = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager -// multicastLock = wifi.createMulticastLock("multicastLock") + multicastLock = wifi.createMulticastLock("multicastLock") } enum class CallType { @@ -59,7 +63,14 @@ class DevicePlugin : Plugin() { } isDiscovering = true -// multicastLock.acquire() + + // Set the flag for the current discovery + multicastLockUsedInCurrentDiscovery = useMulticastLock + + // Acquire the multicast lock if needed + if (useMulticastLock) { + multicastLock.acquire() + } nsdHelper = object : NsdHelper(context.applicationContext) { override fun onNsdServiceResolved(service: NsdServiceInfo) { @@ -82,7 +93,10 @@ class DevicePlugin : Plugin() { override fun onDiscoveryFailed(e: Exception) { val error = JSObject() -// multicastLock.release() + // Release the multicast lock if it was used + if (multicastLockUsedInCurrentDiscovery && multicastLock.isHeld) { + multicastLock.release() + } try { error.put("message", e.message ?: "Unknown error during discovery") } catch (je: JSONException) { @@ -96,17 +110,13 @@ class DevicePlugin : Plugin() { nsdHelper.initializeNsd() nsdHelper.discoverServices() + // Flip the flag for the next discovery attempt + useMulticastLock = !useMulticastLock + // Resolve the call call.resolve() } - private fun hasLocationPermission(): Boolean { - return ContextCompat.checkSelfPermission( - context, - Manifest.permission.ACCESS_FINE_LOCATION - ) == android.content.pm.PackageManager.PERMISSION_GRANTED - } - @PluginMethod fun stopDiscoverDevices(call: PluginCall) { val result = JSObject() @@ -116,7 +126,10 @@ class DevicePlugin : Plugin() { return } try { -// multicastLock.release() + // Release the multicast lock if it was used + if (multicastLockUsedInCurrentDiscovery && multicastLock.isHeld) { + multicastLock.release() + } nsdHelper.stopDiscovery() isDiscovering = false result.put("success", true) diff --git a/src/components/DeviceSettings.tsx b/src/components/DeviceSettings.tsx index 96c9fdaa..aa17699d 100644 --- a/src/components/DeviceSettings.tsx +++ b/src/components/DeviceSettings.tsx @@ -667,69 +667,80 @@ export function CameraSettingsTab(props: SettingProps) { return true; }; + const [isAudio] = createResource(() => context.getAudioMode(id())); + return (
- -

Starting Camera...

- +

+ Preview not available in audio only mode. +

} > -
- - -
+ + +

Starting Camera...

+ + } + > +
+ + +
+
+ +
- -

Recording Window

@@ -2549,7 +2560,6 @@ export function DeviceSettingsModal() { () => params.deviceSettings, async (id) => { const res = await context.hasAudioCapabilities(id); - console.log("HAS AUDIO", res); return res; } ); @@ -2561,6 +2571,18 @@ export function DeviceSettingsModal() { return items; } }; + + const textSizeClass = createMemo(() => { + const numItems = navItems().length; + if (numItems <= 4) { + return "text-base"; + } else if (numItems === 5) { + return "text-sm"; + } else if (numItems >= 6) { + return "text-xs"; + } + }); + const isConnected = () => context.devices.get(params.deviceSettings)?.isConnected; @@ -2600,7 +2622,7 @@ export function DeviceSettingsModal() { -