2026-02-17 14:30:02 +07:00
|
|
|
<!-- navbar select menus -->
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import favicon from '$lib/assets/favicon.svg';
|
|
|
|
|
import AppAccountSelect from '$lib/components/app-account-select.svelte';
|
|
|
|
|
import AppSidebar from '$lib/components/app-sidebar.svelte';
|
|
|
|
|
import * as Sidebar from '$lib/components/ui/sidebar/index';
|
|
|
|
|
import '../layout.css';
|
|
|
|
|
import ErrorLayout from '$lib/components/error-layout.svelte';
|
|
|
|
|
import { sidebarStore } from '$lib/core/stores/sidebar';
|
2026-02-26 12:49:08 +07:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { auth } from '$lib/core/stores/auth';
|
|
|
|
|
import { get } from 'svelte/store';
|
|
|
|
|
import { connectToWebsocket } from '$lib/core/stores/websocketStore';
|
2026-03-04 13:28:14 +07:00
|
|
|
import * as adb from '$lib/core/adb/adb';
|
|
|
|
|
import { addNotification } from '$lib/core/stores/noti';
|
|
|
|
|
import { AdbDaemonWebUsbDeviceManager } from '@yume-chan/adb-daemon-webusb';
|
|
|
|
|
import AdbWebCredentialStore from '@yume-chan/adb-credential-web';
|
|
|
|
|
import { deviceCredentialManager } from '$lib/core/adb/deviceCredManager';
|
2026-02-17 14:30:02 +07:00
|
|
|
|
|
|
|
|
let { children } = $props();
|
2026-02-26 12:49:08 +07:00
|
|
|
|
2026-03-04 13:28:14 +07:00
|
|
|
async function tryAutoConnect() {
|
|
|
|
|
try {
|
|
|
|
|
if (!('usb' in navigator) || !AdbDaemonWebUsbDeviceManager.BROWSER) {
|
|
|
|
|
throw new Error('WebUSB not supported, try using fallback or different browser');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const devices = await AdbDaemonWebUsbDeviceManager.BROWSER.getDevices();
|
|
|
|
|
if (!devices || devices.length == 0) {
|
|
|
|
|
throw new Error('No device found');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (devices.length > 1) {
|
|
|
|
|
throw new Error('Too many connected devices');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const device = devices[0];
|
|
|
|
|
const credStore = new AdbWebCredentialStore();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await adb.connectDeviceByCred(device, credStore);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
if (e.message === 'CREDENTIAL_EXPIRED') {
|
|
|
|
|
try {
|
|
|
|
|
await deviceCredentialManager.clearAllCredentials();
|
|
|
|
|
} catch (ignored) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('error on auto connect brew page', e);
|
|
|
|
|
addNotification('ERROR:Failed to auto connect, please try again');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
2026-02-26 12:49:08 +07:00
|
|
|
let currentUser = get(auth);
|
2026-03-04 13:28:14 +07:00
|
|
|
// console.log(`on mount layout current user: ${JSON.stringify(currentUser)}`);
|
2026-02-26 12:49:08 +07:00
|
|
|
if (currentUser) {
|
|
|
|
|
connectToWebsocket();
|
2026-03-04 13:28:14 +07:00
|
|
|
await tryAutoConnect();
|
2026-02-26 12:49:08 +07:00
|
|
|
}
|
|
|
|
|
});
|
2026-02-17 14:30:02 +07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
|
<link rel="icon" href={favicon} />
|
|
|
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto+Flex" rel="stylesheet" />
|
|
|
|
|
<title>Taobin Management Tools</title>
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
|
|
<Sidebar.Provider
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
sidebarStore.set(open);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<AppSidebar />
|
|
|
|
|
<main class="h-screen w-screen overflow-hidden">
|
|
|
|
|
<Sidebar.Trigger />
|
|
|
|
|
{@render children()}
|
|
|
|
|
</main>
|
|
|
|
|
</Sidebar.Provider>
|