From 2a97cb358f6f4b6f2ecd793e519132b52403b6f6 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sun, 14 May 2023 16:03:12 -0700 Subject: [PATCH] Final cleanup, ready for packing! --- forge.config.js | 2 +- package.json | 2 +- src/models/Journal.ts | 15 +++++++++++---- src/models/Safari.ts | 15 ++++++++++++--- src/renderer.js | 1 + src/settings.js | 7 +++++-- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/forge.config.js b/forge.config.js index 44ed1eb..7a032cc 100755 --- a/forge.config.js +++ b/forge.config.js @@ -11,7 +11,7 @@ module.exports = { }, { name: '@electron-forge/maker-zip', - platforms: ['darwin'], + platforms: ['darwin', 'win32'], }, { name: '@electron-forge/maker-deb', diff --git a/package.json b/package.json index 1c52690..ebb0679 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ed-safari", "productName": "ed-safari", - "version": "0.1.0", + "version": "1.0.0", "description": "My Electron application description", "main": ".vite/build/main.js", "scripts": { diff --git a/src/models/Journal.ts b/src/models/Journal.ts index 3a1ecc5..82b6077 100755 --- a/src/models/Journal.ts +++ b/src/models/Journal.ts @@ -18,6 +18,7 @@ export class Journal extends EventEmitter { testing: string; location: System; navRoute: System[]; + #tail?: TailType; constructor(journalPath: string) { super(); @@ -218,12 +219,12 @@ export class Journal extends EventEmitter { // Watch the journal for changes. watch(): void { - const tail: TailType = new Tail(this.#path, {useWatchFile: true}); + this.#tail = new Tail(this.#path, {useWatchFile: true}); Log.write(`Watching ${path.basename(this.#path)}...`); - tail.on('line', (data) => data ? this.#parseLine(data) : undefined); - tail.on('error', (err) => Log.write(`Tail error in Journal.watch(): ${err}`)); + this.#tail?.on('line', (data) => data ? this.#parseLine(data) : undefined); + this.#tail?.on('error', (err) => Log.write(`Tail error in Journal.watch(): ${err}`)); } /* ------------------------------------------------------------------------ #parseLine() ---- */ @@ -296,7 +297,7 @@ export class Journal extends EventEmitter { /* --------------------------------------------------------------------- #handleScanLine ---- */ - #handleScanLine(line: autoScan|detailedScan, DSS: boolean = false) { + #handleScanLine(line: autoScan|detailedScan, DSS: boolean = false): void { const dupChecker = {'BodyName': line.BodyName, 'BodyID': line.BodyID}; let body: Body|null = null; @@ -327,4 +328,10 @@ export class Journal extends EventEmitter { Log.write(`Scan detected. Body: ${line.BodyName}.`); this.emit('BODY_SCANNED', body, DSS); } + + /* ---------------------------------------------------------------------------- shutdown ---- */ + + shutdown(): void { + this.#tail?.unwatch(); + } } \ No newline at end of file diff --git a/src/models/Safari.ts b/src/models/Safari.ts index f52c146..7fa8877 100755 --- a/src/models/Safari.ts +++ b/src/models/Safari.ts @@ -14,6 +14,8 @@ export class Safari { #journalPattern?: string; journal?: Journal; + #watcher?: any; + private constructor(isPackaged: boolean) { if (!isPackaged && os.platform() === 'linux') { // Account for WSL during development this.#journalDir = "/mnt/c/Users/marle/Saved\ Games/Frontier\ Developments/Elite\ Dangerous/"; @@ -80,9 +82,16 @@ export class Safari { watchJournalDir(): void { const options = {usePolling: true, persistent: true, ignoreInitial: true}; - const watcher = chokidar.watch(this.#journalPattern, options); + this.#watcher = chokidar.watch(this.#journalPattern, options); - watcher.on('ready', () => Log.write('Watching journal folder for changes...')); - watcher.on('add', () => this.journal = this.#getLatestJournal()); + this.#watcher.on('ready', () => Log.write('Watching journal folder for changes...')); + this.#watcher.on('add', () => this.journal = this.#getLatestJournal()); + } + + /* ---------------------------------------------------------------------------- shutdown ---- */ + + async shutdown(): Promise { + this.journal?.shutdown(); + await this.#watcher.close(); } } \ No newline at end of file diff --git a/src/renderer.js b/src/renderer.js index 4debcc2..a10277b 100755 --- a/src/renderer.js +++ b/src/renderer.js @@ -44,6 +44,7 @@ settings.on('CUSTOM_COLORS_SET', () => { /* -------------------------------------------------------------------- close window handler ---- */ $('#closeBtn').on('click', () => { + safari.shutdown(); ipcRenderer.send('CLOSE_WINDOW'); }); diff --git a/src/settings.js b/src/settings.js index 6bdb7ff..d9d4c61 100644 --- a/src/settings.js +++ b/src/settings.js @@ -7,9 +7,11 @@ const { ipcRenderer } = require('electron'); const { setTimeout } = require('node:timers/promises'); const { basename } = require('node:path'); +import { Safari } from './models/Safari'; import { Settings } from './models/Settings'; import { UI } from './models/UI'; +const safari = Safari.start(); const settings = Settings.get(); if (settings.matrix) { @@ -25,13 +27,14 @@ settings.on('CUSTOM_COLORS_SET', () => { /* -------------------------------------------------------------------- close window handler ---- */ $('#closeBtn').on('click', () => { - ipcRenderer.send('CLOSE_WINDOW') + safari.shutdown(); + ipcRenderer.send('CLOSE_WINDOW'); }) /* ---------------------------------------------------------------- load main window handler ---- */ $('.backBtn').on('click', () => { - ipcRenderer.send('LOAD_MAIN') + ipcRenderer.send('LOAD_MAIN'); }) /* ------------------------------------------------------------------- insert current values ---- */