Skip to content

Commit

Permalink
style improvements in device settings, add sentry features
Browse files Browse the repository at this point in the history
  • Loading branch information
Zainrax committed Oct 1, 2024
1 parent 01b0b15 commit 991e6f2
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 76 deletions.
2 changes: 1 addition & 1 deletion sidekick/App/App/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover, user-scalable=no"/>
<title>Sidekick</title>
<script type="module" crossorigin src="/assets/index-428b83c5.js"></script>
<script type="module" crossorigin src="/assets/index-09ebbfc3.js"></script>
<link rel="stylesheet" href="/assets/index-46635731.css">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion sidekick/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def capacitor_pods
pod 'CapacitorGeolocation', :path => '../../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@capacitor/geolocation'
pod 'CapacitorNetwork', :path => '../../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@capacitor/network'
pod 'CapacitorPreferences', :path => '../../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@capacitor/preferences'
pod 'SentryCapacitor', :path => '../../node_modules/.pnpm/@sentry+capacitor@0.19.0_@[email protected]/node_modules/@sentry/capacitor'
pod 'SentryCapacitor', :path => '../../node_modules/.pnpm/@sentry+capacitor@1.0.0_@[email protected]/node_modules/@sentry/capacitor'
pod 'CapacitorNativeSettings', :path => '../../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/capacitor-native-settings'
end

Expand Down
2 changes: 1 addition & 1 deletion sidekick/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ include ':capacitor-preferences'
project(':capacitor-preferences').projectDir = new File('../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@capacitor/preferences/android')

include ':sentry-capacitor'
project(':sentry-capacitor').projectDir = new File('../node_modules/.pnpm/@sentry+capacitor@0.19.0_@[email protected]/node_modules/@sentry/capacitor/android')
project(':sentry-capacitor').projectDir = new File('../node_modules/.pnpm/@sentry+capacitor@1.0.0_@[email protected]/node_modules/@sentry/capacitor/android')

include ':capacitor-native-settings'
project(':capacitor-native-settings').projectDir = new File('../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/capacitor-native-settings/android')
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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()
Expand All @@ -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)
Expand Down
138 changes: 80 additions & 58 deletions src/components/DeviceSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -667,69 +667,80 @@ export function CameraSettingsTab(props: SettingProps) {
return true;
};

const [isAudio] = createResource(() => context.getAudioMode(id()));

return (
<section>
<Show
when={isRecieving()}
when={isAudio.loading || isAudio() !== "AudioOnly"}
fallback={
<div
style={{
height: "269px",
}}
class="flex h-full items-center justify-center gap-x-2 bg-slate-50"
>
<FaSolidSpinner class="animate-spin" size={32} />
<p>Starting Camera...</p>
</div>
<p class="w-full p-8 text-center text-2xl text-neutral-600">
Preview not available in audio only mode.
</p>
}
>
<div class="relative">
<canvas
ref={frameCanvas}
id="frameCanvas"
width="160"
height="120"
class="w-full"
/>
<canvas
ref={trackCanvas}
id="trackCanvas"
width="160"
height="120"
class="absolute left-0 top-0 z-10 w-full"
/>
</div>
<Show
when={isRecieving()}
fallback={
<div
style={{
height: "269px",
}}
class="flex h-full items-center justify-center gap-x-2 bg-slate-50"
>
<FaSolidSpinner class="animate-spin" size={32} />
<p>Starting Camera...</p>
</div>
}
>
<div class="relative">
<canvas
ref={frameCanvas}
id="frameCanvas"
width="160"
height="120"
class="w-full"
/>
<canvas
ref={trackCanvas}
id="trackCanvas"
width="160"
height="120"
class="absolute left-0 top-0 z-10 w-full"
/>
</div>
</Show>
<button
ref={triggerTrap}
style="position: relative;display: none"
type="button"
>
Trigger trap
</button>
<button
class="flex w-full items-center justify-center space-x-2 rounded-b-lg bg-blue-500 py-3 text-white"
onClick={() => createTestRecording()}
disabled={recording()}
>
<Switch>
<Match when={recording()}>
<p>Recording...</p>
<FaSolidSpinner class="animate-spin" size={24} />
</Match>
<Match when={result() === "success"}>
<p>Success!</p>
<FaSolidCheck size={24} />
</Match>
<Match when={result() === "failed"}>
<ImCross size={12} />
</Match>
<Match when={!recording() && !result()}>
<p>Test Recording</p>
<FaSolidVideo size={24} />
</Match>
</Switch>
</button>
</Show>
<button
ref={triggerTrap}
style="position: relative;display: none"
type="button"
>
Trigger trap
</button>
<button
class="flex w-full items-center justify-center space-x-2 rounded-b-lg bg-blue-500 py-3 text-white"
onClick={() => createTestRecording()}
disabled={recording()}
>
<Switch>
<Match when={recording()}>
<p>Recording...</p>
<FaSolidSpinner class="animate-spin" size={24} />
</Match>
<Match when={result() === "success"}>
<p>Success!</p>
<FaSolidCheck size={24} />
</Match>
<Match when={result() === "failed"}>
<ImCross size={12} />
</Match>
<Match when={!recording() && !result()}>
<p>Test Recording</p>
<FaSolidVideo size={24} />
</Match>
</Switch>
</button>
<div class="px-6 py-2">
<h1 class="font-semibold text-gray-800">Recording Window</h1>
<div class="flex w-full justify-between">
Expand Down Expand Up @@ -2549,7 +2560,6 @@ export function DeviceSettingsModal() {
() => params.deviceSettings,
async (id) => {
const res = await context.hasAudioCapabilities(id);
console.log("HAS AUDIO", res);
return res;
}
);
Expand All @@ -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;

Expand Down Expand Up @@ -2600,7 +2622,7 @@ export function DeviceSettingsModal() {
<ImCross size={12} />
</button>
</header>
<nav class="flex w-full justify-between">
<nav class={`flex w-full justify-between ${textSizeClass()}`}>
<For each={navItems()}>
{(nav) => (
<button
Expand Down
9 changes: 6 additions & 3 deletions src/contexts/LogsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import {
createResource,
} from "solid-js";
import * as Sentry from "@sentry/capacitor";
import * as SentryBrowser from "@sentry/browser";
import * as SentrySolid from "@sentry/solid";
import { User, useUserContext } from "./User"; // Import User context
import { useLocation } from "@solidjs/router"; // Import router location
import { Preferences } from "@capacitor/preferences";
import { createRequire } from "module";
import { replayCanvasIntegration } from "@sentry/browser";
import { Primitive } from "zod";
import { browserTracingIntegration } from "@sentry/capacitor";

export enum TracingLevel {
NON_PERSONALIZED = "non_personalized",
Expand Down Expand Up @@ -77,6 +76,10 @@ const [LogsProvider, useLogsContext] = createContextProvider(() => {
const [userData, setUser] = createSignal<User | null>();
onMount(() => {
Sentry.init({
integrations: [
SentrySolid.browserTracingIntegration(),
SentrySolid.replayIntegration(),
],
dsn: "https://0af3453887927768a693178c3604d01f@o4507970723971072.ingest.us.sentry.io/4507970755493888",
tracesSampleRate: 0.2,
});
Expand Down

0 comments on commit 991e6f2

Please sign in to comment.