Skip to content

Commit

Permalink
fix(gui): now handle 'bot crash' msg from Go
Browse files Browse the repository at this point in the history
refactor: replace dmBotRunning var by computed sessionManager
  • Loading branch information
hbollon committed Nov 11, 2021
1 parent 70da812 commit 592766a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
31 changes: 30 additions & 1 deletion resources/static/vue-igopher/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,46 @@

<script lang="ts">
import { Vue, Options } from "vue-class-component";
import { inject } from "vue";
import { Astor } from "./plugins/astilectron";
import LateralNav from "@/components/LateralNav.vue";
import NavBar from "@/components/NavBar.vue";
import Footer from "@/components/Footer.vue";
import * as config from "@/config";
import "@/theme"
@Options({
components: {
LateralNav,
NavBar,
Footer,
}
},
data() {
return {
astor: Astor,
}
},
mounted() {
this.astor = inject("astor");
config.ready(() => {
this.astor.onIsReady(() => {
this.astor.listen("bot crash", () => {
const dmBotLaunchBtn = document.querySelector("#dmBotLaunchBtn");
const dmBotLaunchIcon = document.querySelector("#dmBotLaunchIcon");
const dmBotLaunchSpan = document.querySelector("#dmBotLaunchSpan");
if(dmBotLaunchBtn != undefined && dmBotLaunchIcon != undefined && dmBotLaunchSpan != undefined) {
dmBotLaunchBtn.classList.add("btn-success");
dmBotLaunchBtn.classList.remove("btn-danger");
dmBotLaunchIcon.classList.add("fa-rocket");
dmBotLaunchIcon.classList.remove("fa-spinner", "fa-spin");
dmBotLaunchSpan.innerHTML = "Launch !";
}
sessionStorage.setItem("botState", "false");
});
});
});
},
})
export default class App extends Vue {}
</script>
Expand Down
22 changes: 14 additions & 8 deletions resources/static/vue-igopher/src/components/DmAutomationPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ import Multiselect from '@vueform/multiselect'
data() {
return {
astor: Astor,
dmBotRunning: "false",
srcUsrMultiSelect: {
mode: 'tags',
value: [],
Expand All @@ -166,6 +165,16 @@ import Multiselect from '@vueform/multiselect'
},
}
},
computed: {
sessionBotState: {
get(): string {
return sessionStorage.getItem("botState");
},
set(value: string) {
return sessionStorage.setItem("botState", value);
},
}
},
methods: {
fillInputs() {
const dmTemplatesField = document.getElementById(
Expand Down Expand Up @@ -199,17 +208,16 @@ import Multiselect from '@vueform/multiselect'
const dmBotLaunchBtn = document.querySelector("#dmBotLaunchBtn");
const dmBotLaunchIcon = document.querySelector("#dmBotLaunchIcon");
const dmBotLaunchSpan = document.querySelector("#dmBotLaunchSpan");
if (this.dmBotRunning === "false" || this.dmBotRunning === null) {
if (this.sessionBotState === "false" || this.sessionBotState === null) {
this.astor.trigger("launchDmBot", {}, (message: any) => {
if (message.status === config.SUCCESS) {
this.$emit("showDlModal");
this.dmBotRunning = "true";
this.sessionBotState = "true";
dmBotLaunchBtn.classList.add("btn-danger");
dmBotLaunchBtn.classList.remove("btn-success");
dmBotLaunchIcon.classList.add("fa-skull-crossbones");
dmBotLaunchIcon.classList.remove("fa-rocket");
dmBotLaunchSpan.innerHTML = "Stop !";
sessionStorage.setItem("botState", "true");
} else {
config.Toast.fire({
icon: "error",
Expand All @@ -233,13 +241,12 @@ import Multiselect from '@vueform/multiselect'
title: message.msg,
});
this.dmBotRunning = "false";
this.sessionBotState = "false";
dmBotLaunchBtn.classList.add("btn-success");
dmBotLaunchBtn.classList.remove("btn-danger");
dmBotLaunchIcon.classList.add("fa-rocket");
dmBotLaunchIcon.classList.remove("fa-spinner", "fa-spin");
dmBotLaunchSpan.innerHTML = "Launch !";
sessionStorage.setItem("botState", "false");
} else {
dmBotLaunchIcon.classList.add("fa-skull-crossbones");
dmBotLaunchIcon.classList.remove("fa-spinner", "fa-spin");
Expand Down Expand Up @@ -352,8 +359,7 @@ import Multiselect from '@vueform/multiselect'
const dmBotLaunchSpan = document.querySelector("#dmBotLaunchSpan");
// Dynamics buttons inits
this.dmBotRunning = sessionStorage.getItem("botState");
if (this.dmBotRunning === "false" || this.dmBotRunning === null) {
if (this.sessionBotState === "false" || this.sessionBotState === null) {
dmBotLaunchBtn.classList.add("btn-success");
dmBotLaunchBtn.classList.remove("btn-danger");
dmBotLaunchIcon.classList.add("fa-rocket");
Expand Down

0 comments on commit 592766a

Please sign in to comment.