Fix RustDesk sync before auto-launch redirect
The RustDesk data saved by Rust directly to file was not being synced to the backend because the app redirected to the web platform before the sync could complete. - Reload store from disk in openSystem to get Rust-saved data - Sync RustDesk before redirecting with 3s timeout - Fire-and-forget sync to avoid blocking the redirect 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2c47e84cab
commit
90d2221240
1 changed files with 40 additions and 1 deletions
|
|
@ -1042,8 +1042,47 @@ const resolvedAppUrl = useMemo(() => {
|
||||||
const openSystem = useCallback(async () => {
|
const openSystem = useCallback(async () => {
|
||||||
if (!token) return
|
if (!token) return
|
||||||
setIsLaunchingSystem(true)
|
setIsLaunchingSystem(true)
|
||||||
|
|
||||||
|
// Recarrega store do disco para pegar dados que o Rust salvou diretamente
|
||||||
|
// e sincroniza RustDesk antes de redirecionar (fire-and-forget com timeout)
|
||||||
try {
|
try {
|
||||||
// Tenta criar a sessão via API (evita dependência de redirecionamento + cookies em 3xx)
|
if (store && config?.machineId) {
|
||||||
|
const freshStore = await loadStore()
|
||||||
|
const freshRustdesk = await readRustdeskInfo(freshStore)
|
||||||
|
if (freshRustdesk && (!freshRustdesk.lastSyncedAt || Date.now() - freshRustdesk.lastSyncedAt > 60000)) {
|
||||||
|
logDesktop("openSystem:rustdesk:sync:start", { id: freshRustdesk.id })
|
||||||
|
const payload = buildRemoteAccessPayload(freshRustdesk)
|
||||||
|
if (payload) {
|
||||||
|
const syncPromise = fetch(`${apiBaseUrl}/api/machines/remote-access`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Idempotency-Key": `${config.machineId}:RustDesk:${freshRustdesk.id}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ machineToken: token, ...payload }),
|
||||||
|
}).then(async (syncRes) => {
|
||||||
|
if (syncRes.ok) {
|
||||||
|
logDesktop("openSystem:rustdesk:sync:success", { id: freshRustdesk.id })
|
||||||
|
const nextInfo: RustdeskInfo = { ...freshRustdesk, lastSyncedAt: Date.now(), lastError: null }
|
||||||
|
await writeRustdeskInfo(freshStore, nextInfo)
|
||||||
|
setRustdeskInfo(nextInfo)
|
||||||
|
} else {
|
||||||
|
logDesktop("openSystem:rustdesk:sync:error", { status: syncRes.status })
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
logDesktop("openSystem:rustdesk:sync:failed", { error: String(err) })
|
||||||
|
})
|
||||||
|
// Espera no maximo 3s pelo sync, depois continua
|
||||||
|
await Promise.race([syncPromise, new Promise((r) => setTimeout(r, 3000))])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (syncErr) {
|
||||||
|
logDesktop("openSystem:rustdesk:sync:exception", { error: String(syncErr) })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Tenta criar a sessao via API (evita dependencia de redirecionamento + cookies em 3xx)
|
||||||
const res = await fetch(`${apiBaseUrl}/api/machines/sessions`, {
|
const res = await fetch(`${apiBaseUrl}/api/machines/sessions`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue