Skip to content

Commit

Permalink
feat: allow service restart when klipper service is down
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Bassett <[email protected]>
  • Loading branch information
cadriel committed Feb 22, 2021
1 parent de1de4e commit 75b4588
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/components/AppDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class AppDrawer extends Mixins(UtilsMixin) {
}
get versionsSupported () {
return this.$store.state.socket.plugins.includes('update_manager')
return this.$store.state.socket.printer.serverInfo.plugins.includes('update_manager')
}
close () {
Expand Down
14 changes: 12 additions & 2 deletions src/components/cards/KlippyCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<v-card-text>
<v-row>
<v-col cols="12" sm="4">
<v-btn block color="warning" @click="serviceRestartKlippy" class="me-2 mb-2">Restart Klipper</v-btn>
<v-btn block color="warning" @click="serviceFirmwareRestartKlippy" class="me-2 mb-2">Firmware Restart</v-btn>
<v-btn v-if="!klipperConnected" block color="warning" @click="serviceRestartKlipper" class="me-2 mb-2">Restart Klipper Service</v-btn>
<v-btn v-if="klipperConnected" block color="warning" @click="serviceRestartKlippy" class="me-2 mb-2">Restart Klipper</v-btn>
<v-btn v-if="klipperConnected" block color="warning" @click="serviceFirmwareRestartKlippy" class="me-2 mb-2">Firmware Restart</v-btn>
<v-btn block color="warning" @click="serviceRestartMoonraker" class="me-2 mb-2">Restart Moonraker</v-btn>
<v-btn block color="secondary" @click="getKlippyLog()" class="me-2 mb-2"><v-icon left small>$download</v-icon>Klippy.log</v-btn>
<v-btn block color="secondary" @click="getMoonrakerLog()" class="me-2 mb-2"><v-icon left small>$download</v-icon>Moonraker.log</v-btn>
Expand Down Expand Up @@ -35,6 +36,10 @@ import WarningsWidget from '@/components/widgets/WarningsWidget.vue'
}
})
export default class KlippyCard extends Mixins(UtilsMixin) {
get klipperConnected () {
return this.$store.state.socket.printer.serverInfo.klippy_connected
}
getKlippyLog () {
this.download('klippy.log', '')
}
Expand All @@ -61,5 +66,10 @@ export default class KlippyCard extends Mixins(UtilsMixin) {
SocketActions.serverRestart()
this.$emit('click')
}
serviceRestartKlipper () {
SocketActions.machineServicesRestart('klipper')
this.$emit('click')
}
}
</script>
2 changes: 1 addition & 1 deletion src/components/widgets/SystemCommandsWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class SystemCommandsWidget extends Mixins(UtilsMixin) {
}
get devicePowerPluginEnabled () {
return (this.$store.state.socket.plugins.includes('power'))
return (this.$store.state.socket.printer.serverInfo.plugins.includes('power'))
}
togglePowerDevice (device: Device, wait?: string) {
Expand Down
18 changes: 5 additions & 13 deletions src/store/socket/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export const actions: ActionTree<SocketState, RootState> = {
async onSocketOpen ({ commit }, payload) {
commit('onSocketOpen', payload)
SocketActions.printerInfo()
// We run this here so that we can get the status of power devices
// without necessarily having connection to the printer.
SocketActions.serverInfo()
},

/**
Expand Down Expand Up @@ -101,6 +98,9 @@ export const actions: ActionTree<SocketState, RootState> = {

async onPrinterInfo ({ commit }, payload) {
commit('onPrinterInfo', payload)
// We run this here so that we can get the status of power devices
// without necessarily having connection to the printer.
SocketActions.serverInfo()

if (payload.state !== 'ready') {
clearTimeout(retryTimeout)
Expand All @@ -109,7 +109,7 @@ export const actions: ActionTree<SocketState, RootState> = {
}, Globals.KLIPPY_RETRY_DELAY)
} else {
// We're good, move on. Start by loading the server data, temperature and console history.
SocketActions.serverInfo()
// SocketActions.serverInfo()
SocketActions.serverConfig()
SocketActions.serverGcodeStore()
SocketActions.printerGcodeHelp()
Expand All @@ -129,19 +129,11 @@ export const actions: ActionTree<SocketState, RootState> = {
async onServerInfo ({ commit, dispatch }, payload) {
// This payload should return a list of enabled plugins
// and root directories that are available.
if (
payload.failed_plugins &&
payload.failed_plugins.length
) {
commit('onFailedPlugins', payload.failed_plugins)
}

commit('onServerInfo', payload)
if (
payload.plugins &&
payload.plugins.length > 0
) {
commit('onPlugins', payload.plugins)

// Init any plugins we need.
const pluginsToInit = [
'power',
Expand Down
2 changes: 1 addition & 1 deletion src/store/socket/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,6 @@ export const getters: GetterTree<SocketState, RootState> = {
},

getMoonrakerWarnings: (state) => {
return state.failed_plugins || []
return state.printer.serverInfo.failed_plugins || []
}
}
9 changes: 7 additions & 2 deletions src/store/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export const defaultState = (): SocketState => {
availableCommands: {},
chart: [],
macros: [],
plugins: [],
failed_plugins: [],
printer: {
bed_mesh: {},
heaters: {
Expand All @@ -30,6 +28,13 @@ export const defaultState = (): SocketState => {
state: '',
state_message: ''
},
serverInfo: {
failed_plugins: [],
klippy_connected: false, // indicates if klippy is disconnected vs shutdown.
klippy_state: '',
plugins: [],
registered_directories: []
},
configfile: {
save_config_pending: false,
config: {},
Expand Down
15 changes: 2 additions & 13 deletions src/store/socket/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,8 @@ export const mutations: MutationTree<SocketState> = {
onPrinterInfo (state, payload) {
Vue.set(state.printer, 'info', payload)
},
onPlugins (state, payload) {
Vue.set(
state,
'plugins',
[...new Set([...state.plugins, ...payload])]
)
},
onFailedPlugins (state, payload) {
Vue.set(
state,
'failed_plugins',
[...new Set([...state.failed_plugins, ...payload])]
)
onServerInfo (state, payload) {
Vue.set(state.printer, 'serverInfo', payload)
},
onPrinterObjectsList (state, payload) {
if (!state.printer.objects.includes(payload)) {
Expand Down
2 changes: 0 additions & 2 deletions src/store/socket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export interface SocketState {
error: SocketError | null;
endstops: EndStops;
macros: Macro[];
plugins: string[]; // active plugins (device_power)
failed_plugins: string[];
console: ConsoleEntry[]; // console stream
availableCommands: GcodeCommands; // available gcode commands
chart: ChartData[]; // chart data
Expand Down

0 comments on commit 75b4588

Please sign in to comment.