diff --git a/src/renderer/components/AiLayer.vue b/src/renderer/components/AiLayer.vue index 82cf7b2..e9cf055 100644 --- a/src/renderer/components/AiLayer.vue +++ b/src/renderer/components/AiLayer.vue @@ -10,7 +10,9 @@ props: [], mounted () { this.aiLayer = aiLayer({url: this.$store.state.Settings.settings.phi_url}) - this.aiLayer.addTo(this.$parent.mapObject) + if(this.aiLayer) { + this.aiLayer.addTo(this.$parent.mapObject) + } }, data () { return { diff --git a/src/renderer/components/PavementLayer.vue b/src/renderer/components/PavementLayer.vue index 4ec1111..3198945 100644 --- a/src/renderer/components/PavementLayer.vue +++ b/src/renderer/components/PavementLayer.vue @@ -31,12 +31,19 @@ // Callback for add readPavement(this.$store.state.Settings.settings.flightgearDirectory_apt, icao, this.read) }, + // Callback called when pavement read read (layer) { this.pavement = layer if (this.pavement) { this.pavement.on('add', this.onAdd) this.pavement.addTo(this.$parent.mapObject) this.visible = true + } else { + this.$message({ + type: 'Error', + showClose: true, + message: `Couldn't load pavement from ${this.$store.state.Settings.settings.flightgearDirectory_apt}` + }) } }, onAdd () { diff --git a/src/renderer/components/SettingsPanel.vue b/src/renderer/components/SettingsPanel.vue index f27e169..ee3ea39 100644 --- a/src/renderer/components/SettingsPanel.vue +++ b/src/renderer/components/SettingsPanel.vue @@ -17,23 +17,31 @@ - Flightgear Directory + Flightgear Data Directory {{ flightgear_directory }} - + + + Traffic Directory - {{ Traffic_directory }} + {{ Traffic_directory }} APT File - {{ apt_file }} + {{ apt_file }} @@ -123,7 +131,7 @@ import DirectorySelect from './DirectorySelect' const { ipcRenderer } = require('electron') - + const fs = require('fs') export default { name: 'settings-panel', components: { DirectorySelect, FileSelect }, @@ -132,7 +140,7 @@ }, data () { - return { + return { ok: true } }, methods: { @@ -192,9 +200,25 @@ Traffic_directory: function () { return this.$store.state.Settings.settings.flightgearDirectory_traffic }, + Traffic_directory_ok: function () { + try { + fs.accessSync(this.$store.state.Settings.settings.flightgearDirectory_traffic) + return true + } catch (error) { + return false + } + }, apt_file: function () { return this.$store.state.Settings.settings.flightgearDirectory_apt }, + apt_file_ok: function () { + try { + fs.accessSync(this.$store.state.Settings.settings.flightgearDirectory_apt) + return true + } catch (error) { + return false + } + }, airports_directory: function () { return this.$store.state.Settings.settings.airportsDirectory }, @@ -229,4 +253,9 @@ .file-label { padding: 10px; } +.invalid { + padding: 10px; + background-color: red; +} + diff --git a/src/renderer/loaders/pavement_loader.js b/src/renderer/loaders/pavement_loader.js index 3168588..3eb9743 100644 --- a/src/renderer/loaders/pavement_loader.js +++ b/src/renderer/loaders/pavement_loader.js @@ -12,7 +12,6 @@ You should have received a copy of the GNU General Public License along with FG /* eslint-disable */ const lineReader = require('readline'); const zlib = require('zlib'); -// const geodesy = require('geodesy'); const LatLonEllipsoidal = require('geodesy/latlon-ellipsoidal-vincenty.js').default; const fs = require('fs'); @@ -269,7 +268,7 @@ function createLineString(currentFeature, layerGroup) { } } -module.exports.readPavement = function (f, icao, cb) { +module.exports.readPavement = function (f, icao, callback) { console.log(f); var pavementLayerGroup = L.layerGroup(); var currentFeature; @@ -278,6 +277,7 @@ module.exports.readPavement = function (f, icao, cb) { if (!fs.existsSync(f)) { store.default.dispatch('setPavementLoaded', true); + callback(); return; } try { @@ -307,14 +307,16 @@ module.exports.readPavement = function (f, icao, cb) { store.default.dispatch('setPavementLoaded', true); console.error(err); lr.close(); + callback(); }).on('close', function () { store.default.dispatch('setPavementLoaded', true); console.log("End"); - cb(pavementLayerGroup); + callback(pavementLayerGroup); }); } catch (err) { console.error('no access!'); store.default.dispatch('setPavementLoaded', true); + callback(); return; } } diff --git a/src/renderer/phi/AILayer.js b/src/renderer/phi/AILayer.js index c31c44e..6812678 100644 --- a/src/renderer/phi/AILayer.js +++ b/src/renderer/phi/AILayer.js @@ -264,5 +264,5 @@ function mapSGPropertyNode(node) { })); export function aiLayer(options) { - return new L.AILayer(null, options); + return undefined //new L.AILayer(null, options); } diff --git a/src/renderer/store/modules/Settings.js b/src/renderer/store/modules/Settings.js index 439130d..a835589 100644 --- a/src/renderer/store/modules/Settings.js +++ b/src/renderer/store/modules/Settings.js @@ -1,4 +1,7 @@ /* eslint-disable */ +const path = require('path'); +const fs = require('fs'); + const state = { settings: { flightgearDirectory: '.', testDirectory: '.', email: 'flightgearairports@example.org', name: 'unknown', phi_url: 'http://localhost:8080' }, zoom: 14, @@ -8,41 +11,52 @@ const state = { } const mutations = { - 'DELETE_INDEXED_DB' () { }, - 'FLIGHTGEAR_DIRECTORY' (state, flightgearDirectory) { - state.settings.flightgearDirectory = flightgearDirectory - state.settings.flightgearDirectory_ai = flightgearDirectory + '/data/AI' - state.settings.flightgearDirectory_traffic = flightgearDirectory + '/data/AI/Traffic' - state.settings.flightgearDirectory_apt = flightgearDirectory + '/data/Airports/apt.dat.gz' + 'DELETE_INDEXED_DB'() { }, + 'FLIGHTGEAR_DIRECTORY'(state, flightgearDirectory) { + try { + fs.accessSync(flightgearDirectory) + state.settings.flightgearDirectory = flightgearDirectory + } catch (err) { + try { + fs.accessSync(flightgearDirectory.replace(/\.App/, '')) + state.settings.flightgearDirectory = flightgearDirectory.replace(/\.App/, '') + } catch (error) { + console.warn(error) + } + } + + state.settings.flightgearDirectory_ai = flightgearDirectory + path.sep + 'AI' + state.settings.flightgearDirectory_traffic = path.join(flightgearDirectory, 'AI', 'Traffic'); + state.settings.flightgearDirectory_apt = path.join(flightgearDirectory, 'Airports', 'apt.dat.gz'); }, - 'AIPORTS_DIRECTORY' (state, airportsDirectory) { + 'AIPORTS_DIRECTORY'(state, airportsDirectory) { state.settings.airportsDirectory = airportsDirectory }, - 'TEST_DIRECTORY' (state, testDirectory) { + 'TEST_DIRECTORY'(state, testDirectory) { state.settings.testDirectory = testDirectory }, - 'ZOOM' (state, zoom) { + 'ZOOM'(state, zoom) { state.zoom = zoom }, - 'CENTER' (state, center) { + 'CENTER'(state, center) { state.center = center }, - 'BOUNDS' (state, bounds) { + 'BOUNDS'(state, bounds) { state.bounds = bounds }, - 'SET_EMAIL' (state, email) { + 'SET_EMAIL'(state, email) { state.settings.email = email }, - 'SET_NAME' (state, name) { + 'SET_NAME'(state, name) { state.settings.name = name }, - 'SET_PHI_URL' (state, phi_url) { + 'SET_PHI_URL'(state, phi_url) { state.settings.phi_url = phi_url - }, - 'SET_SCAN_LOGGING' (state, scanLogging) { + }, + 'SET_SCAN_LOGGING'(state, scanLogging) { state.settings.scanLogging = scanLogging }, - 'ADD_WIP' (state, airport) { + 'ADD_WIP'(state, airport) { const item = state.wip.find((e) => e.icao === airport.icao) airport.time = Date.now() if (item === null || item === undefined) { @@ -52,12 +66,12 @@ const mutations = { } state.wip.sort((w1, w2) => w1.time - w2.time) }, - 'UPLOAD_WIP' (state, icao) { + 'UPLOAD_WIP'(state, icao) { const item = state.wip.find((e) => e.icao === icao) item.upload = Date.now() state.wip.sort((p, p2) => { return p.time - p2.time }) }, - 'REMOVE_WIP' (state, icao) { + 'REMOVE_WIP'(state, icao) { const item = state.wip.find((e) => e.icao === icao) const index = state.wip.indexOf(item) if (index > -1) { @@ -69,21 +83,21 @@ const mutations = { const plugins = [] const actions = { - async setZoom (context, zoom) { + async setZoom(context, zoom) { context.commit('ZOOM', zoom) }, - async setCenter (context, center) { - if( center.lat !== context.state.center.lat || center.lng !== context.state.center.lng) { + async setCenter(context, center) { + if (center.lat !== context.state.center.lat || center.lng !== context.state.center.lng) { context.commit('CENTER', center) } }, - async setBounds (context, bounds) { + async setBounds(context, bounds) { context.commit('BOUNDS', bounds) }, - async addWip (context, airport) { + async addWip(context, airport) { context.commit('ADD_WIP', airport) }, - async removeWip (context, icao) { + async removeWip(context, icao) { context.commit('REMOVE_WIP', icao) } }