Skip to content

Commit

Permalink
fix(console): keep enabled if klippy is connected
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Mar 3, 2024
1 parent 85facaa commit 3763366
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/components/widgets/console/Console.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<console-command
v-if="!readonly && flipLayout"
v-model="currentCommand"
:disabled="!klippyReady"
:disabled="!klippyConnected"
:autofocus="fullscreen"
@send="sendCommand"
/>
Expand Down Expand Up @@ -48,7 +48,7 @@
<console-command
v-if="!readonly && !flipLayout"
v-model="currentCommand"
:disabled="!klippyReady"
:disabled="!klippyConnected"
:autofocus="fullscreen"
@send="sendCommand"
/>
Expand Down
7 changes: 2 additions & 5 deletions src/mixins/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Vue from 'vue'
import { SocketActions } from '@/api/socketActions'
import { Component } from 'vue-property-decorator'
import type { ServerInfo } from '@/store/server/types'

@Component
export default class StateMixin extends Vue {
Expand All @@ -22,13 +21,11 @@ export default class StateMixin extends Vue {
}

get klippyReady (): boolean {
return this.$store.getters['printer/getklippyReady'] as boolean
return this.$store.getters['printer/getKlippyReady'] as boolean
}

get klippyConnected (): boolean {
const server = this.$store.getters['server/getInfo'] as ServerInfo

return server.klippy_connected
return this.$store.getters['printer/getKlippyConnected'] as boolean
}

get hasWarnings (): boolean {
Expand Down
12 changes: 6 additions & 6 deletions src/store/console/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export const getters: GetterTree<ConsoleState, RootState> = {
},

getAllKnownCommands: (state): GcodeHelp => {
const commands = state.gcodeHelp

for (const extraCommand of ['TESTZ', 'ABORT', 'ACCEPT', 'ADJUSTED']) {
if (extraCommand in commands !== true) {
commands[extraCommand] = ''
}
const commands: GcodeHelp = {
TESTZ: '',
ABORT: '',
ACCEPT: '',
ADJUSTED: '',
...state.gcodeHelp
}

return commands
Expand Down
51 changes: 24 additions & 27 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,41 @@ import { get } from 'lodash-es'
import getKlipperType from '@/util/get-klipper-type'
import i18n from '@/plugins/i18n'
import type { GcodeHelp } from '../console/types'
import type { ServerInfo } from '../server/types'

export const getters: GetterTree<PrinterState, RootState> = {

/**
* Indicates if klippy is connected or not.
*/
getklippyReady: (state, getters, rootState, rootGetters): boolean => {
getKlippyReady: (state, getters, rootState, rootGetters): boolean => {
// Valid states are;
// ready, startup, shutdown, error
const serverInfo = rootGetters['server/getInfo']
const server_klippy_state = serverInfo.klippy_state || ''
const connected = serverInfo.klippy_connected || false
if (
server_klippy_state !== 'ready' ||
!connected
) {
return false
}
return true
const serverInfo = rootGetters['server/getInfo'] as ServerInfo

return (
serverInfo.klippy_state === 'ready' &&
serverInfo.klippy_connected
)
},

getKlippyConnected: (state, getters, rootState, rootGetters): boolean => {
const serverInfo = rootGetters['server/getInfo'] as ServerInfo

return serverInfo.klippy_connected
},

getKlippyState: (state, getters, rootState, rootGetters): string => {
const serverInfo = rootGetters['server/getInfo']
const server_klippy_state = serverInfo.klippy_state || ''
return Vue.$filters.capitalize(server_klippy_state)
// if (state1 === state2) {
// return Vue.$filters.capitalize(state1)
// }
// if (state1 !== 'ready' && state1 !== '') {
// return Vue.$filters.capitalize(state1)
// }
// if (state2 !== 'ready' && state1 !== '') {
// return Vue.$filters.capitalize(state2)
// }
// return state1
const serverInfo = rootGetters['server/getInfo'] as ServerInfo

return Vue.$filters.capitalize(serverInfo.klippy_state || '')
},

getKlippyStateMessage: (state, getters, rootState, rootGetters): string => {
const regex = /(?:\r\n|\r|\n)/g
// If there's absolutely no connection to klipper, then
// say so.
const serverInfo = rootGetters['server/getInfo']
const serverInfo = rootGetters['server/getInfo'] as ServerInfo
if (serverInfo.klippy_connected === false) {
return 'Klippy not connected.'
}
Expand Down Expand Up @@ -910,11 +903,15 @@ export const getters: GetterTree<PrinterState, RootState> = {
},

getMoonrakerFailedComponents: (state, getters, rootState, rootGetters) => {
return rootGetters['server/getInfo'].failed_components || []
const serverInfo = rootGetters['server/getInfo'] as ServerInfo

return serverInfo.failed_components || []
},

getMoonrakerWarnings: (state, getters, rootState, rootGetters) => {
return rootGetters['server/getInfo'].warnings || []
const serverInfo = rootGetters['server/getInfo'] as ServerInfo

return serverInfo.warnings || []
},

getSaveConfigPending: (state): boolean => {
Expand Down

0 comments on commit 3763366

Please sign in to comment.