2023-05-08 12:25:13 -07:00
|
|
|
/**
|
|
|
|
* This file will automatically be loaded by vite and run in the "renderer" context.
|
|
|
|
* To learn more about the differences between the "main" and the "renderer" context in
|
|
|
|
* Electron, visit:
|
|
|
|
*
|
|
|
|
* https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes
|
|
|
|
*
|
|
|
|
* By default, Node.js integration in this file is disabled. When enabling Node.js integration
|
|
|
|
* in a renderer process, please be aware of potential security implications. You can read
|
|
|
|
* more about security risks here:
|
|
|
|
*
|
|
|
|
* https://electronjs.org/docs/tutorial/security
|
|
|
|
*
|
|
|
|
* To enable Node.js integration in this file, open up `main.js` and enable the `nodeIntegration`
|
|
|
|
* flag:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* // Create the browser window.
|
|
|
|
* mainWindow = new BrowserWindow({
|
|
|
|
* width: 800,
|
|
|
|
* height: 600,
|
|
|
|
* webPreferences: {
|
|
|
|
* nodeIntegration: true
|
|
|
|
* }
|
|
|
|
* });
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
|
2023-05-09 16:05:58 -07:00
|
|
|
import 'bootstrap/dist/css/bootstrap.css'
|
2023-05-09 12:55:15 -07:00
|
|
|
import './assets/index.css'
|
2023-05-08 17:42:09 -07:00
|
|
|
import './icons/flaticon.css'
|
2023-05-08 12:25:13 -07:00
|
|
|
|
2023-05-12 23:02:05 -07:00
|
|
|
import './assets/ldom.min'
|
2023-05-12 22:48:31 -07:00
|
|
|
|
2023-05-13 12:50:39 -07:00
|
|
|
const { app, ipcRenderer } = require('electron')
|
2023-05-11 21:20:06 -07:00
|
|
|
import { Safari } from './models/Safari'
|
2023-05-10 21:54:32 -07:00
|
|
|
import { UI } from './models/UI'
|
2023-05-09 20:13:25 -07:00
|
|
|
import { Body } from './models/Body'
|
2023-05-11 01:54:03 -07:00
|
|
|
import { sep } from 'path'
|
2023-05-12 03:00:15 -07:00
|
|
|
import { EDSM } from './models/EDSM'
|
2023-05-08 12:25:13 -07:00
|
|
|
|
2023-05-08 17:42:09 -07:00
|
|
|
// Grab app.isPackaged from main process
|
|
|
|
let isPackaged = false
|
|
|
|
window.process.argv.forEach((item) => {
|
|
|
|
if (item.includes('EDS-ENV')) {
|
|
|
|
isPackaged = (item.split('=').pop() === 'true')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-05-09 12:55:15 -07:00
|
|
|
/* ------------------------------------------------------------------------------- app setup ---- */
|
2023-05-08 12:25:13 -07:00
|
|
|
|
2023-05-12 00:05:34 -07:00
|
|
|
const safari = Safari.start(isPackaged)
|
2023-05-11 21:20:06 -07:00
|
|
|
const journal = safari.journal
|
2023-05-12 03:00:15 -07:00
|
|
|
const edsm = EDSM.connect()
|
2023-05-08 13:10:38 -07:00
|
|
|
|
2023-05-11 21:20:06 -07:00
|
|
|
if (!journal) {
|
2023-05-09 12:55:15 -07:00
|
|
|
// handle error
|
|
|
|
}
|
2023-05-08 12:25:13 -07:00
|
|
|
|
2023-05-11 21:20:06 -07:00
|
|
|
safari.watchJournalDir()
|
|
|
|
journal.watch()
|
2023-05-09 20:13:25 -07:00
|
|
|
|
2023-05-13 12:50:39 -07:00
|
|
|
/* -------------------------------------------------------------------- close window handler ---- */
|
|
|
|
|
|
|
|
$('#closeBtn').on('click', () => {
|
|
|
|
ipcRenderer.send('CLOSE_WINDOW')
|
|
|
|
})
|
|
|
|
|
2023-05-11 21:02:23 -07:00
|
|
|
/* ------------------------------------------------------------------------- build body list ---- */
|
2023-05-09 12:55:15 -07:00
|
|
|
|
2023-05-11 21:02:23 -07:00
|
|
|
journal.once('BUILD_BODY_LIST', () => {
|
2023-05-09 20:13:25 -07:00
|
|
|
if (journal.location?.bodies?.length > 0) {
|
2023-05-12 19:48:01 -07:00
|
|
|
journal.location.sortBodies()
|
|
|
|
|
2023-05-09 12:55:15 -07:00
|
|
|
journal.location.bodies.forEach((body) => {
|
2023-05-10 21:54:32 -07:00
|
|
|
const row = UI.createBodyRow(body)
|
2023-05-12 19:53:16 -07:00
|
|
|
|
|
|
|
$('#scans').appendChild(row)
|
2023-05-09 12:55:15 -07:00
|
|
|
})
|
|
|
|
}
|
2023-05-09 13:40:32 -07:00
|
|
|
})
|
|
|
|
|
2023-05-11 21:02:23 -07:00
|
|
|
/* ----------------------------------------------------------------- started hyperspace jump ---- */
|
|
|
|
|
|
|
|
journal.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace())
|
|
|
|
|
2023-05-09 13:40:32 -07:00
|
|
|
/* ---------------------------------------------------------------------- entered new system ---- */
|
|
|
|
|
|
|
|
journal.on('ENTERED_NEW_SYSTEM', () => {
|
2023-05-11 21:02:23 -07:00
|
|
|
UI.setCurrentSystem(journal.location)
|
|
|
|
|
2023-05-12 03:00:15 -07:00
|
|
|
$('#navRoute').children().filter(`#${CSS.escape(journal.location.SystemAddress)}`).remove()
|
2023-05-09 13:40:32 -07:00
|
|
|
|
2023-05-11 21:02:23 -07:00
|
|
|
// 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')
|
|
|
|
}
|
2023-05-09 16:05:58 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- body scan detected ---- */
|
|
|
|
|
|
|
|
journal.on('BODY_SCANNED', (body, DSS) => {
|
2023-05-12 19:48:01 -07:00
|
|
|
journal.location.sortBodies()
|
|
|
|
|
2023-05-09 16:05:58 -07:00
|
|
|
// 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}`)
|
|
|
|
|
2023-05-09 16:13:27 -07:00
|
|
|
if (bodyRow.length > 0) { // check just in case body was missed in earlier scans
|
2023-05-09 16:05:58 -07:00
|
|
|
bodyRow.removeClass('highlighted uncharted').addClass('charted')
|
2023-05-09 16:13:27 -07:00
|
|
|
} else {
|
2023-05-10 21:54:32 -07:00
|
|
|
const row = UI.createBodyRow(body)
|
2023-05-12 19:53:16 -07:00
|
|
|
$('#scans').appendChild(row)
|
2023-05-09 16:05:58 -07:00
|
|
|
}
|
2023-05-09 16:13:27 -07:00
|
|
|
|
|
|
|
} else { // else it's an FSS/auto scan and won't be in the list yet
|
2023-05-10 21:54:32 -07:00
|
|
|
const row = UI.createBodyRow(body)
|
2023-05-12 19:53:16 -07:00
|
|
|
$('#scans').appendChild(row)
|
2023-05-09 16:05:58 -07:00
|
|
|
}
|
2023-05-11 01:54:03 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------- nav route set ---- */
|
|
|
|
|
|
|
|
journal.on('SET_NAV_ROUTE', () => {
|
|
|
|
// clear previous nav route, if any
|
2023-05-11 02:45:02 -07:00
|
|
|
$('#navRoute').children().remove()
|
|
|
|
|
2023-05-11 21:02:23 -07:00
|
|
|
if (journal.navRoute.length > 0) {
|
2023-05-11 02:45:02 -07:00
|
|
|
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 (systemRow.length === 0) {
|
|
|
|
const row = UI.createSystemRow(system)
|
|
|
|
$('#navRoute').appendChild(row)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-05-12 03:00:15 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ system value set ---- */
|
|
|
|
|
|
|
|
edsm.on('SYSTEM_APPRAISED', (system) => {
|
|
|
|
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`)
|
|
|
|
|
|
|
|
if (systemRow.length > 0) {
|
|
|
|
UI.setValue(systemRow, system.estimatedValueMapped)
|
|
|
|
}
|
2023-05-09 12:55:15 -07:00
|
|
|
})
|