feat: código inicial do client Electron com auto-updater integrado
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
*.exe
|
||||||
|
*.blockmap
|
||||||
|
uploaded_cache.json
|
||||||
|
config.json
|
||||||
+1488
File diff suppressed because it is too large
Load Diff
+396
@@ -0,0 +1,396 @@
|
|||||||
|
:root {
|
||||||
|
--bg: #0a0910;
|
||||||
|
--card-bg: rgba(18, 16, 30, 0.75);
|
||||||
|
--border: rgba(255, 255, 255, 0.08);
|
||||||
|
--primary: #8257e5;
|
||||||
|
--primary-hover: #9466ff;
|
||||||
|
--primary-glow: rgba(130, 87, 229, 0.3);
|
||||||
|
--accent: #04d361;
|
||||||
|
--text: #f8f8f2;
|
||||||
|
--muted: #8f8f9d;
|
||||||
|
--input-bg: rgba(0, 0, 0, 0.4);
|
||||||
|
--danger: #e96379;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: 'Inter', sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--bg);
|
||||||
|
background-image:
|
||||||
|
radial-gradient(at 0% 0%, rgba(130, 87, 229, 0.15) 0px, transparent 65%),
|
||||||
|
radial-gradient(at 100% 100%, rgba(4, 211, 97, 0.08) 0px, transparent 65%);
|
||||||
|
background-attachment: fixed;
|
||||||
|
color: var(--text);
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-container {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100vh;
|
||||||
|
padding: 24px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* HEADER */
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding-bottom: 16px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-icon {
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-text h1 {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.5px;
|
||||||
|
background: linear-gradient(135deg, #fff 0%, var(--muted) 100%);
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-text p {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
margin-top: 1px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-domain {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--primary-hover);
|
||||||
|
background: rgba(130, 87, 229, 0.1);
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
border: 1px solid rgba(130, 87, 229, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* MAIN CONTENT AREA */
|
||||||
|
.main-content {
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CONTAINER PANELS (LOGIN & SETTINGS) */
|
||||||
|
.container-panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: space-between;
|
||||||
|
transition: opacity 0.25s ease, transform 0.25s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container-panel.hidden {
|
||||||
|
display: none !important;
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(15px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header h2 {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header p {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* LOGIN FORM SPECIFICS */
|
||||||
|
.login-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
max-width: 400px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 24px;
|
||||||
|
padding-top: 16px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SETTINGS FORM SPECIFICS */
|
||||||
|
.config-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group.full-width {
|
||||||
|
grid-column: span 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
color: var(--muted);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
background: var(--input-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 13px;
|
||||||
|
transition: all 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--primary);
|
||||||
|
box-shadow: 0 0 0 3px var(--primary-glow);
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.help-text {
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--muted);
|
||||||
|
margin-top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ACTIONS */
|
||||||
|
.form-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 16px;
|
||||||
|
padding-top: 16px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BUTTONS */
|
||||||
|
.btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 9px 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background: var(--primary);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background: var(--primary-hover);
|
||||||
|
box-shadow: 0 4px 15px var(--primary-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-outline {
|
||||||
|
background: rgba(255, 255, 255, 0.03);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-outline:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
border-color: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-text {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-text:hover {
|
||||||
|
color: #fff;
|
||||||
|
background: rgba(255, 255, 255, 0.03);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SPINNER */
|
||||||
|
.spinner {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top-color: white;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TOAST */
|
||||||
|
.toast {
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%) translateY(-50px);
|
||||||
|
opacity: 0;
|
||||||
|
background: var(--primary);
|
||||||
|
color: white;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 30px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||||
|
z-index: 1000;
|
||||||
|
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||||
|
pointer-events: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast.show {
|
||||||
|
transform: translateX(-50%) translateY(0);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast.success {
|
||||||
|
background: var(--accent);
|
||||||
|
color: #050408;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast.error {
|
||||||
|
background: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.password-wrapper {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.password-wrapper input {
|
||||||
|
width: 100%;
|
||||||
|
padding-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-toggle-password {
|
||||||
|
position: absolute;
|
||||||
|
right: 12px;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: var(--muted);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
outline: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-toggle-password:hover {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TERMINAL LOGS */
|
||||||
|
.terminal-container {
|
||||||
|
margin-top: 20px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(0,0,0,0.4);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
.terminal-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: rgba(255,255,255,0.02);
|
||||||
|
border-radius: 8px 8px 0 0;
|
||||||
|
}
|
||||||
|
.terminal-header h3 {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
.terminal-header .btn-sm {
|
||||||
|
padding: 4px 8px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
.terminal-body {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 10px;
|
||||||
|
font-family: 'JetBrains Mono', monospace;
|
||||||
|
font-size: 11px;
|
||||||
|
color: #a0a0b0;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
.terminal-body .log-line {
|
||||||
|
margin-bottom: 3px;
|
||||||
|
border-left: 2px solid rgba(130, 87, 229, 0.4);
|
||||||
|
padding-left: 6px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
+145
@@ -0,0 +1,145 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pt-BR">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>ScoreOdonto - Configuração</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="config-ui.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="toast" class="toast"></div>
|
||||||
|
<div class="page-container">
|
||||||
|
<!-- HEADER -->
|
||||||
|
<header class="header">
|
||||||
|
<div class="logo">
|
||||||
|
<span class="logo-icon">🦷</span>
|
||||||
|
<div class="logo-text">
|
||||||
|
<h1>ScoreOdonto</h1>
|
||||||
|
<p>Dental Client Setup</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<div class="brand-domain">rx.scoreodonto.com</div>
|
||||||
|
<span style="font-size: 10px; background: rgba(130,87,229,0.15); color: rgba(180,160,255,0.8); padding: 2px 8px; border-radius: 20px; border: 1px solid rgba(130,87,229,0.2); font-family: 'JetBrains Mono', monospace; letter-spacing: 0.5px;">Client v1.1.0</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- MAIN CONTENT AREA -->
|
||||||
|
<main class="main-content">
|
||||||
|
|
||||||
|
<!-- 1. LOGIN SCREEN -->
|
||||||
|
<div id="login-container" class="container-panel">
|
||||||
|
<div class="panel-header">
|
||||||
|
<h2>🔒 Acesso Restrito</h2>
|
||||||
|
<p>Insira as credenciais do Administrador para alterar as configurações.</p>
|
||||||
|
</div>
|
||||||
|
<form id="login-form" class="login-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="login-username">👤 Usuário</label>
|
||||||
|
<input type="text" id="login-username" placeholder="Digite o usuário" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="login-password">🔑 Senha</label>
|
||||||
|
<input type="password" id="login-password" placeholder="Digite a senha" required>
|
||||||
|
</div>
|
||||||
|
<div class="login-actions">
|
||||||
|
<button type="button" id="btn-login-cancel" class="btn btn-outline">Minimizar</button>
|
||||||
|
<button type="submit" id="btn-login-submit" class="btn btn-primary">Entrar</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 2. CONFIGURATION SCREEN (Hidden by default, shown after login or on first run) -->
|
||||||
|
<div id="settings-container" class="container-panel hidden">
|
||||||
|
<form id="config-form" class="config-form">
|
||||||
|
<div class="form-grid">
|
||||||
|
<!-- Machine Name - High Priority -->
|
||||||
|
<div class="form-group full-width">
|
||||||
|
<label for="clientName">🖥️ Nome Deste Computador</label>
|
||||||
|
<input type="text" id="clientName" placeholder="Ex: PC-CONSULTORIO-1" required autocomplete="off">
|
||||||
|
<small class="help-text">Insira um nome único identificável no painel da ScoreOdonto.</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server URL -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="serverUrl">🌐 URL do Servidor</label>
|
||||||
|
<input type="text" id="serverUrl" placeholder="https://rx.scoreodonto.com" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Monitor Path -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="monitorPath">📁 Pasta para Monitorar</label>
|
||||||
|
<input type="text" id="monitorPath" placeholder="C:\ProgramData\RF\Dental Sensor\Images" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Email -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="serverEmail">📧 E-mail do Servidor</label>
|
||||||
|
<input type="email" id="serverEmail" placeholder="email@clinica.com" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Password -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="serverPassword">🔑 Senha do Servidor</label>
|
||||||
|
<input type="password" id="serverPassword" placeholder="Sua senha no servidor" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Token -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="token">🔑 Token do Servidor</label>
|
||||||
|
<input type="text" id="token" placeholder="Token de 48 caracteres do cadastro" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Local Admin Username -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="adminUsername">👤 Usuário do Painel</label>
|
||||||
|
<input type="text" id="adminUsername" placeholder="Usuário admin" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Local Admin Password -->
|
||||||
|
<div class="form-group full-width">
|
||||||
|
<label for="adminPassword">🔒 Senha do Painel (Bloqueio de Configurações)</label>
|
||||||
|
<div class="password-wrapper">
|
||||||
|
<input type="password" id="adminPassword" placeholder="Senha do painel" required autocomplete="off">
|
||||||
|
<button type="button" id="toggle-admin-password" class="btn-toggle-password">👁️</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ACTIONS -->
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="button" id="btn-test" class="btn btn-outline">
|
||||||
|
<span id="test-spinner" class="spinner"></span>
|
||||||
|
<span id="test-text">⚡ Testar Conexão</span>
|
||||||
|
</button>
|
||||||
|
<div class="right-buttons">
|
||||||
|
<button type="button" id="btn-cancel" class="btn btn-text">Minimizar</button>
|
||||||
|
<button type="submit" id="btn-save" class="btn btn-primary">
|
||||||
|
<span id="save-spinner" class="spinner"></span>
|
||||||
|
<span>💾 Salvar Configurações</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- TERMINAL LOGS -->
|
||||||
|
<div class="terminal-container">
|
||||||
|
<div class="terminal-header">
|
||||||
|
<h3>📜 Logs do Sistema</h3>
|
||||||
|
<button type="button" class="btn btn-outline btn-sm" id="btn-copy-logs" title="Copiar logs">
|
||||||
|
<span id="copy-icon">📋</span> Copiar
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="terminal-body" id="terminal-logs">
|
||||||
|
<div class="log-line">[Sistema] Aguardando logs do monitor...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="config-ui.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+262
@@ -0,0 +1,262 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
// Containers
|
||||||
|
const loginContainer = document.getElementById('login-container');
|
||||||
|
const settingsContainer = document.getElementById('settings-container');
|
||||||
|
|
||||||
|
// Login Form Elements
|
||||||
|
const loginForm = document.getElementById('login-form');
|
||||||
|
const loginUsernameInput = document.getElementById('login-username');
|
||||||
|
const loginPasswordInput = document.getElementById('login-password');
|
||||||
|
const btnLoginCancel = document.getElementById('btn-login-cancel');
|
||||||
|
|
||||||
|
// Config Form Elements
|
||||||
|
const configForm = document.getElementById('config-form');
|
||||||
|
const clientNameInput = document.getElementById('clientName');
|
||||||
|
const serverUrlInput = document.getElementById('serverUrl');
|
||||||
|
const monitorPathInput = document.getElementById('monitorPath');
|
||||||
|
const serverEmailInput = document.getElementById('serverEmail');
|
||||||
|
const serverPasswordInput = document.getElementById('serverPassword');
|
||||||
|
const tokenInput = document.getElementById('token');
|
||||||
|
const adminUsernameInput = document.getElementById('adminUsername');
|
||||||
|
const adminPasswordInput = document.getElementById('adminPassword');
|
||||||
|
|
||||||
|
// Action Buttons
|
||||||
|
const btnTest = document.getElementById('btn-test');
|
||||||
|
const testSpinner = document.getElementById('test-spinner');
|
||||||
|
const testText = document.getElementById('test-text');
|
||||||
|
const btnCancel = document.getElementById('btn-cancel');
|
||||||
|
|
||||||
|
let loadedConfig = null;
|
||||||
|
|
||||||
|
// Show message notification
|
||||||
|
function showToast(message, type = 'success') {
|
||||||
|
const toast = document.getElementById('toast');
|
||||||
|
toast.textContent = message;
|
||||||
|
toast.className = `toast show ${type}`;
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.className = 'toast';
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize layout and load config
|
||||||
|
try {
|
||||||
|
loadedConfig = await window.api.getConfig();
|
||||||
|
|
||||||
|
// Populate settings form
|
||||||
|
if (loadedConfig.clientName === 'DIGITE-O-NOME-DA-MAQUINA') {
|
||||||
|
clientNameInput.value = '';
|
||||||
|
} else {
|
||||||
|
clientNameInput.value = loadedConfig.clientName || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
serverUrlInput.value = loadedConfig.serverUrl || 'https://rx.scoreodonto.com';
|
||||||
|
monitorPathInput.value = loadedConfig.monitorPath || 'C:\\ProgramData\\RF\\Dental Sensor\\Images';
|
||||||
|
serverEmailInput.value = loadedConfig.serverEmail || '';
|
||||||
|
serverPasswordInput.value = loadedConfig.serverPassword || '';
|
||||||
|
tokenInput.value = loadedConfig.token || '';
|
||||||
|
adminUsernameInput.value = loadedConfig.adminUsername || 'admin';
|
||||||
|
adminPasswordInput.value = loadedConfig.adminPassword || 'admin';
|
||||||
|
|
||||||
|
// Check if it is a first run (clientName not configured yet)
|
||||||
|
const isFirstRun = !loadedConfig.clientName || loadedConfig.clientName === 'DIGITE-O-NOME-DA-MAQUINA';
|
||||||
|
|
||||||
|
if (isFirstRun) {
|
||||||
|
// Bypass login overlay and show setup screen directly
|
||||||
|
loginContainer.classList.add('hidden');
|
||||||
|
settingsContainer.classList.remove('hidden');
|
||||||
|
} else {
|
||||||
|
// Show login screen
|
||||||
|
loginContainer.classList.remove('hidden');
|
||||||
|
settingsContainer.classList.add('hidden');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showToast('Erro ao carregar configurações: ' + e.message, 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Login Submit
|
||||||
|
loginForm.addEventListener('submit', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const username = loginUsernameInput.value.trim();
|
||||||
|
const password = loginPasswordInput.value;
|
||||||
|
|
||||||
|
const correctUsername = loadedConfig.adminUsername || 'admin';
|
||||||
|
const correctPassword = loadedConfig.adminPassword || 'admin';
|
||||||
|
|
||||||
|
if (username === correctUsername && password === correctPassword) {
|
||||||
|
showToast('Autenticado com sucesso!', 'success');
|
||||||
|
// Transition panels
|
||||||
|
loginContainer.classList.add('hidden');
|
||||||
|
settingsContainer.classList.remove('hidden');
|
||||||
|
} else {
|
||||||
|
showToast('Usuário ou senha inválidos.', 'error');
|
||||||
|
loginPasswordInput.value = '';
|
||||||
|
loginPasswordInput.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle Config Form Submit
|
||||||
|
configForm.addEventListener('submit', async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const name = clientNameInput.value.trim();
|
||||||
|
if (!name || name === 'DIGITE-O-NOME-DA-MAQUINA') {
|
||||||
|
showToast('Por favor, informe um nome válido para o computador.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serverUrl = serverUrlInput.value.trim();
|
||||||
|
const serverEmail = serverEmailInput.value.trim();
|
||||||
|
const serverPassword = serverPasswordInput.value;
|
||||||
|
const token = tokenInput.value.trim();
|
||||||
|
|
||||||
|
// Validar credenciais no servidor
|
||||||
|
const saveSpinner = document.getElementById('save-spinner');
|
||||||
|
const saveBtn = document.getElementById('btn-save');
|
||||||
|
saveBtn.disabled = true;
|
||||||
|
if (saveSpinner) saveSpinner.style.display = 'inline-block';
|
||||||
|
|
||||||
|
try {
|
||||||
|
showToast('Validando credenciais com o servidor...', 'info');
|
||||||
|
const verifyResult = await window.api.verifyCredentials(serverUrl, serverEmail, serverPassword, token);
|
||||||
|
|
||||||
|
if (saveSpinner) saveSpinner.style.display = 'none';
|
||||||
|
saveBtn.disabled = false;
|
||||||
|
|
||||||
|
if (!verifyResult.success) {
|
||||||
|
showToast('Falha na validação: ' + verifyResult.error, 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showToast('Credenciais confirmadas pelo servidor!', 'success');
|
||||||
|
} catch (authErr) {
|
||||||
|
if (saveSpinner) saveSpinner.style.display = 'none';
|
||||||
|
saveBtn.disabled = false;
|
||||||
|
showToast('Erro ao conectar ao servidor para validar: ' + authErr.message, 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newConfig = {
|
||||||
|
...loadedConfig,
|
||||||
|
clientName: name,
|
||||||
|
serverUrl: serverUrl,
|
||||||
|
monitorPath: monitorPathInput.value.trim(),
|
||||||
|
apiKey: token, // Salva o token também como apiKey para compatibilidade retroativa
|
||||||
|
serverEmail: serverEmail,
|
||||||
|
serverPassword: serverPassword,
|
||||||
|
token: token,
|
||||||
|
adminUsername: adminUsernameInput.value.trim(),
|
||||||
|
adminPassword: adminPasswordInput.value.trim(),
|
||||||
|
clientType: 'windows'
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const success = await window.api.saveConfig(newConfig);
|
||||||
|
if (success) {
|
||||||
|
showToast('Configurações salvas!');
|
||||||
|
setTimeout(() => {
|
||||||
|
window.api.closeWindow();
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
showToast('Falha ao salvar as configurações.', 'error');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
showToast('Erro: ' + err.message, 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle Test Connection
|
||||||
|
btnTest.addEventListener('click', async () => {
|
||||||
|
const url = serverUrlInput.value.trim();
|
||||||
|
if (!url) {
|
||||||
|
showToast('Informe a URL do servidor.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
btnTest.disabled = true;
|
||||||
|
testSpinner.style.display = 'inline-block';
|
||||||
|
testText.textContent = ' Testando...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await window.api.testServer(url);
|
||||||
|
if (result.success) {
|
||||||
|
showToast('Conexão estabelecida com sucesso!', 'success');
|
||||||
|
} else {
|
||||||
|
showToast('Falha na conexão: ' + result.error, 'error');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
showToast('Erro: ' + err.message, 'error');
|
||||||
|
} finally {
|
||||||
|
btnTest.disabled = false;
|
||||||
|
testSpinner.style.display = 'none';
|
||||||
|
testText.textContent = '⚡ Testar Conexão';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Toggle Admin Password Visibility
|
||||||
|
const toggleAdminPassword = document.getElementById('toggle-admin-password');
|
||||||
|
if (toggleAdminPassword) {
|
||||||
|
toggleAdminPassword.addEventListener('click', () => {
|
||||||
|
const type = adminPasswordInput.getAttribute('type') === 'password' ? 'text' : 'password';
|
||||||
|
adminPasswordInput.setAttribute('type', type);
|
||||||
|
toggleAdminPassword.textContent = type === 'password' ? '👁️' : '🙈';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Minimize / Close Window
|
||||||
|
btnCancel.addEventListener('click', () => {
|
||||||
|
window.api.closeWindow();
|
||||||
|
});
|
||||||
|
|
||||||
|
btnLoginCancel.addEventListener('click', () => {
|
||||||
|
window.api.closeWindow();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Terminal Logs
|
||||||
|
const terminalLogs = document.getElementById('terminal-logs');
|
||||||
|
const btnCopyLogs = document.getElementById('btn-copy-logs');
|
||||||
|
|
||||||
|
if (window.api.onLog) {
|
||||||
|
window.api.onLog((log) => {
|
||||||
|
if (terminalLogs) {
|
||||||
|
// remove the waiting message if present
|
||||||
|
const waitingMsg = terminalLogs.querySelector('.log-line');
|
||||||
|
if (waitingMsg && waitingMsg.textContent.includes('Aguardando logs')) {
|
||||||
|
terminalLogs.innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.className = 'log-line';
|
||||||
|
div.textContent = log;
|
||||||
|
terminalLogs.appendChild(div);
|
||||||
|
|
||||||
|
// Auto scroll to bottom
|
||||||
|
terminalLogs.scrollTop = terminalLogs.scrollHeight;
|
||||||
|
|
||||||
|
// Keep max 100 logs
|
||||||
|
while (terminalLogs.children.length > 100) {
|
||||||
|
terminalLogs.removeChild(terminalLogs.firstChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (btnCopyLogs && terminalLogs) {
|
||||||
|
btnCopyLogs.addEventListener('click', () => {
|
||||||
|
const logsText = Array.from(terminalLogs.children)
|
||||||
|
.map(el => el.textContent)
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
|
navigator.clipboard.writeText(logsText).then(() => {
|
||||||
|
const icon = document.getElementById('copy-icon');
|
||||||
|
const originalText = btnCopyLogs.innerHTML;
|
||||||
|
btnCopyLogs.innerHTML = '✅ Copiado';
|
||||||
|
setTimeout(() => {
|
||||||
|
btnCopyLogs.innerHTML = originalText;
|
||||||
|
}, 2000);
|
||||||
|
}).catch(err => {
|
||||||
|
showToast('Erro ao copiar logs', 'error');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
@echo off
|
||||||
|
echo Abrindo painel de configuracao do Dental Client...
|
||||||
|
start http://localhost:3001
|
||||||
|
exit
|
||||||
Executable
+67
@@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# ─── deploy-client.sh (RX ScoreOdonto - Desktop Client) ──────────────────────
|
||||||
|
# Cross-compile do Electron na VPS 4 (Linux) gerando .exe para Windows
|
||||||
|
# e distribui os binários de atualização para a VPS 1 (Produção).
|
||||||
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CLIENT_PATH="/home/deploy/stack/dental-client"
|
||||||
|
PROD_VPS="10.99.0.1"
|
||||||
|
PROD_USER="deploy"
|
||||||
|
UPDATES_PATH="/home/deploy/stack/rx.scoreodonto.com/dental-server/updates"
|
||||||
|
LOG_FILE="/home/deploy/stack/webhook-listener/deploy.log"
|
||||||
|
LOG_TAG="[dental-client]"
|
||||||
|
|
||||||
|
log() {
|
||||||
|
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] ${LOG_TAG} $1" | tee -a "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
log "🚀 Iniciando build do client desktop..."
|
||||||
|
|
||||||
|
# 1. Atualizar repositório local
|
||||||
|
log "📦 Sincronizando repositório Git..."
|
||||||
|
cd "$CLIENT_PATH"
|
||||||
|
git fetch origin main
|
||||||
|
git reset --hard origin/main
|
||||||
|
|
||||||
|
# 2. Instalar dependências
|
||||||
|
log "📦 Instalando dependências (npm install)..."
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# 3. Build cross-platform (Linux → Windows .exe)
|
||||||
|
log "⚙️ Buildando .exe para Windows via electron-builder (cross-compile)..."
|
||||||
|
npx electron-builder --win --x64 --publish never
|
||||||
|
|
||||||
|
# 4. Verificar se o build gerou os artefatos
|
||||||
|
if [ ! -d "$CLIENT_PATH/dist" ]; then
|
||||||
|
log "❌ ERRO: Pasta dist/ não encontrada após o build!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
EXE_COUNT=$(find "$CLIENT_PATH/dist" -name "*.exe" | wc -l)
|
||||||
|
YML_COUNT=$(find "$CLIENT_PATH/dist" -name "latest.yml" | wc -l)
|
||||||
|
|
||||||
|
if [ "$EXE_COUNT" -eq 0 ] || [ "$YML_COUNT" -eq 0 ]; then
|
||||||
|
log "❌ ERRO: Artefatos incompletos (exe: $EXE_COUNT, yml: $YML_COUNT)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "✅ Build concluído: $EXE_COUNT .exe(s), $YML_COUNT latest.yml"
|
||||||
|
|
||||||
|
# 5. Garantir que a pasta de updates existe na VPS 1
|
||||||
|
ssh -o BatchMode=yes -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_VPS} \
|
||||||
|
"mkdir -p ${UPDATES_PATH}"
|
||||||
|
|
||||||
|
# 6. Transferir binários para VPS 1
|
||||||
|
log "🚚 Transferindo binários para VPS 1 (${UPDATES_PATH})..."
|
||||||
|
rsync -avz --delete \
|
||||||
|
"$CLIENT_PATH/dist/"*.exe \
|
||||||
|
"$CLIENT_PATH/dist/"*.yml \
|
||||||
|
"$CLIENT_PATH/dist/"*.blockmap \
|
||||||
|
${PROD_USER}@${PROD_VPS}:${UPDATES_PATH}/ 2>/dev/null || \
|
||||||
|
rsync -avz \
|
||||||
|
"$CLIENT_PATH/dist/"*.exe \
|
||||||
|
"$CLIENT_PATH/dist/"*.yml \
|
||||||
|
${PROD_USER}@${PROD_VPS}:${UPDATES_PATH}/
|
||||||
|
|
||||||
|
log "✅ Build e distribuição do client concluídos com sucesso!"
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 341 KiB |
@@ -0,0 +1,396 @@
|
|||||||
|
const { app, BrowserWindow, Tray, Menu, ipcMain, shell, dialog } = require('electron');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const { fork } = require('child_process');
|
||||||
|
const { autoUpdater } = require('electron-updater');
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// AUTO-UPDATER CONFIG
|
||||||
|
// ================================================================
|
||||||
|
autoUpdater.autoDownload = true;
|
||||||
|
autoUpdater.autoInstallOnAppQuit = true;
|
||||||
|
autoUpdater.logger = require('electron').app ? console : null;
|
||||||
|
|
||||||
|
autoUpdater.on('checking-for-update', () => {
|
||||||
|
console.log('🔍 Verificando atualizações...');
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-available', (info) => {
|
||||||
|
console.log('🔄 Nova versão disponível:', info.version);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-not-available', () => {
|
||||||
|
console.log('✅ Aplicativo está na versão mais recente.');
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('download-progress', (progress) => {
|
||||||
|
console.log(`⬇️ Baixando atualização: ${Math.round(progress.percent)}%`);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-downloaded', (info) => {
|
||||||
|
console.log('✅ Atualização baixada:', info.version, '— será instalada ao fechar o app.');
|
||||||
|
// Notificar o usuário na tray
|
||||||
|
if (tray) {
|
||||||
|
tray.displayBalloon({
|
||||||
|
title: 'ScoreOdonto - Atualização Pronta',
|
||||||
|
content: `Versão ${info.version} será instalada automaticamente ao fechar o aplicativo.`,
|
||||||
|
iconType: 'info'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('error', (err) => {
|
||||||
|
console.error('❌ Erro no auto-updater:', err.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
let tray = null;
|
||||||
|
let configWindow = null;
|
||||||
|
let monitorProcess = null;
|
||||||
|
let currentStatus = { connected: false, identified: false };
|
||||||
|
|
||||||
|
const appDataFolder = app.getPath('userData');
|
||||||
|
const configPath = path.join(appDataFolder, 'config.json');
|
||||||
|
|
||||||
|
// Ensure directory exists
|
||||||
|
if (!fs.existsSync(appDataFolder)) {
|
||||||
|
fs.mkdirSync(appDataFolder, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default config template
|
||||||
|
const defaultConfig = {
|
||||||
|
serverUrl: "https://rx.scoreodonto.com",
|
||||||
|
monitorPath: "C:\\ProgramData\\RF\\Dental Sensor\\Images",
|
||||||
|
clientName: "DIGITE-O-NOME-DA-MAQUINA",
|
||||||
|
clientType: "windows",
|
||||||
|
apiKey: "rf-dental-secure-key-2026",
|
||||||
|
serverEmail: "",
|
||||||
|
serverPassword: "",
|
||||||
|
token: "",
|
||||||
|
adminUsername: "admin",
|
||||||
|
adminPassword: "admin"
|
||||||
|
};
|
||||||
|
|
||||||
|
function loadConfig() {
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2), 'utf8');
|
||||||
|
return defaultConfig;
|
||||||
|
}
|
||||||
|
const userConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||||
|
// Ensure required fields exist
|
||||||
|
return { ...defaultConfig, ...userConfig };
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error loading config:", e);
|
||||||
|
return defaultConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveConfig(newConfig) {
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(newConfig, null, 2), 'utf8');
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error saving config:", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start background child process
|
||||||
|
function startMonitorProcess() {
|
||||||
|
if (monitorProcess) {
|
||||||
|
monitorProcess.kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = loadConfig();
|
||||||
|
// Don't start if it's default/placeholder
|
||||||
|
if (!config.clientName || config.clientName === defaultConfig.clientName) {
|
||||||
|
console.log("Monitor process not started: clientName not configured.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Starting client-monitor.js as background process...");
|
||||||
|
monitorProcess = fork(path.join(__dirname, 'client-monitor.js'), [], {
|
||||||
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
DENTAL_CONFIG_DIR: appDataFolder
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
monitorProcess.on('message', (message) => {
|
||||||
|
if (message && message.event === 'status') {
|
||||||
|
currentStatus.connected = message.connected;
|
||||||
|
currentStatus.identified = message.identified;
|
||||||
|
updateTrayMenu();
|
||||||
|
} else if (message && message.event === 'log') {
|
||||||
|
if (configWindow && !configWindow.isDestroyed()) {
|
||||||
|
configWindow.webContents.send('new-log', message.log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
monitorProcess.on('exit', (code) => {
|
||||||
|
console.log(`Monitor process exited with code ${code}`);
|
||||||
|
currentStatus.connected = false;
|
||||||
|
currentStatus.identified = false;
|
||||||
|
updateTrayMenu();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createConfigWindow() {
|
||||||
|
if (configWindow) {
|
||||||
|
configWindow.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
configWindow = new BrowserWindow({
|
||||||
|
width: 600,
|
||||||
|
height: 680,
|
||||||
|
minHeight: 520,
|
||||||
|
title: "ScoreOdonto Dental Client - Configuração",
|
||||||
|
icon: path.join(__dirname, 'favicon.png'),
|
||||||
|
resizable: true,
|
||||||
|
maximizable: true,
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
|
contextIsolation: true,
|
||||||
|
nodeIntegration: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
configWindow.loadFile(path.join(__dirname, 'config-ui.html'));
|
||||||
|
|
||||||
|
configWindow.on('closed', () => {
|
||||||
|
configWindow = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTrayMenu() {
|
||||||
|
if (!tray) return;
|
||||||
|
|
||||||
|
let statusText = "ScoreOdonto: Desconectado 🔴";
|
||||||
|
if (currentStatus.connected) {
|
||||||
|
statusText = currentStatus.identified
|
||||||
|
? "ScoreOdonto: Identificado 🟢"
|
||||||
|
: "ScoreOdonto: Conectado... 🟡";
|
||||||
|
}
|
||||||
|
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{ label: statusText, enabled: false },
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Forçar Sincronização 🔄',
|
||||||
|
click: () => {
|
||||||
|
if (monitorProcess) {
|
||||||
|
monitorProcess.send({ command: 'sync' });
|
||||||
|
} else {
|
||||||
|
startMonitorProcess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Verificar Atualizações 🔄',
|
||||||
|
click: () => {
|
||||||
|
autoUpdater.checkForUpdatesAndNotify();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Configurações ⚙️',
|
||||||
|
click: () => {
|
||||||
|
createConfigWindow();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Abrir Pasta de Imagens 📂',
|
||||||
|
click: () => {
|
||||||
|
const config = loadConfig();
|
||||||
|
if (fs.existsSync(config.monitorPath)) {
|
||||||
|
shell.openPath(config.monitorPath);
|
||||||
|
} else {
|
||||||
|
shell.openPath(path.dirname(config.monitorPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Sair 🚪',
|
||||||
|
click: () => {
|
||||||
|
app.isQuitting = true;
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
tray.setContextMenu(contextMenu);
|
||||||
|
tray.setToolTip(`ScoreOdonto Dental Client\n${statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initTray() {
|
||||||
|
const iconPath = path.join(__dirname, 'favicon.png');
|
||||||
|
tray = new Tray(iconPath);
|
||||||
|
updateTrayMenu();
|
||||||
|
|
||||||
|
tray.on('double-click', () => {
|
||||||
|
createConfigWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single instance lock
|
||||||
|
const gotTheLock = app.requestSingleInstanceLock();
|
||||||
|
if (!gotTheLock) {
|
||||||
|
app.quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.on('second-instance', () => {
|
||||||
|
if (configWindow) {
|
||||||
|
if (configWindow.isMinimized()) configWindow.restore();
|
||||||
|
configWindow.focus();
|
||||||
|
} else {
|
||||||
|
createConfigWindow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
initTray();
|
||||||
|
|
||||||
|
// Verificar atualizações silenciosamente ao iniciar
|
||||||
|
autoUpdater.checkForUpdatesAndNotify();
|
||||||
|
|
||||||
|
const config = loadConfig();
|
||||||
|
// If not configured, show config UI
|
||||||
|
if (!config.clientName || config.clientName === defaultConfig.clientName) {
|
||||||
|
createConfigWindow();
|
||||||
|
} else {
|
||||||
|
// Start background process
|
||||||
|
startMonitorProcess();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
// Keep running in tray on close
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
// do nothing, let it run in tray
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('before-quit', () => {
|
||||||
|
if (monitorProcess) {
|
||||||
|
monitorProcess.kill();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// IPC communication
|
||||||
|
ipcMain.handle('get-config', () => {
|
||||||
|
return loadConfig();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('save-config', (event, newConfig) => {
|
||||||
|
const success = saveConfig(newConfig);
|
||||||
|
if (success) {
|
||||||
|
// Restart child process with new settings
|
||||||
|
startMonitorProcess();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('test-server', async (event, url) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
try {
|
||||||
|
const checkUrl = url.endsWith('/') ? `${url}status` : `${url}/status`;
|
||||||
|
const clientModule = checkUrl.startsWith('https') ? require('https') : require('http');
|
||||||
|
const req = clientModule.get(checkUrl, { timeout: 4000 }, (res) => {
|
||||||
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||||
|
resolve({ success: true, message: `Conexão bem sucedida! Código: ${res.statusCode}` });
|
||||||
|
} else {
|
||||||
|
resolve({ success: false, error: `Código de status inesperado: ${res.statusCode}` });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.on('error', (err) => {
|
||||||
|
resolve({ success: false, error: err.message });
|
||||||
|
});
|
||||||
|
req.on('timeout', () => {
|
||||||
|
req.destroy();
|
||||||
|
resolve({ success: false, error: 'Timeout de 4 segundos esgotado.' });
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
resolve({ success: false, error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('verify-credentials', async (event, url, email, password, token) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
try {
|
||||||
|
let base = url.trim();
|
||||||
|
if (base.endsWith('/')) {
|
||||||
|
base = base.slice(0, -1);
|
||||||
|
}
|
||||||
|
const verifyUrl = `${base}/api/auth/verify-client-credentials`;
|
||||||
|
const clientModule = verifyUrl.startsWith('https') ? require('https') : require('http');
|
||||||
|
const parsedUrl = new URL(verifyUrl);
|
||||||
|
|
||||||
|
const postData = JSON.stringify({ email, password, token });
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
hostname: parsedUrl.hostname,
|
||||||
|
port: parsedUrl.port || (verifyUrl.startsWith('https') ? 443 : 80),
|
||||||
|
path: parsedUrl.pathname,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Content-Length': Buffer.byteLength(postData)
|
||||||
|
},
|
||||||
|
timeout: 8000
|
||||||
|
};
|
||||||
|
|
||||||
|
const req = clientModule.request(options, (res) => {
|
||||||
|
let body = '';
|
||||||
|
res.on('data', (chunk) => body += chunk);
|
||||||
|
res.on('end', () => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(body);
|
||||||
|
if (res.statusCode >= 200 && res.statusCode < 300 && data.success) {
|
||||||
|
resolve({ success: true, clinic: data.clinic });
|
||||||
|
} else {
|
||||||
|
resolve({ success: false, error: data.error || `Erro de validação: ${res.statusCode}` });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
resolve({ success: false, error: `Resposta inválida do servidor: ${e.message}` });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', (err) => {
|
||||||
|
resolve({ success: false, error: `Falha de rede: ${err.message}` });
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('timeout', () => {
|
||||||
|
req.destroy();
|
||||||
|
resolve({ success: false, error: 'Tempo limite esgotado ao tentar validar credenciais (8s).' });
|
||||||
|
});
|
||||||
|
|
||||||
|
req.write(postData);
|
||||||
|
req.end();
|
||||||
|
} catch (e) {
|
||||||
|
resolve({ success: false, error: `Erro interno: ${e.message}` });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('open-folder', () => {
|
||||||
|
const config = loadConfig();
|
||||||
|
const targetPath = config.monitorPath;
|
||||||
|
if (!fs.existsSync(targetPath)) {
|
||||||
|
fs.mkdirSync(targetPath, { recursive: true });
|
||||||
|
}
|
||||||
|
shell.openPath(targetPath);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('close-window', () => {
|
||||||
|
if (configWindow) {
|
||||||
|
configWindow.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
@echo off
|
||||||
|
title Dental Client - Monitor
|
||||||
|
echo Iniciando Dental Client...
|
||||||
|
node client-monitor.js
|
||||||
|
pause
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "dental-client",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"description": "Cliente Windows para envio de imagens dentais da ScoreOdonto",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron .",
|
||||||
|
"dist": "electron-builder"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"chokidar": "^3.5.3",
|
||||||
|
"electron-updater": "^6.3.0",
|
||||||
|
"sharp": "^0.34.5",
|
||||||
|
"socket.io-client": "^4.7.5"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"appId": "com.scoreodonto.dentalclient",
|
||||||
|
"productName": "ScoreOdonto Dental Client",
|
||||||
|
"win": {
|
||||||
|
"target": "nsis",
|
||||||
|
"icon": "favicon.png"
|
||||||
|
},
|
||||||
|
"nsis": {
|
||||||
|
"oneClick": true,
|
||||||
|
"perMachine": true,
|
||||||
|
"allowToChangeInstallationDirectory": false,
|
||||||
|
"createDesktopShortcut": true,
|
||||||
|
"createStartMenuShortcut": true,
|
||||||
|
"shortcutName": "ScoreOdonto Dental Client"
|
||||||
|
},
|
||||||
|
"publish": [
|
||||||
|
{
|
||||||
|
"provider": "generic",
|
||||||
|
"url": "https://rx.scoreodonto.com/updates/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"**/*",
|
||||||
|
"!docs-client/**/*",
|
||||||
|
"!Output/**/*",
|
||||||
|
"!dist/**/*"
|
||||||
|
],
|
||||||
|
"asar": false
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"electron": "^42.2.0",
|
||||||
|
"electron-builder": "^26.8.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
const { contextBridge, ipcRenderer } = require('electron');
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld('api', {
|
||||||
|
getConfig: () => ipcRenderer.invoke('get-config'),
|
||||||
|
saveConfig: (config) => ipcRenderer.invoke('save-config', config),
|
||||||
|
testServer: (url) => ipcRenderer.invoke('test-server', url),
|
||||||
|
verifyCredentials: (url, email, password, token) => ipcRenderer.invoke('verify-credentials', url, email, password, token),
|
||||||
|
openFolder: () => ipcRenderer.invoke('open-folder'),
|
||||||
|
closeWindow: () => ipcRenderer.send('close-window'),
|
||||||
|
onLog: (callback) => ipcRenderer.on('new-log', (event, log) => callback(log))
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user