Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/components/settings/SettingsEditorTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
}
Expand All @@ -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>
6 changes: 5 additions & 1 deletion src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions src/store/editor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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 })
}
Expand Down
15 changes: 14 additions & 1 deletion src/store/editor/getters.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions src/store/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 2 additions & 0 deletions src/store/gui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface GuiState {
editor: {
escToClose: boolean
confirmUnsavedChanges: boolean
klipperRestartMethod: 'FIRMWARE_RESTART' | 'RESTART'
moonrakerRestartInstance: string | null
}
gcodeViewer: {
extruderColors: string[]
Expand Down