From 20d72fd6569982ff45b25722f76182da8c180781 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:35:23 -0600 Subject: [PATCH 01/11] Firmar app --- .github/workflows/build.yml | 48 +++++++++++++++++++++++++++++++++++ harvester-app/.gitignore | 6 +++++ harvester-app/forge.config.js | 9 ++++++- harvester-app/src/main.js | 26 ++++++++++--------- 4 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..fd86a50f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,48 @@ +name: Build and Sign Windows App + +on: + push: + branches: [ develop ] + tags: + - 'v*' + pull_request: + branches: [ develop ] + workflow_dispatch: + +jobs: + build-windows: + runs-on: windows-latest + + steps: + - name: Checkout código + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + + - name: Install dependencies + run: cd harvester-app && npm install + + - name: Decodificar certificado + env: + CERTIFICATE_BASE64: ${{ secrets.WINDOWS_CERT_BASE64 }} + run: | + echo "$env:CERTIFICATE_BASE64" | base64 -d > certificate.pfx + shell: bash + + - name: Construir y firmar app + env: + WINDOWS_CERT_PASSWORD: ${{ secrets.WINDOWS_CERT_PASSWORD }} + CI: true + run: cd harvester-app && npm run make + + - name: Subir instalador + uses: actions/upload-artifact@v3 + with: + name: windows-installer + path: | + out/make/squirrel.windows/**/*.exe + out/make/squirrel.windows/**/*.nupkg + out/make/squirrel.windows/**/RELEASES \ No newline at end of file diff --git a/harvester-app/.gitignore b/harvester-app/.gitignore index a9d7914c..6439297e 100644 --- a/harvester-app/.gitignore +++ b/harvester-app/.gitignore @@ -88,6 +88,12 @@ typings/ # Vite .vite/ +# Certificados +cert/ +*.pfx +*.p12 +cert-base64.txt + # Electron-Forge out/ diff --git a/harvester-app/forge.config.js b/harvester-app/forge.config.js index 82938ba3..9638ed11 100644 --- a/harvester-app/forge.config.js +++ b/harvester-app/forge.config.js @@ -10,7 +10,14 @@ module.exports = { makers: [ { name: '@electron-forge/maker-squirrel', - config: {}, + config: { + name: 'Harvester', + authors: 'TracTech', + exe: 'Harvester.exe', + certificateFile: './cert/certificado.pfx', + certificatePassword: 'Harvester123', + signWithParams: '/tr http://timestamp.digicert.com /td sha256 /fd sha256 /a' + }, }, { name: '@electron-forge/maker-zip', diff --git a/harvester-app/src/main.js b/harvester-app/src/main.js index 08e6cf59..51e05e76 100644 --- a/harvester-app/src/main.js +++ b/harvester-app/src/main.js @@ -200,20 +200,22 @@ app.on('window-all-closed', () => { }); // Manejar la apertura del diálogo de selección de archivos cuando se descarga un pdf -ipcMain.on('guardar-pdf', async (evento, bufer) => { - const resultado = await dialog.showSaveDialog(mainWindow, { - title: 'Guardar PDF', - defaultPath: 'reporte.pdf', - filters: [ - { name: 'PDF', extensions: ['pdf'] } - ] +ipcMain.on('guardar-pdf', async (event, buffer) => { + const { canceled, filePath } = await dialog.showSaveDialog({ + title: 'Guardar reporte PDF', + defaultPath: path.join(os.homedir(), 'Downloads', 'reporte.pdf'), + filters: [{ name: 'PDF', extensions: ['pdf'] }] }); - - if (!resultado.canceled) { - fs.writeFileSync(resultado.filePath, bufer); + if (canceled) { + event.reply('pdf-guardado', false); + return; + } + try { + fs.writeFileSync(filePath, buffer); + event.reply('pdf-guardado', true); + } catch (error) { + event.reply('pdf-guardado', false); } - - evento.sender.send('pdf-guardado', !resultado.canceled); }); ipcMain.handle('precargar-ejs', async (event, rutaEJS, parametros) => { From 4c9c4e133734838d9903a377dbb58428ac1f3554 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:37:27 -0600 Subject: [PATCH 02/11] Cambiar workflow --- .github/workflows/build.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fd86a50f..0d6b1a76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,13 +1,7 @@ name: Build and Sign Windows App on: - push: - branches: [ develop ] - tags: - - 'v*' pull_request: - branches: [ develop ] - workflow_dispatch: jobs: build-windows: From 6d8be77c09ab0dce7dce167d9d5fc7d0aaac8de4 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:39:40 -0600 Subject: [PATCH 03/11] Eslint --- harvester-app/src/main.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/harvester-app/src/main.js b/harvester-app/src/main.js index 51e05e76..08e6cf59 100644 --- a/harvester-app/src/main.js +++ b/harvester-app/src/main.js @@ -200,22 +200,20 @@ app.on('window-all-closed', () => { }); // Manejar la apertura del diálogo de selección de archivos cuando se descarga un pdf -ipcMain.on('guardar-pdf', async (event, buffer) => { - const { canceled, filePath } = await dialog.showSaveDialog({ - title: 'Guardar reporte PDF', - defaultPath: path.join(os.homedir(), 'Downloads', 'reporte.pdf'), - filters: [{ name: 'PDF', extensions: ['pdf'] }] +ipcMain.on('guardar-pdf', async (evento, bufer) => { + const resultado = await dialog.showSaveDialog(mainWindow, { + title: 'Guardar PDF', + defaultPath: 'reporte.pdf', + filters: [ + { name: 'PDF', extensions: ['pdf'] } + ] }); - if (canceled) { - event.reply('pdf-guardado', false); - return; - } - try { - fs.writeFileSync(filePath, buffer); - event.reply('pdf-guardado', true); - } catch (error) { - event.reply('pdf-guardado', false); + + if (!resultado.canceled) { + fs.writeFileSync(resultado.filePath, bufer); } + + evento.sender.send('pdf-guardado', !resultado.canceled); }); ipcMain.handle('precargar-ejs', async (event, rutaEJS, parametros) => { From 4b0c407ae4aaf36f678d0327718f3788a2bf7c74 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:41:50 -0600 Subject: [PATCH 04/11] Arreglar workflow --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d6b1a76..6a2720ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,12 +12,12 @@ jobs: uses: actions/checkout@v3 - name: Set up Node.js - uses: actions/setup-node@v3 - with: + uses: actions/setup-node@v3 + with: node-version: 20.x - name: Install dependencies - run: cd harvester-app && npm install + run: cd harvester-app && npm install - name: Decodificar certificado env: From c6558060d82da92d7165850238566d3b127ca543 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:44:27 -0600 Subject: [PATCH 05/11] Workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a2720ea..d9f6292a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: jobs: build-windows: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - name: Checkout código From b01590b671417e30d61bd17d6827342d0bd06f44 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:46:29 -0600 Subject: [PATCH 06/11] workflow --- .github/workflows/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9f6292a..6daaaa03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,14 +5,14 @@ on: jobs: build-windows: - runs-on: ubuntu-latest + runs-on: windows-latest # CAMBIADO: Necesitas Windows steps: - name: Checkout código - uses: actions/checkout@v3 + uses: actions/checkout@v4 # ACTUALIZADO a v4 - name: Set up Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 # ACTUALIZADO a v4 with: node-version: 20.x @@ -23,7 +23,7 @@ jobs: env: CERTIFICATE_BASE64: ${{ secrets.WINDOWS_CERT_BASE64 }} run: | - echo "$env:CERTIFICATE_BASE64" | base64 -d > certificate.pfx + echo $env:CERTIFICATE_BASE64 | base64 -d > harvester-app/certificate.pfx shell: bash - name: Construir y firmar app @@ -33,10 +33,10 @@ jobs: run: cd harvester-app && npm run make - name: Subir instalador - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 # ACTUALIZADO a v4 with: name: windows-installer path: | - out/make/squirrel.windows/**/*.exe - out/make/squirrel.windows/**/*.nupkg - out/make/squirrel.windows/**/RELEASES \ No newline at end of file + harvester-app/out/make/squirrel.windows/**/*.exe + harvester-app/out/make/squirrel.windows/**/*.nupkg + harvester-app/out/make/squirrel.windows/**/RELEASES \ No newline at end of file From 1becbc582623b58d8d52897c332e414a0c5e6027 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:49:49 -0600 Subject: [PATCH 07/11] workflow --- .github/workflows/build.yml | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6daaaa03..1dafcccd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,41 +2,66 @@ name: Build and Sign Windows App on: pull_request: + workflow_dispatch: jobs: build-windows: - runs-on: windows-latest # CAMBIADO: Necesitas Windows + runs-on: windows-latest steps: - name: Checkout código - uses: actions/checkout@v4 # ACTUALIZADO a v4 + uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v4 # ACTUALIZADO a v4 + uses: actions/setup-node@v4 with: node-version: 20.x - name: Install dependencies run: cd harvester-app && npm install + - name: Verificar secretos + run: | + echo "Verificando secretos..." + if ("${{ secrets.WINDOWS_CERT_BASE64 }}" -eq "") { + Write-Error "❌ WINDOWS_CERT_BASE64 no está configurado" + exit 1 + } + if ("${{ secrets.WINDOWS_CERT_PASSWORD }}" -eq "") { + Write-Error "❌ WINDOWS_CERT_PASSWORD no está configurado" + exit 1 + } + echo "✅ Todos los secretos están configurados" + shell: pwsh + - name: Decodificar certificado + working-directory: harvester-app env: CERTIFICATE_BASE64: ${{ secrets.WINDOWS_CERT_BASE64 }} run: | - echo $env:CERTIFICATE_BASE64 | base64 -d > harvester-app/certificate.pfx - shell: bash + try { + $certBytes = [System.Convert]::FromBase64String($env:CERTIFICATE_BASE64) + [System.IO.File]::WriteAllBytes("certificate.pfx", $certBytes) + echo "✅ Certificado decodificado: $(Get-Item certificate.pfx).Length bytes" + } catch { + Write-Error "❌ Error al decodificar el certificado: $_" + exit 1 + } + shell: pwsh - name: Construir y firmar app + working-directory: harvester-app env: WINDOWS_CERT_PASSWORD: ${{ secrets.WINDOWS_CERT_PASSWORD }} CI: true - run: cd harvester-app && npm run make + run: npm run make - name: Subir instalador - uses: actions/upload-artifact@v4 # ACTUALIZADO a v4 + uses: actions/upload-artifact@v4 with: name: windows-installer path: | - harvester-app/out/make/squirrel.windows/**/*.exe - harvester-app/out/make/squirrel.windows/**/*.nupkg - harvester-app/out/make/squirrel.windows/**/RELEASES \ No newline at end of file + harvester-app/out/make/**/*.exe + harvester-app/out/make/**/*.nupkg + harvester-app/out/make/**/RELEASES + if-no-files-found: error \ No newline at end of file From 1a994b262421719c0a5c5053fc558bc9b6ebb813 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 22:56:11 -0600 Subject: [PATCH 08/11] forge config --- harvester-app/forge.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/harvester-app/forge.config.js b/harvester-app/forge.config.js index 9638ed11..ba17c4bd 100644 --- a/harvester-app/forge.config.js +++ b/harvester-app/forge.config.js @@ -16,7 +16,6 @@ module.exports = { exe: 'Harvester.exe', certificateFile: './cert/certificado.pfx', certificatePassword: 'Harvester123', - signWithParams: '/tr http://timestamp.digicert.com /td sha256 /fd sha256 /a' }, }, { From 81e63b45686b4a664f8ca0fada589ba3fb02b685 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 23:01:44 -0600 Subject: [PATCH 09/11] workflow --- .github/workflows/build.yml | 29 +++++++++++++++++++++++++++-- harvester-app/src/main.js | 27 +++++++++++++++------------ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1dafcccd..75ea6343 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,15 +40,40 @@ jobs: CERTIFICATE_BASE64: ${{ secrets.WINDOWS_CERT_BASE64 }} run: | try { + # Crear la carpeta cert si no existe + New-Item -ItemType Directory -Force -Path "cert" + + # Guardar el certificado donde forge.config.js lo espera $certBytes = [System.Convert]::FromBase64String($env:CERTIFICATE_BASE64) - [System.IO.File]::WriteAllBytes("certificate.pfx", $certBytes) - echo "✅ Certificado decodificado: $(Get-Item certificate.pfx).Length bytes" + [System.IO.File]::WriteAllBytes("cert\certificado.pfx", $certBytes) + echo "✅ Certificado decodificado: $(Get-Item cert\certificado.pfx).Length bytes" } catch { Write-Error "❌ Error al decodificar el certificado: $_" exit 1 } shell: pwsh + - name: Verificar estructura y certificado + working-directory: harvester-app + run: | + echo "=== Verificando estructura ===" + if (Test-Path "cert\certificado.pfx") { + echo "✅ cert\certificado.pfx existe" + + # Intentar verificar el certificado + try { + $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("cert\certificado.pfx", "${{ secrets.WINDOWS_CERT_PASSWORD }}") + echo "✅ Certificado válido" + echo "Subject: $($cert.Subject)" + } catch { + echo "⚠️ No se pudo verificar el certificado (esto es normal con certificados auto-firmados)" + } + } else { + echo "❌ No se encontró cert\certificado.pfx" + exit 1 + } + shell: pwsh + - name: Construir y firmar app working-directory: harvester-app env: diff --git a/harvester-app/src/main.js b/harvester-app/src/main.js index 08e6cf59..48e8c1f8 100644 --- a/harvester-app/src/main.js +++ b/harvester-app/src/main.js @@ -5,6 +5,7 @@ const {precargarEJS} = require('./framework/utils/scripts/middleware/precargarEJ const { verificarEstado } = require('./backend/servicios/verificarEstado'); const { obtenerID } = require('./backend/servicios/generadorID'); const { PERMISOS } = require('./framework/utils/scripts/middleware/auth'); +const os = require('os'); const INTERVALOTIEMPO = 120000; // 2 minutos en milisegundos @@ -200,20 +201,22 @@ app.on('window-all-closed', () => { }); // Manejar la apertura del diálogo de selección de archivos cuando se descarga un pdf -ipcMain.on('guardar-pdf', async (evento, bufer) => { - const resultado = await dialog.showSaveDialog(mainWindow, { - title: 'Guardar PDF', - defaultPath: 'reporte.pdf', - filters: [ - { name: 'PDF', extensions: ['pdf'] } - ] +ipcMain.on('guardar-pdf', async (event, buffer) => { + const { canceled, filePath } = await dialog.showSaveDialog({ + title: 'Guardar reporte PDF', + defaultPath: path.join(os.homedir(), 'Downloads', 'reporte.pdf'), + filters: [{ name: 'PDF', extensions: ['pdf'] }] }); - - if (!resultado.canceled) { - fs.writeFileSync(resultado.filePath, bufer); + if (canceled) { + event.reply('pdf-guardado', false); + return; + } + try { + fs.writeFileSync(filePath, buffer); + event.reply('pdf-guardado', true); + } catch { + event.reply('pdf-guardado', false); // <-- Elimina 'error' del catch } - - evento.sender.send('pdf-guardado', !resultado.canceled); }); ipcMain.handle('precargar-ejs', async (event, rutaEJS, parametros) => { From 5be420a7485f46cb614e7d75df10f473eb19fb64 Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 23:31:51 -0600 Subject: [PATCH 10/11] borrar workflow innecesario --- .github/workflows/build.yml | 92 ------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 75ea6343..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Build and Sign Windows App - -on: - pull_request: - workflow_dispatch: - -jobs: - build-windows: - runs-on: windows-latest - - steps: - - name: Checkout código - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: 20.x - - - name: Install dependencies - run: cd harvester-app && npm install - - - name: Verificar secretos - run: | - echo "Verificando secretos..." - if ("${{ secrets.WINDOWS_CERT_BASE64 }}" -eq "") { - Write-Error "❌ WINDOWS_CERT_BASE64 no está configurado" - exit 1 - } - if ("${{ secrets.WINDOWS_CERT_PASSWORD }}" -eq "") { - Write-Error "❌ WINDOWS_CERT_PASSWORD no está configurado" - exit 1 - } - echo "✅ Todos los secretos están configurados" - shell: pwsh - - - name: Decodificar certificado - working-directory: harvester-app - env: - CERTIFICATE_BASE64: ${{ secrets.WINDOWS_CERT_BASE64 }} - run: | - try { - # Crear la carpeta cert si no existe - New-Item -ItemType Directory -Force -Path "cert" - - # Guardar el certificado donde forge.config.js lo espera - $certBytes = [System.Convert]::FromBase64String($env:CERTIFICATE_BASE64) - [System.IO.File]::WriteAllBytes("cert\certificado.pfx", $certBytes) - echo "✅ Certificado decodificado: $(Get-Item cert\certificado.pfx).Length bytes" - } catch { - Write-Error "❌ Error al decodificar el certificado: $_" - exit 1 - } - shell: pwsh - - - name: Verificar estructura y certificado - working-directory: harvester-app - run: | - echo "=== Verificando estructura ===" - if (Test-Path "cert\certificado.pfx") { - echo "✅ cert\certificado.pfx existe" - - # Intentar verificar el certificado - try { - $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("cert\certificado.pfx", "${{ secrets.WINDOWS_CERT_PASSWORD }}") - echo "✅ Certificado válido" - echo "Subject: $($cert.Subject)" - } catch { - echo "⚠️ No se pudo verificar el certificado (esto es normal con certificados auto-firmados)" - } - } else { - echo "❌ No se encontró cert\certificado.pfx" - exit 1 - } - shell: pwsh - - - name: Construir y firmar app - working-directory: harvester-app - env: - WINDOWS_CERT_PASSWORD: ${{ secrets.WINDOWS_CERT_PASSWORD }} - CI: true - run: npm run make - - - name: Subir instalador - uses: actions/upload-artifact@v4 - with: - name: windows-installer - path: | - harvester-app/out/make/**/*.exe - harvester-app/out/make/**/*.nupkg - harvester-app/out/make/**/RELEASES - if-no-files-found: error \ No newline at end of file From 312ae39064fa6707ff8e8daa904b12f49a6bbaef Mon Sep 17 00:00:00 2001 From: DanielContrerasCh Date: Mon, 2 Jun 2025 23:32:43 -0600 Subject: [PATCH 11/11] Cambiar autores --- harvester-app/forge.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harvester-app/forge.config.js b/harvester-app/forge.config.js index ba17c4bd..635f0152 100644 --- a/harvester-app/forge.config.js +++ b/harvester-app/forge.config.js @@ -12,7 +12,7 @@ module.exports = { name: '@electron-forge/maker-squirrel', config: { name: 'Harvester', - authors: 'TracTech', + authors: 'Code&Co - TracTech', exe: 'Harvester.exe', certificateFile: './cert/certificado.pfx', certificatePassword: 'Harvester123',