Update frontend.

This commit is contained in:
marley 2023-05-19 11:29:26 -07:00
parent 48807e59f0
commit 2c6af2d044

View file

@ -19,21 +19,20 @@ window.process.argv.forEach((item) => {
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 settings = Settings.get();
const cmdr = safari.CMDR;
const edsm = EDSM.connect();
if (!journal) {
if (!cmdr) {
// TODO handle error
}
safari.watchJournalDir();
journal.watch();
cmdr.track();
/* ------------------------------------------------------------------------------ set colors ---- */
@ -56,11 +55,11 @@ $('#settingsBtn').on('click', () => {
/* ------------------------------------------------------------------------- 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) => {
cmdr.location.bodies.forEach((body) => {
const row = UI.createBodyRow(body);
$('#scans').appendChild(row);
@ -70,25 +69,25 @@ journal.once('BUILD_BODY_LIST', () => {
/* ----------------------------------------------------------------- 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');
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
@ -110,12 +109,12 @@ journal.on('BODY_SCANNED', (body, DSS) => {
/* --------------------------------------------------------------------------- nav route set ---- */
journal.on('SET_NAV_ROUTE', () => {
cmdr.on('SET_NAV_ROUTE', () => {
// clear previous nav route, if any
$('#navRoute').children().remove();
if (journal.navRoute.length > 0) {
journal.navRoute.forEach((system) => {
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)}`);