Update frontend.
This commit is contained in:
parent
48807e59f0
commit
2c6af2d044
1 changed files with 66 additions and 67 deletions
131
src/renderer.js
131
src/renderer.js
|
@ -16,124 +16,123 @@ import { EDSM } from './models/EDSM';
|
||||||
// Grab app.isPackaged from main process
|
// Grab app.isPackaged from main process
|
||||||
let isPackaged = false;
|
let isPackaged = false;
|
||||||
window.process.argv.forEach((item) => {
|
window.process.argv.forEach((item) => {
|
||||||
if (item.includes('EDS-ENV')) {
|
if (item.includes('EDS-ENV')) {
|
||||||
isPackaged = (item.split('=').pop() === 'true');
|
isPackaged = (item.split('=').pop() === 'true');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------- app setup ---- */
|
/* ------------------------------------------------------------------------------- app setup ---- */
|
||||||
|
|
||||||
const safari = Safari.start(isPackaged);
|
const safari = Safari.start(isPackaged);
|
||||||
const settings = Settings.get(isPackaged);
|
const settings = Settings.get();
|
||||||
const journal = safari.journal;
|
const cmdr = safari.CMDR;
|
||||||
const edsm = EDSM.connect();
|
const edsm = EDSM.connect();
|
||||||
|
|
||||||
if (!journal) {
|
if (!cmdr) {
|
||||||
// TODO handle error
|
// TODO handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
safari.watchJournalDir();
|
cmdr.track();
|
||||||
journal.watch();
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------ set colors ---- */
|
/* ------------------------------------------------------------------------------ set colors ---- */
|
||||||
|
|
||||||
settings.on('CUSTOM_COLORS_SET', () => {
|
settings.on('CUSTOM_COLORS_SET', () => {
|
||||||
UI.setColors(settings.matrix);
|
UI.setColors(settings.matrix);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- close window handler ---- */
|
/* -------------------------------------------------------------------- close window handler ---- */
|
||||||
|
|
||||||
$('#closeBtn').on('click', () => {
|
$('#closeBtn').on('click', () => {
|
||||||
safari.shutdown();
|
safari.shutdown();
|
||||||
ipcRenderer.send('CLOSE_WINDOW');
|
ipcRenderer.send('CLOSE_WINDOW');
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- settings button handler ---- */
|
/* ----------------------------------------------------------------- settings button handler ---- */
|
||||||
|
|
||||||
$('#settingsBtn').on('click', () => {
|
$('#settingsBtn').on('click', () => {
|
||||||
ipcRenderer.send('LOAD_SETTINGS');
|
ipcRenderer.send('LOAD_SETTINGS');
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- build body list ---- */
|
/* ------------------------------------------------------------------------- build body list ---- */
|
||||||
|
|
||||||
journal.once('BUILD_BODY_LIST', () => {
|
cmdr.once('BUILD_BODY_LIST', () => {
|
||||||
if (journal.location?.bodies?.length > 0) {
|
if (cmdr.location?.bodies?.length > 0) {
|
||||||
journal.location.sortBodies();
|
cmdr.location.sortBodies();
|
||||||
|
|
||||||
journal.location.bodies.forEach((body) => {
|
cmdr.location.bodies.forEach((body) => {
|
||||||
const row = UI.createBodyRow(body);
|
const row = UI.createBodyRow(body);
|
||||||
|
|
||||||
$('#scans').appendChild(row);
|
$('#scans').appendChild(row);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- started hyperspace jump ---- */
|
/* ----------------------------------------------------------------- started hyperspace jump ---- */
|
||||||
|
|
||||||
journal.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace());
|
cmdr.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace());
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- entered new system ---- */
|
/* ---------------------------------------------------------------------- entered new system ---- */
|
||||||
|
|
||||||
journal.on('ENTERED_NEW_SYSTEM', () => {
|
cmdr.on('ENTERED_NEW_SYSTEM', () => {
|
||||||
UI.setCurrentSystem(journal.location);
|
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
|
// verify that the internal navRoute matches the UI navRoute, and rebuild it if not
|
||||||
if ($('#navRoute').children().length !== journal.navRoute.length) {
|
if ($('#navRoute').children().length !== cmdr.navRoute.length) {
|
||||||
journal.emit('SET_NAV_ROUTE');
|
cmdr.emit('SET_NAV_ROUTE');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- body scan detected ---- */
|
/* ---------------------------------------------------------------------- body scan detected ---- */
|
||||||
|
|
||||||
journal.on('BODY_SCANNED', (body, DSS) => {
|
cmdr.on('BODY_SCANNED', (body, DSS) => {
|
||||||
journal.location.sortBodies();
|
cmdr.location.sortBodies();
|
||||||
|
|
||||||
// If this is a DSS scan, it's very likely that the body already exists in our list so we just
|
// 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
|
// need to remove the highlighting if applicable
|
||||||
if (DSS) {
|
if (DSS) {
|
||||||
const bodyRow = $(`#${body.BodyID}`);
|
const bodyRow = $(`#${body.BodyID}`);
|
||||||
|
|
||||||
if (bodyRow.length > 0) { // check just in case body was missed in earlier scans
|
if (bodyRow.length > 0) { // check just in case body was missed in earlier scans
|
||||||
bodyRow.removeClass('highlighted uncharted').addClass('charted');
|
bodyRow.removeClass('highlighted uncharted').addClass('charted');
|
||||||
} else {
|
} else {
|
||||||
const row = UI.createBodyRow(body);
|
const row = UI.createBodyRow(body);
|
||||||
$('#scans').appendChild(row);
|
$('#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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} 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 ---- */
|
/* --------------------------------------------------------------------------- nav route set ---- */
|
||||||
|
|
||||||
journal.on('SET_NAV_ROUTE', () => {
|
cmdr.on('SET_NAV_ROUTE', () => {
|
||||||
// clear previous nav route, if any
|
// clear previous nav route, if any
|
||||||
$('#navRoute').children().remove();
|
$('#navRoute').children().remove();
|
||||||
|
|
||||||
if (journal.navRoute.length > 0) {
|
if (cmdr.navRoute.length > 0) {
|
||||||
journal.navRoute.forEach((system) => {
|
cmdr.navRoute.forEach((system) => {
|
||||||
// duplicate check
|
// duplicate check
|
||||||
// CSS.escape is needed since CSS technically doesn't allow numeric IDs
|
// CSS.escape is needed since CSS technically doesn't allow numeric IDs
|
||||||
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`);
|
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`);
|
||||||
|
|
||||||
if (systemRow.length === 0) {
|
if (systemRow.length === 0) {
|
||||||
const row = UI.createSystemRow(system);
|
const row = UI.createSystemRow(system);
|
||||||
$('#navRoute').appendChild(row);
|
$('#navRoute').appendChild(row);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ system value set ---- */
|
/* ------------------------------------------------------------------------ system value set ---- */
|
||||||
|
|
||||||
edsm.on('SYSTEM_APPRAISED', (system) => {
|
edsm.on('SYSTEM_APPRAISED', (system) => {
|
||||||
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`);
|
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`);
|
||||||
|
|
||||||
if (systemRow.length > 0) {
|
if (systemRow.length > 0) {
|
||||||
UI.setValue(systemRow, system.estimatedValueMapped);
|
UI.setValue(systemRow, system.estimatedValueMapped);
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in a new issue