liftinstall/ui/src/main.js

121 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-06-25 03:06:28 +00:00
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import { ajax, stream_ajax } from './helpers'
import Buefy from 'buefy'
2019-06-25 03:06:28 +00:00
import 'buefy/dist/buefy.css'
Vue.config.productionTip = false
Vue.use(Buefy)
2019-06-25 03:06:28 +00:00
// Borrowed from http://tobyho.com/2012/07/27/taking-over-console-log/
function intercept (method) {
console[method] = function () {
var message = Array.prototype.slice.apply(arguments).join(' ')
window.external.invoke(
JSON.stringify({
Log: {
kind: method,
msg: message
}
})
)
}
}
// See if we have access to the JSON interface
2019-09-05 17:19:56 +00:00
var has_external_interface = false
try {
window.external.invoke(JSON.stringify({
Test: {}
}))
2019-09-05 17:19:56 +00:00
has_external_interface = true
} catch (e) {
2019-09-05 17:19:56 +00:00
console.warn('Running without JSON interface - unexpected behaviour may occur!')
}
2019-06-25 03:06:28 +00:00
// Overwrite loggers with the logging backend
if (has_external_interface) {
2019-06-25 03:06:28 +00:00
window.onerror = function (msg, url, line) {
window.external.invoke(
JSON.stringify({
Log: {
kind: 'error',
msg: msg + ' @ ' + url + ':' + line
}
})
)
}
var methods = ['log', 'warn', 'error']
for (var i = 0; i < methods.length; i++) {
intercept(methods[i])
}
}
// Disable F5
function disable_shortcuts (e) {
switch (e.keyCode) {
case 116: // F5
e.preventDefault()
break
}
}
// Check to see if we need to enable dark mode
ajax('/api/dark-mode', function (enable) {
if (enable) {
document.body.classList.add('has-background-black-ter')
}
})
window.addEventListener('keydown', disable_shortcuts)
document.getElementById('window-title').innerText =
base_attributes.name + ' Installer'
function selectFileCallback (name) {
app.install_location = name
}
var app = new Vue({
router: router,
data: {
attrs: base_attributes,
config: {},
install_location: '',
// If the option to pick an install location should be provided
show_install_location: true,
metadata: {
database: [],
install_path: '',
preexisting_install: false
}
},
2019-06-26 13:43:24 +00:00
render: function (caller) {
return caller(App)
2019-06-25 03:06:28 +00:00
},
methods: {
exit: function () {
ajax(
'/api/exit',
function () {},
function (msg) {
2019-09-05 17:19:56 +00:00
var search_location = app.metadata.install_path.length > 0 ? app.metadata.install_path
: 'the location where this installer is'
2019-09-05 17:19:56 +00:00
app.$router.replace({ name: 'showerr',
params: { msg: msg +
'\n\nPlease upload the log file (in ' + search_location + ') to ' +
'the ' + app.attrs.name + ' team'
2019-09-05 17:19:56 +00:00
} })
2019-06-25 03:06:28 +00:00
}
)
},
ajax: ajax,
stream_ajax: stream_ajax
}
}).$mount('#app')
2019-09-05 17:19:56 +00:00
console.log('Vue started')