diff --git a/electron/main.js b/electron/main.js index 32954cc..4885f8b 100644 --- a/electron/main.js +++ b/electron/main.js @@ -7,6 +7,7 @@ const { app, BrowserWindow, ipcMain, Menu, Tray, dialog } = require('electron'); const path = require('path'); const { spawn } = require('child_process'); const http = require('http'); +const https = require('https'); const setupHelper = require('./setup-helper'); // État de l'application @@ -17,7 +18,11 @@ let serverStarted = false; let rendererReady = false; const SERVER_PORT = process.env.PORT || 3000; -const SERVER_URL = `http://localhost:${SERVER_PORT}`; +// HTTPS activé par défaut (cohérent avec le setup mkcert automatique au premier +// lancement) ; ENABLE_HTTPS=false permet de revenir explicitement en HTTP +const ENABLE_HTTPS = process.env.ENABLE_HTTPS !== 'false'; +const SERVER_PROTOCOL = ENABLE_HTTPS ? 'https' : 'http'; +const SERVER_URL = `${SERVER_PROTOCOL}://localhost:${SERVER_PORT}`; const isDev = process.argv.includes('--dev'); /** @@ -133,6 +138,7 @@ async function startServer() { ...process.env, PORT: SERVER_PORT, USE_LOCAL_LIVEKIT: 'true', + ENABLE_HTTPS: ENABLE_HTTPS ? 'true' : 'false', NODE_ENV: isDev ? 'development' : 'production' } }); @@ -289,7 +295,13 @@ async function stopServer() { */ async function pingServer() { return new Promise((resolve) => { - http.get(`${SERVER_URL}/health`, (res) => { + const client = ENABLE_HTTPS ? https : http; + // rejectUnauthorized: false : le cert mkcert est approuvé par le Keychain + // macOS (Safari/Chrome/Electron renderer), mais le module https de Node + // ne lit pas ce trust store et rejetterait sinon ce ping vers notre + // propre serveur local. + const options = ENABLE_HTTPS ? { rejectUnauthorized: false } : {}; + client.get(`${SERVER_URL}/health`, options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { diff --git a/electron/preload.js b/electron/preload.js index aa69be0..dc6f5a9 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -5,8 +5,15 @@ const { contextBridge, ipcRenderer } = require('electron'); +// Même logique que dans main.js : doit rester synchronisé avec SERVER_URL +const SERVER_PORT = process.env.PORT || 3000; +const ENABLE_HTTPS = process.env.ENABLE_HTTPS !== 'false'; +const SERVER_URL = `${ENABLE_HTTPS ? 'https' : 'http'}://localhost:${SERVER_PORT}`; + // Exposer l'API au renderer de manière sécurisée contextBridge.exposeInMainWorld('electronAPI', { + serverUrl: SERVER_URL, + // Contrôle serveur server: { start: () => ipcRenderer.invoke('server:start'), diff --git a/electron/ui/app.js b/electron/ui/app.js index ebd7e71..e1b71c2 100644 --- a/electron/ui/app.js +++ b/electron/ui/app.js @@ -2,7 +2,7 @@ * PTT Live Desktop - Renderer Process Logic */ -const API_BASE = 'http://localhost:3000'; +const API_BASE = window.electronAPI?.serverUrl || 'http://localhost:3000'; // État global let serverRunning = false; @@ -604,7 +604,7 @@ function connectAudioLevelsWS() { return; } - const wsUrl = 'ws://localhost:3000/audio-levels'; + const wsUrl = API_BASE.replace(/^http/, 'ws') + '/audio-levels'; console.log('Connexion WebSocket audio-levels...', wsUrl); try {