feat: add settings for klipper & moonraker 'SAVE & RESTART' (#700)

This commit is contained in:
Stefan Dej authored and GitHub committed 2022-03-06 00:50:42 +01:00
1 parent fc7dec8bfa
commit c85a4ac5dd
7 files changed
+93 -5

No files matched your search

@@ -16,6 +16,32 @@
<v-switch v-model="confirmUnsavedChanges" hide-details class="mt-0"></v-switch>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row
:title="$t('Settings.EditorTab.KlipperRestartMethod')"
:sub-title="$t('Settings.EditorTab.KlipperRestartMethodDescription')">
<v-select
v-model="klipperRestartMethod"
:items="klipperRestartMethods"
hide-details
outlined
dense
attached></v-select>
</settings-row>
<v-divider class="my-2"></v-divider>
<template v-if="availableMoonrakerInstances.length > 1">
<settings-row
:title="$t('Settings.EditorTab.MoonrakerRestartInstance')"
:sub-title="$t('Settings.EditorTab.MoonrakerRestartInstanceDescription')">
<v-select
v-model="moonrakerRestartInstance"
:items="availableMoonrakerInstances"
hide-details
outlined
dense
attached></v-select>
</settings-row>
<v-divider class="my-2"></v-divider>
</template>
</v-card-text>
</v-card>
</div>
@@ -30,6 +56,17 @@ import SettingsRow from '@/components/settings/SettingsRow.vue'
components: { SettingsRow },
})
export default class SettingsEditorTab extends Mixins(BaseMixin) {
private klipperRestartMethods = [
{
text: 'FIRMWARE_RESTART',
value: 'FIRMWARE_RESTART',
},
{
text: 'RESTART',
value: 'RESTART',
},
]
get escToClose() {
return this.$store.state.gui.editor.escToClose
}
@@ -45,5 +82,27 @@ export default class SettingsEditorTab extends Mixins(BaseMixin) {
set confirmUnsavedChanges(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.confirmUnsavedChanges', value: newVal })
}
get klipperRestartMethod() {
return this.$store.state.gui.editor.klipperRestartMethod
}
set klipperRestartMethod(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.klipperRestartMethod', value: newVal })
}
get moonrakerRestartInstance() {
return this.$store.state.gui.editor.moonrakerRestartInstance
}
set moonrakerRestartInstance(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.moonrakerRestartInstance', value: newVal })
}
get availableMoonrakerInstances() {
const available_instances = this.$store.state.server.system_info?.available_services ?? []
return available_instances.filter((name: string) => name.startsWith('moonraker')).sort()
}
}
</script>
+5 -1
View File
@@ -149,7 +149,11 @@
"UnsavedChangesSubMessage": "Deine Änderungen werden verloren gehen wenn du sie nicht speicherst. Du kannst diese Meldung in den Editor-Einstellungen deaktivieren.",
"DontSave": "Nicht speichern",
"Cancel": "Abbrechen",
"FileReadOnly": "schreibgeschützt"
"FileReadOnly": "schreibgeschützt",
"KlipperRestartMethod": "Klipper Neustartmethode",
"KlipperRestartMethodDescription": "Wählen der Neustartmethode die bei 'Speichern & Neustarten' verwendet wird, wenn Klipper-Konfigurationsdateien bearbeitet werden.",
"MoonrakerRestartInstance": "Moonraker Neustartinstanz",
"MoonrakerRestartInstanceDescription": "Wählen der Moonraker-Instanz die bei 'Speichern & Neustarten' neu gestartet wird, wenn Moonraker-Konfigurationsdateien bearbeitet werden."
},
"Files": {
"GCodeFiles": "G-Code Dateien",
+5 -1
View File
@@ -917,7 +917,11 @@
"UseEscToClose": "Use ESC to close editor",
"UseEscToCloseDescription": "Allows the ESC key to close the editor",
"ConfirmUnsavedChanges": "Prompt to save or discard unsaved changes",
"ConfirmUnsavedChangesDescription": "If enabled, the editor requires a confirmation to either save or discard the changes made. If disabled, changes are silently discarded."
"ConfirmUnsavedChangesDescription": "If enabled, the editor requires a confirmation to either save or discard the changes made. If disabled, changes are silently discarded.",
"KlipperRestartMethod": "Klipper restart method",
"KlipperRestartMethodDescription": "Select which restart method will be used on 'Save & Restart' when editing Klipper config files.",
"MoonrakerRestartInstance": "Moonraker restart instance",
"MoonrakerRestartInstanceDescription": "Select which Moonraker service will restart on 'Save & Restart' when editing Moonraker config files."
}
},
"GCodeViewer": {
+6 -2
View File
@@ -77,7 +77,7 @@ export const actions: ActionTree<EditorState, RootState> = {
},
async saveFile(
{ state, commit, rootGetters, dispatch },
{ state, commit, getters, rootGetters, dispatch },
payload: { content: string; restartServiceName: string | null }
) {
const content = new Blob([payload.content], { type: 'text/plain' })
@@ -133,8 +133,12 @@ export const actions: ActionTree<EditorState, RootState> = {
dispatch('clearLoader')
Vue.$toast.success(i18n.t('Editor.SuccessfullySaved', { filename: data.item.path }).toString())
if (payload.restartServiceName === 'klipper') {
const klipperRestartMethod = getters['getKlipperRestartMethod']
//dispatch('server/addEvent', { message: 'FIRMWARE_RESTART', type: 'command' })
Vue.$socket.emit('printer.gcode.script', { script: 'FIRMWARE_RESTART' })
Vue.$socket.emit('printer.gcode.script', { script: klipperRestartMethod })
} else if (payload.restartServiceName === 'moonraker') {
const moonrakerRestartInstance = getters['getMoonrakerRestartInstance']
Vue.$socket.emit('machine.services.restart', { service: moonrakerRestartInstance })
} else if (payload.restartServiceName !== null) {
Vue.$socket.emit('machine.services.restart', { service: payload.restartServiceName })
}
+14 -1
View File
@@ -1,4 +1,17 @@
import { GetterTree } from 'vuex'
import { EditorState } from '@/store/editor/types'
export const getters: GetterTree<EditorState, any> = {}
export const getters: GetterTree<EditorState, any> = {
getKlipperRestartMethod: (state, getters, rootState) => {
return rootState.gui.editor?.klipperRestartMethod ?? 'FIRMWARE_RESTART'
},
getMoonrakerRestartInstance: (state, getters, rootState) => {
const available_services = rootState.server?.system_info?.available_services ?? []
const setting = rootState.gui.editor?.moonrakerRestartInstance ?? 'moonraker'
if (available_services.includes(setting)) return setting
return 'moonraker'
},
}
+2
View File
@@ -104,6 +104,8 @@ export const getDefaultState = (): GuiState => {
editor: {
escToClose: true,
confirmUnsavedChanges: true,
klipperRestartMethod: 'FIRMWARE_RESTART',
moonrakerRestartInstance: null,
},
gcodeViewer: {
extruderColors: ['#E76F51FF', '#F4A261FF', '#E9C46AFF', '#2A9D8FFF', '#264653FF'],
+2
View File
@@ -48,6 +48,8 @@ export interface GuiState {
editor: {
escToClose: boolean
confirmUnsavedChanges: boolean
klipperRestartMethod: 'FIRMWARE_RESTART' | 'RESTART'
moonrakerRestartInstance: string | null
}
gcodeViewer: {
extruderColors: string[]