From 2c6af2d0447fcb56c3b6da066f3011bab3d49846 Mon Sep 17 00:00:00 2001 From: marley Date: Fri, 19 May 2023 11:29:26 -0700 Subject: [PATCH] Update frontend. --- src/renderer.js | 133 ++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/src/renderer.js b/src/renderer.js index a10277b..f6b026d 100755 --- a/src/renderer.js +++ b/src/renderer.js @@ -16,124 +16,123 @@ import { EDSM } from './models/EDSM'; // Grab app.isPackaged from main process let isPackaged = false; window.process.argv.forEach((item) => { - if (item.includes('EDS-ENV')) { - isPackaged = (item.split('=').pop() === 'true'); - } -}) + if (item.includes('EDS-ENV')) { + isPackaged = (item.split('=').pop() === 'true'); + } +}); /* ------------------------------------------------------------------------------- app setup ---- */ -const safari = Safari.start(isPackaged); -const settings = Settings.get(isPackaged); -const journal = safari.journal; -const edsm = EDSM.connect(); +const safari = Safari.start(isPackaged); +const settings = Settings.get(); +const cmdr = safari.CMDR; +const edsm = EDSM.connect(); -if (!journal) { - // TODO handle error +if (!cmdr) { + // TODO handle error } -safari.watchJournalDir(); -journal.watch(); +cmdr.track(); /* ------------------------------------------------------------------------------ set colors ---- */ settings.on('CUSTOM_COLORS_SET', () => { - UI.setColors(settings.matrix); + UI.setColors(settings.matrix); }); /* -------------------------------------------------------------------- close window handler ---- */ $('#closeBtn').on('click', () => { - safari.shutdown(); - ipcRenderer.send('CLOSE_WINDOW'); + safari.shutdown(); + ipcRenderer.send('CLOSE_WINDOW'); }); /* ----------------------------------------------------------------- settings button handler ---- */ $('#settingsBtn').on('click', () => { - ipcRenderer.send('LOAD_SETTINGS'); + ipcRenderer.send('LOAD_SETTINGS'); }); /* ------------------------------------------------------------------------- build body list ---- */ -journal.once('BUILD_BODY_LIST', () => { - if (journal.location?.bodies?.length > 0) { - journal.location.sortBodies(); +cmdr.once('BUILD_BODY_LIST', () => { + if (cmdr.location?.bodies?.length > 0) { + cmdr.location.sortBodies(); - journal.location.bodies.forEach((body) => { - const row = UI.createBodyRow(body); + cmdr.location.bodies.forEach((body) => { + const row = UI.createBodyRow(body); - $('#scans').appendChild(row); - }); - } + $('#scans').appendChild(row); + }); + } }); /* ----------------------------------------------------------------- started hyperspace jump ---- */ -journal.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace()); +cmdr.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace()); /* ---------------------------------------------------------------------- entered new system ---- */ -journal.on('ENTERED_NEW_SYSTEM', () => { - UI.setCurrentSystem(journal.location); +cmdr.on('ENTERED_NEW_SYSTEM', () => { + UI.setCurrentSystem(cmdr.location); - $('#navRoute').children().filter(`#${CSS.escape(journal.location.SystemAddress)}`).remove(); + $('#navRoute').children().filter(`#${CSS.escape(cmdr.location.SystemAddress)}`).remove(); - // verify that the internal navRoute matches the UI navRoute, and rebuild it if not - if ($('#navRoute').children().length !== journal.navRoute.length) { - journal.emit('SET_NAV_ROUTE'); - } + // verify that the internal navRoute matches the UI navRoute, and rebuild it if not + if ($('#navRoute').children().length !== cmdr.navRoute.length) { + cmdr.emit('SET_NAV_ROUTE'); + } }); /* ---------------------------------------------------------------------- body scan detected ---- */ -journal.on('BODY_SCANNED', (body, DSS) => { - journal.location.sortBodies(); +cmdr.on('BODY_SCANNED', (body, DSS) => { + cmdr.location.sortBodies(); - // If this is a DSS scan, it's very likely that the body already exists in our list so we just - // need to remove the highlighting if applicable - if (DSS) { - const bodyRow = $(`#${body.BodyID}`); + // If this is a DSS scan, it's very likely that the body already exists in our list so we just + // need to remove the highlighting if applicable + if (DSS) { + const bodyRow = $(`#${body.BodyID}`); - if (bodyRow.length > 0) { // check just in case body was missed in earlier scans - bodyRow.removeClass('highlighted uncharted').addClass('charted'); - } else { - const row = UI.createBodyRow(body); - $('#scans').appendChild(row); - } - - } else { // else it's an FSS/auto scan and won't be in the list yet - const row = UI.createBodyRow(body); - $('#scans').appendChild(row); + if (bodyRow.length > 0) { // check just in case body was missed in earlier scans + bodyRow.removeClass('highlighted uncharted').addClass('charted'); + } else { + const row = UI.createBodyRow(body); + $('#scans').appendChild(row); } + + } else { // else it's an FSS/auto scan and won't be in the list yet + const row = UI.createBodyRow(body); + $('#scans').appendChild(row); + } }); /* --------------------------------------------------------------------------- nav route set ---- */ -journal.on('SET_NAV_ROUTE', () => { - // clear previous nav route, if any - $('#navRoute').children().remove(); +cmdr.on('SET_NAV_ROUTE', () => { + // clear previous nav route, if any + $('#navRoute').children().remove(); - if (journal.navRoute.length > 0) { - journal.navRoute.forEach((system) => { - // duplicate check - // CSS.escape is needed since CSS technically doesn't allow numeric IDs - const systemRow = $(`#${CSS.escape(system.SystemAddress)}`); + if (cmdr.navRoute.length > 0) { + cmdr.navRoute.forEach((system) => { + // duplicate check + // CSS.escape is needed since CSS technically doesn't allow numeric IDs + const systemRow = $(`#${CSS.escape(system.SystemAddress)}`); - if (systemRow.length === 0) { - const row = UI.createSystemRow(system); - $('#navRoute').appendChild(row); - } - }); - } + if (systemRow.length === 0) { + const row = UI.createSystemRow(system); + $('#navRoute').appendChild(row); + } + }); + } }); /* ------------------------------------------------------------------------ system value set ---- */ edsm.on('SYSTEM_APPRAISED', (system) => { - const systemRow = $(`#${CSS.escape(system.SystemAddress)}`); + const systemRow = $(`#${CSS.escape(system.SystemAddress)}`); - if (systemRow.length > 0) { - UI.setValue(systemRow, system.estimatedValueMapped); - } -}); \ No newline at end of file + if (systemRow.length > 0) { + UI.setValue(systemRow, system.estimatedValueMapped); + } +});