Adicionado switch na tela de seleção do colaborador que permite ativar ou desativar auto inicio junto ao sistema operacional
This commit is contained in:
parent
e54015cfba
commit
96ac1510ae
45
main.js
45
main.js
|
|
@ -13,12 +13,47 @@ let operatorWin;
|
||||||
let updateWin;
|
let updateWin;
|
||||||
|
|
||||||
const dataPath = path.join(__dirname, 'data.json'); // Caminho para o JSON (backup local)
|
const dataPath = path.join(__dirname, 'data.json'); // Caminho para o JSON (backup local)
|
||||||
|
const settingsPath = path.join(app.getPath('userData'), 'settings.json'); // Caminho para as configurações
|
||||||
const apiUrl = 'https://autoatend.linco.work/api/v1/';
|
const apiUrl = 'https://autoatend.linco.work/api/v1/';
|
||||||
// const apiUrl = 'http://_lara10-autoatend.devel/api/v1/';
|
|
||||||
|
|
||||||
|
//? Função para ler as configurações
|
||||||
|
function getSettings() {
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(settingsPath)) {
|
||||||
|
const settingsData = fs.readFileSync(settingsPath, 'utf-8');
|
||||||
|
return JSON.parse(settingsData);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erro ao ler arquivo de configurações:', error);
|
||||||
|
}
|
||||||
|
return {}; // Retorna objeto vazio se o arquivo não existir ou houver erro
|
||||||
|
}
|
||||||
|
|
||||||
|
//? Função para salvar as configurações
|
||||||
|
function saveSettings(settings) {
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erro ao salvar arquivo de configurações:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.handle('get-setting', (event, key) => {
|
||||||
|
const settings = getSettings();
|
||||||
|
return settings[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('set-setting', (event, key, value) => {
|
||||||
|
const settings = getSettings();
|
||||||
|
settings[key] = value;
|
||||||
|
saveSettings(settings);
|
||||||
|
app.relaunch();
|
||||||
|
app.exit();
|
||||||
|
});
|
||||||
|
//! final de configurações
|
||||||
|
|
||||||
|
//!pusher
|
||||||
const pusherUrl = 'aa.linco.work';
|
const pusherUrl = 'aa.linco.work';
|
||||||
// const pusherUrl = 'localhost';
|
|
||||||
|
|
||||||
|
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
autoUpdater.autoInstallOnAppQuit = true;
|
autoUpdater.autoInstallOnAppQuit = true;
|
||||||
|
|
@ -352,7 +387,9 @@ if (!gotTheLock) {
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
|
||||||
//define a inicialização automatica do aplicativo ao entrar no windows
|
//define a inicialização automatica do aplicativo ao entrar no windows
|
||||||
setAutoLaunch(true);
|
const settings = getSettings();
|
||||||
|
const enableAutoStart = settings.autostart === undefined ? true : settings.autostart;
|
||||||
|
setAutoLaunch(enableAutoStart);
|
||||||
|
|
||||||
// Verifica se o usuário já está autenticado
|
// Verifica se o usuário já está autenticado
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
|
|
|
||||||
13
operator.js
13
operator.js
|
|
@ -3,9 +3,17 @@ const selectButton = document.getElementById('select-button');
|
||||||
const errorMessage = document.getElementById('error-message');
|
const errorMessage = document.getElementById('error-message');
|
||||||
const quitButton = document.getElementById('sair-button');
|
const quitButton = document.getElementById('sair-button');
|
||||||
const verionSpan = document.getElementById('version');
|
const verionSpan = document.getElementById('version');
|
||||||
|
const autoStartSwitch = document.getElementById('active-switch');
|
||||||
|
|
||||||
// Carrega a lista de operadores ao iniciar
|
// Carrega a lista de operadores ao iniciar
|
||||||
window.addEventListener('DOMContentLoaded', async () => {
|
window.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
//... (código existente)
|
||||||
|
|
||||||
|
// Carrega o estado do autostart
|
||||||
|
const autostart = await window.electronAPI.getSetting('autostart');
|
||||||
|
autoStartSwitch.checked = autostart === undefined ? true : autostart;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await window.electronAPI.getOperators();
|
const response = await window.electronAPI.getOperators();
|
||||||
|
|
||||||
|
|
@ -88,7 +96,10 @@ window.electronAPI.onOperatorResponse((response) => {
|
||||||
// Se for bem-sucedido, o processo principal fechará esta janela
|
// Se for bem-sucedido, o processo principal fechará esta janela
|
||||||
});
|
});
|
||||||
|
|
||||||
|
autoStartSwitch.addEventListener('change', () => {
|
||||||
|
const isEnabled = autoStartSwitch.checked;
|
||||||
|
window.electronAPI.setSetting('autostart', isEnabled);
|
||||||
|
});
|
||||||
|
|
||||||
quitButton.addEventListener('click',()=>{
|
quitButton.addEventListener('click',()=>{
|
||||||
window.electronAPI.quitApp();
|
window.electronAPI.quitApp();
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,6 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
showVersion: (version) => ipcRenderer.on('show-version', version),
|
showVersion: (version) => ipcRenderer.on('show-version', version),
|
||||||
onOperatorResponse: (callback) => ipcRenderer.on('operator-response', (_event, response) => callback(response)),
|
onOperatorResponse: (callback) => ipcRenderer.on('operator-response', (_event, response) => callback(response)),
|
||||||
quitApp : () => ipcRenderer.send('sair'),
|
quitApp : () => ipcRenderer.send('sair'),
|
||||||
|
getSetting: (key) => ipcRenderer.invoke('get-setting', key),
|
||||||
|
setSetting: (key, value) => ipcRenderer.send('set-setting', key, value),
|
||||||
});
|
});
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "autoatendcolab",
|
"name": "autoatendcolab",
|
||||||
"version": "1.1.4",
|
"version": "1.1.5",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"isBuildNow": true,
|
"isBuildNow": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"autostart": false
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue