Some changes for the GUI

This commit is contained in:
Félix Aime 2021-02-19 13:20:18 +01:00
parent 6790b17f86
commit 8d64b3bc9a
3 changed files with 35 additions and 39 deletions

View File

@ -2,7 +2,7 @@
<div class="controls" v-if="display">
<i class="off-icon" v-on:click="action('shutdown')" v-if="off_available"></i>
<i class="quit-icon" v-on:click="action('quit')" v-if="quit_available"></i>
<i :class="[ update_available ? 'update-icon' :'no-update-icon' ]" @click="$router.push({ name: 'update' })"></i>
<i class="update-icon" v-if="update_available&&update_possible" @click="$router.push({ name: 'update' })"></i>
</div>
</template>
<script>
@ -14,7 +14,7 @@ export default {
return {
display: true,
update_available: false,
update_possible: true,
update_possible: false,
quit_available: false,
off_available: false
}
@ -33,11 +33,14 @@ export default {
.then(response => {
if(response.data.status) {
if(response.data.message == "A new version is available"){
// Allow to show the warning chip.
this.update_available = true
this.update_possible = true
} else if(response.data.message == "This is the latest version"){
this.update_available = false
this.update_possible = true
// Pass the versions as "global vars" through window variable.
window.current_version = response.data.current_version
window.next_version = response.data.next_version
}
} else {
this.update_possible = false

View File

@ -1,20 +1,10 @@
<template>
<div class="center">
<div v-if="update_possible">
<div v-if="update_available">
<p><span class="orange-strong">TinyCheck needs to be updated.</span><br />
<span v-if="!update_launched">Please click on the button below to update it.</span>
<span v-else>The process can take few minutes, please wait...</span>
</p>
<button class="btn btn-primary" :class="[ update_launched ? 'loading' : '' ]" v-on:click="launch_update()">Update it now</button>
</div>
<div v-else>
<p><span class="green-strong">Your TinyCheck instance is up-to-date!</span><br />You'll be redirected in few seconds.</p>
</div>
</div>
<div v-else>
<p><strong>You dont have Internet or the rights to update Tinycheck.</strong><br />You'll be redirected in few seconds.</p>
</div>
<p><strong>TinyCheck needs to be updated from the version {{current_version}} to the version {{next_version}}.</strong><br />
<span v-if="!update_launched">Please click on the button below to update it.</span>
<span v-else>The process can take few minutes, please wait...</span>
</p>
<button class="btn btn-primary" :class="[ update_launched ? 'loading' : '' ]" v-on:click="launch_update()">Update it now</button>
</div>
</template>
@ -26,30 +16,22 @@
data() {
return {
translation: {},
update_available: null,
update_possible: true,
update_launched: null,
check_interval: null
check_interval: null,
next_version: null,
current_version: null
}
},
methods: {
check_update: function() {
axios.get('/api/update/check', { timeout: 60000 })
axios.get('/api/update/check-version', { timeout: 60000 })
.then(response => {
console.log(response.data.status)
if(response.data.status) {
if(response.data.message == "A new version is available"){
this.update_available = true
this.update_possible = true
} else if (response.data.message == "This is the latest version"){
this.update_available = false
this.update_possible = true
if(response.data.current_version == window.next_version){
window.current_version = response.data.current_version
clearInterval(this.check_interval);
setTimeout(function () { window.location.href = "/"; }.bind(this), 3000);
window.location.href = "/";
}
} else {
this.update_possible = false
setTimeout(function () { window.location.href = "/"; }.bind(this), 3000);
}
})
.catch(error => { console.log(error) });
@ -68,7 +50,17 @@
}
},
created: function() {
this.check_update();
if ('next_version' in window && 'current_version' in window){
if (window.current_version != window.next_version){
this.next_version = window.next_version
this.current_version = window.current_version
} else {
window.location.href = "/";
}
} else {
window.location.href = "/";
}
}
}
</script>

View File

@ -29,15 +29,16 @@ class Update(object):
res = json.loads(res.content.decode("utf8"))
with open(os.path.join(self.app_path, "VERSION")) as f:
if f.read() != res[0]["name"]:
cv = f.read()
if cv != res[0]["name"]:
return {"status": True,
"message": "A new version is available",
"current_version": f.read(),
"current_version": cv,
"next_version": res[0]["name"]}
else:
return {"status": True,
"message": "This is the latest version",
"current_version": f.read()}
"current_version": cv}
except:
return {"status": False,
"message": "Something went wrong (no API access nor version file)"}