use ajax to fetch basic_attrs

This commit is contained in:
liushuyu 2019-10-21 14:09:26 -06:00 committed by James
parent 713b85b59a
commit 91fb88aa98
6 changed files with 65 additions and 29 deletions

View File

@ -8,8 +8,9 @@ module.exports = {
'@vue/standard' '@vue/standard'
], ],
rules: { rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-console': 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-redeclare': 'off'
}, },
parserOptions: { parserOptions: {
parser: 'babel-eslint' parser: 'babel-eslint'

View File

@ -53,7 +53,7 @@ function returnConfig (res) {
app.get('/api/attrs', (req, res) => { app.get('/api/attrs', (req, res) => {
res.send( res.send(
`var base_attributes = {"name":"yuzu","target_url":"https://raw.githubusercontent.com/j-selby/test-installer/master/config.linux.v2.toml"};` { 'name': 'yuzu', 'target_url': 'https://raw.githubusercontent.com/j-selby/test-installer/master/config.linux.v2.toml' }
) )
}) })

View File

@ -8,6 +8,7 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.0",
"buefy": "^0.8.5", "buefy": "^0.8.5",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-router": "^3.1.3" "vue-router": "^3.1.3"

View File

@ -4,7 +4,6 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=11"> <meta http-equiv="X-UA-Compatible" content="IE=11">
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="/api/attrs" type="text/javascript"></script>
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title id="window-title">... Installer</title> <title id="window-title">... Installer</title>
</head> </head>

View File

@ -1,7 +1,8 @@
import Vue from 'vue' import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import { ajax, stream_ajax } from './helpers' import axios from 'axios'
import { ajax, stream_ajax as streamAjax } from './helpers'
import Buefy from 'buefy' import Buefy from 'buefy'
import 'buefy/dist/buefy.css' import 'buefy/dist/buefy.css'
@ -24,18 +25,18 @@ function intercept (method) {
} }
// See if we have access to the JSON interface // See if we have access to the JSON interface
var has_external_interface = false var hasExternalInterface = false
try { try {
window.external.invoke(JSON.stringify({ window.external.invoke(JSON.stringify({
Test: {} Test: {}
})) }))
has_external_interface = true hasExternalInterface = true
} catch (e) { } catch (e) {
console.warn('Running without JSON interface - unexpected behaviour may occur!') console.warn('Running without JSON interface - unexpected behaviour may occur!')
} }
// Overwrite loggers with the logging backend // Overwrite loggers with the logging backend
if (has_external_interface) { if (hasExternalInterface) {
window.onerror = function (msg, url, line) { window.onerror = function (msg, url, line) {
window.external.invoke( window.external.invoke(
JSON.stringify({ JSON.stringify({
@ -54,7 +55,7 @@ if (has_external_interface) {
} }
// Disable F5 // Disable F5
function disable_shortcuts (e) { function disableShortcuts (e) {
switch (e.keyCode) { switch (e.keyCode) {
case 116: // F5 case 116: // F5
e.preventDefault() e.preventDefault()
@ -69,19 +70,23 @@ ajax('/api/dark-mode', function (enable) {
} }
}) })
window.addEventListener('keydown', disable_shortcuts) window.addEventListener('keydown', disableShortcuts)
document.getElementById('window-title').innerText = axios.get('/api/attrs').then(function (resp) {
base_attributes.name + ' Installer' document.getElementById('window-title').innerText =
resp.data.name + ' Installer'
}).catch(function (err) {
console.error(err)
})
function selectFileCallback (name) { // function selectFileCallback (name) {
app.install_location = name // app.install_location = name
} // }
var app = new Vue({ var app = new Vue({
router: router, router: router,
data: { data: {
attrs: base_attributes, attrs: {},
config: {}, config: {},
install_location: '', install_location: '',
// If the option to pick an install location should be provided // If the option to pick an install location should be provided
@ -95,25 +100,28 @@ var app = new Vue({
render: function (caller) { render: function (caller) {
return caller(App) return caller(App)
}, },
mounted: function () {
axios.get('/api/attrs').then(function (resp) {
app.attrs = resp.data
}).catch(function (err) {
console.error(err)
})
},
methods: { methods: {
exit: function () { exit: function () {
ajax( axios.get('/api/attrs').catch(function (msg) {
'/api/exit', var searchLocation = app.metadata.install_path.length > 0 ? app.metadata.install_path
function () {}, : 'the location where this installer is'
function (msg) {
var search_location = app.metadata.install_path.length > 0 ? app.metadata.install_path
: 'the location where this installer is'
app.$router.replace({ name: 'showerr', app.$router.replace({ name: 'showerr',
params: { msg: msg + params: { msg: msg +
'\n\nPlease upload the log file (in ' + search_location + ') to ' + '\n\nPlease upload the log file (in ' + searchLocation + ') to ' +
'the ' + app.attrs.name + ' team' 'the ' + app.attrs.name + ' team'
} }) } })
} })
)
}, },
ajax: ajax, ajax: ajax,
stream_ajax: stream_ajax stream_ajax: streamAjax
} }
}).$mount('#app') }).$mount('#app')

View File

@ -1483,6 +1483,14 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
dependencies:
follow-redirects "1.5.10"
is-buffer "^2.0.2"
babel-eslint@^10.0.3: babel-eslint@^10.0.3:
version "10.0.3" version "10.0.3"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a"
@ -2631,6 +2639,13 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
dependencies: dependencies:
ms "2.0.0" ms "2.0.0"
debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"
debug@^3.0.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6: debug@^3.0.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6:
version "3.2.6" version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
@ -3622,6 +3637,13 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3" inherits "^2.0.3"
readable-stream "^2.3.6" readable-stream "^2.3.6"
follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"
follow-redirects@^1.0.0: follow-redirects@^1.0.0:
version "1.9.0" version "1.9.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.9.0.tgz#8d5bcdc65b7108fe1508649c79c12d732dcedb4f" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.9.0.tgz#8d5bcdc65b7108fe1508649c79c12d732dcedb4f"
@ -4402,6 +4424,11 @@ is-buffer@^1.1.5:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
is-buffer@^2.0.2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.4.tgz#3e572f23c8411a5cfd9557c849e3665e0b290623"
integrity sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==
is-callable@^1.1.4: is-callable@^1.1.4:
version "1.1.4" version "1.1.4"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"