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

fix: restart services with name matching files #876

Merged
Merged
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
26 changes: 20 additions & 6 deletions src/components/TheEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<span class="d-none d-sm-inline">{{ $t('Editor.SaveClose') }}</span>
</v-btn>
<v-btn
v-if="restartServiceName !== null"
v-if="restartServiceNameExists"
color="primary"
text
tile
Expand Down Expand Up @@ -187,6 +187,12 @@ export default class TheEditor extends Mixins(BaseMixin) {
return this.$store.state.editor.filename ?? ''
}

get filenameWithoutExtension(): string {
if (this.filename.lastIndexOf('.')) return this.filename.slice(0, this.filename.lastIndexOf('.'))

return this.filename
}

get fileExtension() {
if (this.filename.lastIndexOf('.')) return this.filename.slice(this.filename.lastIndexOf('.') + 1)

Expand Down Expand Up @@ -231,19 +237,27 @@ export default class TheEditor extends Mixins(BaseMixin) {
return this.$t('Editor.' + directionUppercase)
}

get availableServices() {
return this.$store.state.server.system_info?.available_services ?? []
}

get restartServiceName() {
if (!this.isWriteable) return null
if (['printing', 'paused'].includes(this.printer_state)) return null

if (this.filename === 'moonraker.conf') return 'moonraker'
else if (this.filename === 'webcam.conf') return 'webcamd'
else if (this.filename.startsWith('webcam') && this.filename.endsWith('.txt')) return 'webcamd'
else if (this.filename.startsWith('mooncord') && this.filename.endsWith('.json')) return 'mooncord'
else if (this.filename.endsWith('.cfg')) return 'klipper'
if (this.availableServices.includes(this.filenameWithoutExtension) && this.fileExtension === 'conf')
return this.filenameWithoutExtension
if (this.filename.startsWith('webcam') && ['conf', 'txt'].includes(this.fileExtension)) return 'webcamd'
if (this.filename.startsWith('mooncord') && this.fileExtension === 'json') return 'mooncord'
if (this.fileExtension === 'cfg') return 'klipper'

return null
}

get restartServiceNameExists() {
return this.availableServices.includes(this.restartServiceName)
}

get confirmUnsavedChanges() {
return this.$store.state.gui.editor.confirmUnsavedChanges ?? false
}
Expand Down