const $ = require('jquery'); const axios = require('axios'); const os = require('os'); // const remote = require('electron').remote; // const FindInPage = require('electron-find').FindInPage; // let findInPage = new FindInPage(remote.getCurrentWebContents()); // ipcRenderer.on('on-find', (e, args) => { // findInPage.openFindWindow(); // }); $('#loader').css('display', 'flex'); async function index() { try { const urlOkan = "https://io.okan.tools/api/auth/electron"; const token = 'HrZTvmBNyQaM6jPI7sHo5ywN35ht/cplIBFeE+4Ufx8='; const urlGetProfile = 'https://io.okan.tools/api/auth/users/electron'; let documento; let profile; try { const responseOkan = await axios.post(urlOkan, { user: process.env.USUARIO }, { headers: { 'Authorization': token } }); if (responseOkan.data.cod == '0') { ipcRenderer.send('newLog', { window: 'splash', log: 'Token obtenido: ' + responseOkan.data.data, msg: 'Información del documento encontrado...', splash: true }); console.log('Token: ' + responseOkan.data.data); const token_okan = 'Bearer ' + responseOkan.data.data; console.log(token_okan); try { const responseGetProfile = await axios.get(urlGetProfile, { headers: { 'Authorization': token_okan } }); if (responseGetProfile.data.cod == '0') { ipcRenderer.send('newLog', { window: 'splash', log: 'Perfil obtenido: ' + responseGetProfile.data.data.profile, msg: 'Información del documento encontrado...', splash: true }); console.log('Profile: ' + JSON.stringify(responseGetProfile.data.data)); documento = responseGetProfile.data.data.document_number; profile = responseGetProfile.data.data.profile.id; } else { ipcRenderer.send('newLog', { window: 'splash', log: 'Ha ocurrido un error: ' + responseGetProfile.data.message, msg: 'Ha ocurrido un error', splash: true }); } } catch (e) { ipcRenderer.send('newLog', { window: 'splash', log: 'Error al obtener el perfil: ' + e, msg: 'Error al obtener el perfil: '+e, splash: true }); } } else { ipcRenderer.send('newLog', { window: 'splash', log: 'Ha ocurrido un error: ' + responseGetProfile.data.message, msg: 'Ha ocurrido un error', splash: true }); } } catch (error) { ipcRenderer.send('newLog', { window: 'splash', log: 'Error al obtener el token: ' + error, msg: 'Error al obtener el token: '+error, splash: true }); } // const foundElement = datos.find(item => item.nickname === nicknameToFind); // if (foundElement) { // ipcRenderer.send('newLog', { window: 'splash', log: 'Usuario encontrado: ' + nicknameToFind, msg: 'Información del usuario encontrada...', splash: true }); // if (foundElement.document_number) { // documento = foundElement.document_number; // ipcRenderer.send('newLog', { window: 'splash', log: 'Documento encontrado: ' + documento, msg: 'Información del documento encontrado...', splash: true }); // } else { // ipcRenderer.send('newLog', { window: 'splash', log: 'Documento no encontrado', msg: 'No se pudo encontrar el documento del usuario...', splash: true }); // } // } else { // ipcRenderer.send('newLog', { window: 'splash', log: 'Usuario no encontrado', msg: 'No se pudo obtener el usuario...', splash: true }); // } // const urlProfile = `https://io.okan.tools/api/auth/user/${documento}`; // const responseProfile = await axios.get(urlProfile, { headers: { "Accept": "*/*", "Content-Type": "application/json" } }); // if (responseProfile.data['cod'] == '0') { // profile = responseProfile.data['data']; // ipcRenderer.send('newLog', { window: 'splash', log: 'Perfil encontrado: ' + profile.profile.id, msg: 'Información del perfil encontrado...', splash: true }); // } const urlAplicativos = `https://adm.okan.tools/wp-json/okanapiwp/v1/aplicativos/${documento}/${profile}`; const responseAplicativos = await axios.get(urlAplicativos, { headers: { "Accept": "*/*", "Content-Type": "application/json" } }); var apps_okan = []; var type_app; var url_service; var code_app; if (responseAplicativos.data['cod'] == '0') { const promises = responseAplicativos.data['data'].map(async element => { if (element['rpa'] == "true") { if (element['url'].includes('RpaClaro://?code=')) { var code_temp = element['url']; code_app = code_temp.slice(code_temp.indexOf("=") + 1); if(code_app != 'IRR123' && code_app != 'ACC098' && code_app != 'XLT001' && code_app != 'CTB002' && code_app != 'AVY003'){ url_service = "https://rpa.mind.brm.co/app"; type_app = 'apps'; } else { url_service = "https://rpa.mind.brm.co/desk"; type_app = 'desk'; } apps_okan.push( { 'code_app': code_app, 'name': element['nombre_app'], 'type_app': type_app, 'url_service': url_service, 'url_logo': element['logo'] }); } } }); } var status_integrado; var status; ipcRenderer.send('newLog', { window: 'splash', log: 'Aplicativos obtenidos: ' + apps_okan.length, msg: 'Obteniendo aplicaciones...', splash: true }); const promises = []; async function makeRequest(element) { try { const bodyContent = { code: element.code_app, user: process.env.USUARIO, }; console.log('_____________________________'); await axios.post(element.url_service, bodyContent, { headers: { "Accept": "*/*", "Content-Type": "application/json" } }) .then(response => { console.log(response.data); // Access the response data here status = response.data == 'Invalid parameter' ? false : true; console.log(status); status_integrado = status ? 'integrado' : 'no_integrado'; console.log(status_integrado); console.log('App: ' + element.code_app + ' - ' + status + ' - ' + element.name); $('#aplicativos').append(`
${element.name}
`); }) .catch(error => { ipcRenderer.send('newLog', { window: 'splash', log: 'Error al consultar aplicación', msg: 'Error al consultar aplicación...', splash: true }); status = false; status_integrado = 'no_integrado'; console.log('App: ' + element.code_app + ' - ' + status + ' - ' + element.name); $('#aplicativos').append(`
${element.name}
`); }); console.log('_____________________________'); } catch (e) { // ipcRenderer.send('newLog', { window: 'splash', log: 'Error al consultar aplicación', msg: 'Error al consultar aplicación...', splash: true }); // status = false; // status_integrado = 'no_integrado'; } } async function processApps() { for (const element of apps_okan) { await new Promise(resolve => setTimeout(resolve, 100)); // await makeRequest(element); } // Lógica de ordenación var divs = $('.shortcut').sort(function (a, b) { var textoA = $(a).find('h5').text().toUpperCase(); var textoB = $(b).find('h5').text().toUpperCase(); return (textoA < textoB) ? -1 : (textoA > textoB) ? 1 : 0; }); // Limpia el contenedor original $('.shortcut').remove(); // Agrega los divs ordenados de nuevo al contenedor divs.appendTo('#aplicativos'); ipcRenderer.send('newLog', { window: 'splash', log: 'Termino de ordenar', msg: 'Estamos terminando...', splash: true }); // Esperar un poco antes de emitir el evento 'ordeno' setTimeout(function () { console.log('ordeno apps'); ipcRenderer.send('ordeno'); $('#loader').css('display', 'none'); }, 2000); } processApps(); } catch (error) { console.log("Error en la ejecución: " + error); ipcRenderer.send('newLog', { window: 'splash', log: 'Error en la ejecución', msg: 'Ha ocurrido un error: ' + error, splash: true }); } } index(); $(document).on("click", ".app_click", function () { ipcRenderer.send('newNotification', { 'title': 'Abriendo aplicativo', 'body': $(this).attr('name_app') }); console.log('click'); console.log($(this).attr('integrado')); if ($(this).attr('integrado') == 'true') { data_code = $(this).attr('code') console.log(data_code); ipcRenderer.send('openNewWindow', data_code); } else { error_window = { title: 'Error de aplicativo', content: 'No tienes habilitado este aplicativo, informa al coordinador' } ipcRenderer.send('error_window', error_window); } }); $('#search-input').on('input', function () { var textoBusqueda = $(this).val().toUpperCase(); $('.shortcut').each(function () { var textoElemento = $(this).find('h5').text().toUpperCase(); var elemento = $(this); elemento.toggle(textoElemento.includes(textoBusqueda)); }); }); $('#active_apps').on('click', function () { var elementosFiltrados = $('.shortcut[integrado="true"]'); $('.shortcut').hide(); elementosFiltrados.show(); }); $('#inactive_apps').on('click', function () { var elementosFiltrados = $('.shortcut[integrado="false"]'); $('.shortcut').hide(); elementosFiltrados.show(); }); $('#all_apps').on('click', function () { $('.shortcut').show(); });