From 619f311daab04046bfbd92c5990af5d5dc89f1dc Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Fri, 10 Oct 2025 22:39:38 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20evitar=20URLs=20localhost=20em=20builds?= =?UTF-8?q?=20de=20produ=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/desktop/src/main.tsx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsx index ab44425..9c31c20 100644 --- a/apps/desktop/src/main.tsx +++ b/apps/desktop/src/main.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react" +import { useEffect, useMemo, useState } from "react" import { createRoot } from "react-dom/client" import { invoke } from "@tauri-apps/api/core" import { Store } from "@tauri-apps/plugin-store" @@ -149,6 +149,29 @@ function App() { })() }, []) + useEffect(() => { + if (!store || !config) return + const normalizedAppUrl = normalizeUrl(config.appUrl, appUrl) + const normalizedApiUrl = normalizeUrl(config.apiBaseUrl, apiBaseUrl) + const shouldForceRemote = import.meta.env.MODE === "production" + const nextAppUrl = shouldForceRemote && normalizedAppUrl.includes("localhost") ? appUrl : normalizedAppUrl + const nextApiUrl = shouldForceRemote && normalizedApiUrl.includes("localhost") ? apiBaseUrl : normalizedApiUrl + if (nextAppUrl !== config.appUrl || nextApiUrl !== config.apiBaseUrl) { + const updatedConfig = { ...config, appUrl: nextAppUrl, apiBaseUrl: nextApiUrl } + setConfig(updatedConfig) + writeConfig(store, updatedConfig).catch((err) => console.error("Falha ao atualizar configuração", err)) + } + }, [store, config]) + + const resolvedAppUrl = useMemo(() => { + if (!config?.appUrl) return appUrl + const normalized = normalizeUrl(config.appUrl, appUrl) + if (import.meta.env.MODE === "production" && normalized.includes("localhost")) { + return appUrl + } + return normalized + }, [config?.appUrl, appUrl]) + async function register() { if (!profile) return if (!provisioningSecret.trim()) { setError("Informe o código de provisionamento."); return } @@ -197,7 +220,7 @@ function App() { async function openSystem() { if (!token || !config) return - const url = `${config.appUrl}/machines/handshake?token=${encodeURIComponent(token)}` + const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}` try { // open in default browser; fallback to in-webview const { openUrl } = await import("@tauri-apps/plugin-opener")