From 54cfba5cc463dbd3634927c85c32063fc7b8bf76 Mon Sep 17 00:00:00 2001 From: Eder Moraes <54563944+edermcastro@users.noreply.github.com> Date: Sat, 12 Jul 2025 12:26:16 -0300 Subject: [PATCH] =?UTF-8?q?adicionado=20menu=20de=20contexto=20com=20op?= =?UTF-8?q?=C3=A7=C3=B5es=20para=20chamar=20fila,=20trocar=20de=20colab=20?= =?UTF-8?q?e=20sair=20do=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- floating.js | 6 ++++ floating_preload.js | 5 ++-- main.js | 69 +++++++++++++++++++++++++++++++++++++++------ package.json | 2 +- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/floating.js b/floating.js index 4b8405a..ca8c128 100644 --- a/floating.js +++ b/floating.js @@ -17,5 +17,11 @@ floatButton.addEventListener('click', () => { window.electronAPI.showMainWindow(); }); +// Adiciona um listener para o evento de clique com o botão direito +floatButton.addEventListener('contextmenu', (e) => { + e.preventDefault(); // Impede o menu padrão do navegador + window.electronAPI.showMenu(); // Chama a função para mostrar o menu no processo principal +}); + // Ajuste inicial do cursor floatButton.style.cursor = 'pointer'; \ No newline at end of file diff --git a/floating_preload.js b/floating_preload.js index ec52cf3..dd8c71b 100644 --- a/floating_preload.js +++ b/floating_preload.js @@ -2,7 +2,6 @@ const { contextBridge, ipcRenderer } = require('electron'); contextBridge.exposeInMainWorld('electronAPI', { onUpdateCount: (callback) => ipcRenderer.on('update-count', (_event, value) => callback(value)), - showMainWindow: () => ipcRenderer.send('chamar-fila') - // Remova a linha abaixo: - // startDrag: (offset) => ipcRenderer.send('drag-float-window', offset) + showMainWindow: () => ipcRenderer.send('chamar-fila'), + showMenu: () => ipcRenderer.send('show-context-menu') }); \ No newline at end of file diff --git a/main.js b/main.js index 7065f1a..7dfc278 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, ipcMain, screen, net, dialog } = require('electron'); +const { app, BrowserWindow, ipcMain, screen, net, dialog, Menu } = require('electron'); // const { app: singleInstanceLock } = require('electron-single-instance'); const path = require('path'); const fs = require('fs'); @@ -877,12 +877,65 @@ ipcMain.on('token-exists', async () => { ipcMain.on('sair', ()=>{ - operatorWin.webContents.executeJavaScript(` - localStorage.removeItem("idOperator"); - localStorage.removeItem("selectedOperator"); - localStorage.removeItem("salaOperator"); - localStorage.removeItem("servicosOperator"); - `).then(() => { - app.exit(); + let exec = ` + localStorage.removeItem("idOperator"); + localStorage.removeItem("selectedOperator"); + localStorage.removeItem("salaOperator"); + localStorage.removeItem("servicosOperator"); + `; + + let options = { + 'title': 'Deseja realmente sair?', + 'message': 'Tem certeza que deseja fechar o Auto Atendimento?', + 'type': 'question', + 'buttons': ['Não', 'Sim'], + 'defaultId': 0, + 'cancelId': 0, + }; + + dialog.showMessageBox(floatingWin, options).then(result => { + if (result.response === 1) { // Se o usuário clicou em "Sim" (índice 1) + if (floatingWin) { + floatingWin.webContents.executeJavaScript(exec).then(() => { app.exit(); }); + } else if (operatorWin) { + operatorWin.webContents.executeJavaScript(exec).then(() => { app.exit(); }); + } + } }); + +}); + + +ipcMain.on('show-context-menu', (event) => { + const template = [ + { + label: 'Chamar Fila', + click: () => { + // Lógica para chamar atendimento + if (floatingWin) { + ipcMain.emit('chamar-fila'); + } + } + }, + { + label: 'Trocar Colab', + click: () => { + // Lógica para chamar atendimento + if (floatingWin) { + ipcMain.emit('logout'); + } + } + }, + { + label: 'Sair', + click: () => { + // Lógica para fechar o aplicativo + if (floatingWin) { + ipcMain.emit('sair'); + } + } + } + ]; + const menu = Menu.buildFromTemplate(template); + menu.popup({ window: floatingWin }); }); \ No newline at end of file diff --git a/package.json b/package.json index e4962d5..dd6c48a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "autoatendcolab", - "version": "1.1.0", + "version": "1.1.1", "main": "main.js", "isBuildNow": true, "scripts": {