From 659d9779b3fe98937ebba68a319689cf32790e13 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Jul 2026 20:53:40 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20DOBRADO=5FLOJA=20env=20injetado=20no=20?= =?UTF-8?q?build=20=E2=80=94=20builds=20separadas=20Uniao/Alianca/Ambos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - app.rs: LOJA_FIXA via option_env!(DOBRADO_LOJA), get_loja_fixa command - app.rs: set_loja bloqueado se build fixa - index.html: DOMContentLoaded detecta loja fixa e esconde seletor - 3 executáveis: fc-uniao.exe / fc-alianca.exe / fc-ambos.exe --- src-tauri/src/main.rs | 1 + src-tauri/src/plugins/app.rs | 28 +++++++++++++++++++++++++++- src/index.html | 24 +++++++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 059807d..5efe41b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -111,6 +111,7 @@ fn main() { plugins::printer::ativar_modo_teste_impressao, // App plugins::app::get_loja, + plugins::app::get_loja_fixa, plugins::app::set_loja, plugins::app::get_config, plugins::app::set_config, diff --git a/src-tauri/src/plugins/app.rs b/src-tauri/src/plugins/app.rs index e29364f..5019282 100644 --- a/src-tauri/src/plugins/app.rs +++ b/src-tauri/src/plugins/app.rs @@ -1,5 +1,8 @@ //! Plugin de configuração da aplicação (loja, preferências) //! Persistido em config.json ao lado do banco SQLite. +//! +//! LOJA_FIXA: definido em tempo de build via env DOBRADO_LOJA (Uniao | Alianca). +//! Quando definido, a loja é travada e o seletor do formulário fica desabilitado. use serde::{Deserialize, Serialize}; use std::fs; @@ -7,6 +10,9 @@ use std::path::PathBuf; use std::sync::Mutex; use tauri::State; +/// Indica se a loja foi fixada em tempo de build. +pub const LOJA_FIXA: Option<&'static str> = option_env!("DOBRADO_LOJA"); + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct AppConfig { pub loja: String, @@ -15,17 +21,28 @@ pub struct AppConfig { pub turno_default: String, pub sync_automatico: bool, pub auto_open_printer: bool, + /// Verdadeiro quando a build tem loja fixa (não permite trocar no formulário) + #[serde(skip_serializing_if = "Option::is_none")] + pub loja_fixa: Option, +} + +impl AppConfig { + /// Loja padrão: o env DOBRADO_LOJA se existir, senão "Uniao" + pub fn default_loja() -> String { + LOJA_FIXA.unwrap_or("Uniao").to_string() + } } impl Default for AppConfig { fn default() -> Self { Self { - loja: "Uniao".to_string(), + loja: Self::default_loja(), pdv_nome: "PDV-01".to_string(), operador_default: String::new(), turno_default: String::new(), sync_automatico: true, auto_open_printer: false, + loja_fixa: LOJA_FIXA.map(|_| true), } } } @@ -65,8 +82,17 @@ pub fn get_loja(state: State<'_, AppState>) -> String { state.config.lock().unwrap().loja.clone() } +#[tauri::command] +pub fn get_loja_fixa() -> Option { + LOJA_FIXA.map(|s| s.to_string()) +} + #[tauri::command] pub fn set_loja(state: State<'_, AppState>, loja: String) -> Result<(), String> { + // Se loja_fixa está ativa, não permite alterar + if LOJA_FIXA.is_some() { + return Err("Loja fixa em tempo de build — não é possível trocar.".to_string()); + } state.config.lock().unwrap().loja = loja; state.save() } diff --git a/src/index.html b/src/index.html index 0e9293f..febff18 100644 --- a/src/index.html +++ b/src/index.html @@ -3667,7 +3667,29 @@ async function salvarEdicaoSupabase() { } // ─── Boot ───────────────────────────────────────────────────────────────── -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener('DOMContentLoaded', async () => { + // Detecta se é build com loja fixa (União ou Aliança) + try { + const fixa = await window.__TAURI__.core.invoke('get_loja_fixa'); + if (fixa) { + // Build fixa: desabilita e esconde o seletor de loja + window.__LOJA_FIXA__ = fixa; + const sel = document.getElementById('f-loja'); + if (sel) { + sel.value = fixa; + sel.disabled = true; + sel.style.display = 'none'; + } + // Esconde também o label "Loja" + const label = document.querySelector('.meta-label'); + if (label && label.textContent.trim() === 'Loja') { + label.style.display = 'none'; + } + estado.loja = fixa; + } + } catch(e) { + console.warn('get_loja_fixa não disponível:', e); + } loadConfig(); buildDatalists(); if (!loadState()) init();