LiveAtlas/src/main.ts

110 lines
3.0 KiB
TypeScript
Raw Normal View History

2020-12-16 16:54:41 +00:00
/*
* Copyright 2020 James Lyne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2020-11-20 18:43:30 +00:00
import { createApp } from 'vue'
import App from './App.vue'
2021-05-17 02:39:25 +00:00
import API from './api';
2020-11-23 12:13:28 +00:00
import {store} from "@/store";
2020-11-20 18:43:30 +00:00
2020-11-23 12:13:28 +00:00
import 'leaflet/dist/leaflet.css';
import 'normalize-scss/sass/normalize/_import-now.scss';
2020-12-01 23:20:38 +00:00
import '@/scss/style.scss';
2021-05-17 02:39:25 +00:00
import {MutationTypes} from "@/store/mutation-types";
2020-12-16 22:40:44 +00:00
const splash = document.getElementById('splash'),
2021-05-15 20:09:01 +00:00
splashSpinner = document.getElementById('splash__spinner'),
2020-12-16 22:40:44 +00:00
splashError = document.getElementById('splash__error'),
2021-05-15 20:09:01 +00:00
splashErrorMessage = document.getElementById('splash__error-message'),
splashRetry = document.getElementById('splash__error-retry'),
2021-05-15 19:25:03 +00:00
splashAttempt = document.getElementById('splash__error-attempt'),
svgs = import.meta.globEager('/assets/icons/*.svg');
2020-12-16 22:40:44 +00:00
2021-05-17 02:39:25 +00:00
window.showSplash = function() {
if(!splash) {
return;
}
splash.ontransitionend = null;
splash.hidden = false;
2020-12-16 22:40:44 +00:00
requestAnimationFrame(function() {
if(splash) {
2021-05-17 02:39:25 +00:00
splash.style.opacity = '1';
2020-12-16 22:40:44 +00:00
}
});
};
2021-05-17 02:39:25 +00:00
window.hideSplash = function() {
if(!splash) {
return;
}
splash.ontransitionend = function(e) {
if(e.target === splash) {
splash.hidden = true;
}
};
requestAnimationFrame(function() {
splash.style.opacity = '0';
});
};
2021-05-15 20:09:01 +00:00
window.showSplashError = function(message: string, fatal: boolean, attempts: number) {
2020-12-16 22:40:44 +00:00
if(splashError) {
splashError.setAttribute('aria-hidden', 'false');
}
2021-05-15 20:09:01 +00:00
if(splashErrorMessage) {
splashErrorMessage.innerText = message || 'Unknown error';
}
if(splashSpinner && fatal) {
splashSpinner.style.visibility = 'hidden';
}
if(splashAttempt && splashRetry) {
if(fatal) {
splashAttempt.hidden = splashRetry.hidden = true;
} else if(attempts) {
splashAttempt.hidden = splashRetry.hidden = false;
splashAttempt.textContent = attempts.toString();
}
2020-12-16 22:40:44 +00:00
}
};
2020-12-18 14:35:06 +00:00
console.info(`LiveAtlas version ${store.state.version} - https://github.com/JLyne/LiveAtlas`);
2020-12-17 15:24:40 +00:00
2021-05-17 02:39:25 +00:00
API.validateConfiguration().then((config) => {
store.commit(MutationTypes.SET_SERVERS, config);
if(config.size > 1) {
const lastSegment = window.location.pathname.split('/').pop(),
serverName = lastSegment && config.has(lastSegment) ? lastSegment : config.keys().next().value;
store.commit(MutationTypes.SET_CURRENT_SERVER, serverName);
} else {
store.commit(MutationTypes.SET_CURRENT_SERVER, config.keys().next().value);
}
console.log(store.state.currentServer);
const app = createApp(App).use(store);
2020-11-23 12:13:28 +00:00
2021-05-17 02:39:25 +00:00
// app.config.performance = true;
app.mount('#mcmap');
});