Skip to content

Commit

Permalink
refactor: move info to root printer state
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Nov 20, 2024
1 parent 4a90376 commit 7d93712
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/components/widgets/system/SystemOverviewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
import { Component, Mixins } from 'vue-property-decorator'
import type { SystemInfo, CpuInfo, DistroInfo, Virtualization } from '@/store/server/types'
import StateMixin from '@/mixins/state'
import type { PrinterInfo } from '@/store/printer/types'
@Component({})
export default class PrinterStatsCard extends Mixins(StateMixin) {
Expand Down Expand Up @@ -174,8 +175,8 @@ export default class PrinterStatsCard extends Mixins(StateMixin) {
.join(', ')
}
get printerInfo () {
return this.$store.state.printer.printer.info
get printerInfo (): PrinterInfo {
return this.$store.state.printer.info
}
get canRolloverLogs (): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/store/printer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const actions: ActionTree<PrinterState, RootState> = {
},

async checkKlipperMinVersion ({ state, dispatch }) {
const klipperVersion = state.printer.info.software_version ?? '?'
const klipperVersion = state.info.software_version ?? '?'

const fullKlipperVersion = klipperVersion.includes('-')
? klipperVersion
Expand Down
16 changes: 5 additions & 11 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,19 @@ export const getters: GetterTree<PrinterState, RootState> = {
// If an external source fires an estop, or the client
// is refreshed while klipper is down - the webhook data maybe invalid
// but the printer info should be good.
if (
state.printer.info.state_message &&
state.printer.info.state_message !== ''
) {
return state.printer.info.state_message.trim().replace(/\r\n|\r|\n/g, '<br />')
if (state.info.state_message) {
return state.info.state_message.trim().replace(/\r\n|\r|\n/g, '<br />')
}
if (
state.printer.webhooks.state_message &&
state.printer.webhooks.state_message !== ''
) {
if (state.printer.webhooks.state_message) {
return state.printer.webhooks.state_message.trim().replace(/\r\n|\r|\n/g, '<br />')
}
return 'Unknown'
},

getKlippyApp: (state) => {
const app = state.printer.info.app?.toLowerCase()
const app = state.info.app?.toLowerCase()

const klippyApp = isKeyOf(app, Globals.SUPPORTED_SERVICES.klipper)
const klippyApp = app && isKeyOf(app, Globals.SUPPORTED_SERVICES.klipper)
? app
: 'klipper'

Expand Down
6 changes: 1 addition & 5 deletions src/store/printer/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ export const mutations: MutationTree<PrinterState> = {
},

setPrinterInfo (state, payload) {
Vue.set(state.printer, 'info', payload)
state.info = payload
},

setQueryEndstops (state, payload) {
state.printer.endstops = payload
},

setPrinterBusy (state, payload: boolean) {
state.printer.busy = payload
},

setPrinterObjectList (state, payload) {
if (!state.printer.objects.includes(payload)) {
state.printer.objects.push(payload)
Expand Down
8 changes: 4 additions & 4 deletions src/store/printer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import type { PrinterState } from './types'
*/
export const defaultState = (): PrinterState => {
return {
info: {
state: '',
state_message: ''
},
printer: {
endstops: {},
bed_mesh: {
Expand All @@ -15,10 +19,6 @@ export const defaultState = (): PrinterState => {
available_heaters: [],
available_sensors: []
},
info: {
state: '',
state_message: ''
},
configfile: {
warnings: [],
save_config_pending: false,
Expand Down
19 changes: 16 additions & 3 deletions src/store/printer/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
export interface PrinterState {
printer: Printer;
info: PrinterInfo;
printer: Record<string, any>;
}

export interface Printer {
[key: string]: any;
export interface PrinterInfo {
state: string;
state_message: string;
hostname?: string;
klipper_path?: string;
python_path?: string;
process_id?: number;
user_id?: number;
group_id?: number;
log_file?: string;
config_file?: string;
software_version?: string;
cpu_info?: string
app?: string;
}

export interface KnownExtruder {
Expand Down

0 comments on commit 7d93712

Please sign in to comment.