diff --git a/src/components/panels/MiniconsolePanel.vue b/src/components/panels/MiniconsolePanel.vue
index 57daa0be..182d807f 100644
--- a/src/components/panels/MiniconsolePanel.vue
+++ b/src/components/panels/MiniconsolePanel.vue
@@ -107,7 +107,6 @@ export default class MiniconsolePanel extends Mixins(BaseMixin) {
}
private gcode = ''
- private lastCommands: string[] = []
private lastCommandNumber: number | null = null
private items = [];
private cmdListSearch: string | null = null
@@ -162,6 +161,10 @@ export default class MiniconsolePanel extends Mixins(BaseMixin) {
return this.gcode?.split('\n').length ?? 1
}
+ get lastCommands(): string[] {
+ return this.$store.state.gui.gcodehistory.history ?? []
+ }
+
commandClick(msg: string): void {
this.gcode = msg
@@ -174,7 +177,7 @@ export default class MiniconsolePanel extends Mixins(BaseMixin) {
if (!cmd.shiftKey) {
if (this.gcode !== '') {
this.$store.dispatch('printer/sendGcode', this.gcode)
- this.lastCommands.push(this.gcode)
+ this.$store.dispatch('gui/gcodehistory/addToHistory', this.gcode)
this.gcode = ''
this.lastCommandNumber = null
setTimeout(() => {
diff --git a/src/components/settings/SettingsGeneralTab.vue b/src/components/settings/SettingsGeneralTab.vue
index 8a1bc050..efa0c927 100644
--- a/src/components/settings/SettingsGeneralTab.vue
+++ b/src/components/settings/SettingsGeneralTab.vue
@@ -50,6 +50,13 @@
hide-details
class="mt-0"
>
+
{
diff --git a/src/store/gui/gcodehistory/actions.ts b/src/store/gui/gcodehistory/actions.ts
new file mode 100644
index 00000000..18f62997
--- /dev/null
+++ b/src/store/gui/gcodehistory/actions.ts
@@ -0,0 +1,35 @@
+import { ActionTree } from 'vuex'
+import {RootState} from '@/store/types'
+import Vue from 'vue'
+import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
+import {maxGcodeHistory} from '@/store/variables'
+
+export const actions: ActionTree = {
+ reset({ commit }) {
+ commit('reset')
+ },
+
+ init() {
+ window.console.debug('init gui/gcodehistory')
+ Vue.$socket.emit('server.database.get_item', { namespace: 'mainsail_gcodehistory' }, { action: 'gui/gcodehistory/initStore' })
+ },
+
+ initStore({ commit }, payload) {
+ commit('reset')
+ commit('initStore', payload)
+ },
+
+ upload({ state }) {
+ Vue.$socket.emit('server.database.post_item', { namespace: 'mainsail_gcodehistory', key: 'history', value: state.history })
+ },
+
+ async addToHistory({ commit, dispatch, state }, payload) {
+ const newHistory = [...state.history]
+ newHistory.push(payload)
+
+ while (newHistory.length > maxGcodeHistory) newHistory.splice(0, 1)
+
+ await commit('updateHistory', newHistory)
+ await dispatch('upload')
+ }
+}
\ No newline at end of file
diff --git a/src/store/gui/gcodehistory/getters.ts b/src/store/gui/gcodehistory/getters.ts
new file mode 100644
index 00000000..0648790d
--- /dev/null
+++ b/src/store/gui/gcodehistory/getters.ts
@@ -0,0 +1,7 @@
+import { GetterTree } from 'vuex'
+import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
+
+// eslint-disable-next-line
+export const getters: GetterTree = {
+
+}
\ No newline at end of file
diff --git a/src/store/gui/gcodehistory/index.ts b/src/store/gui/gcodehistory/index.ts
new file mode 100644
index 00000000..2ecb0fe3
--- /dev/null
+++ b/src/store/gui/gcodehistory/index.ts
@@ -0,0 +1,23 @@
+import { Module } from 'vuex'
+import { actions } from '@/store/gui/gcodehistory/actions'
+import { mutations } from '@/store/gui/gcodehistory/mutations'
+import { getters } from '@/store/gui/gcodehistory/getters'
+import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
+
+export const getDefaultState = (): GuiGcodehistoryState => {
+ return {
+ history: [],
+ }
+}
+
+// initial state
+const state = getDefaultState()
+
+// eslint-disable-next-line
+export const gcodehistory: Module = {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations
+}
\ No newline at end of file
diff --git a/src/store/gui/gcodehistory/mutations.ts b/src/store/gui/gcodehistory/mutations.ts
new file mode 100644
index 00000000..36ddade1
--- /dev/null
+++ b/src/store/gui/gcodehistory/mutations.ts
@@ -0,0 +1,18 @@
+import { getDefaultState } from './index'
+import {MutationTree} from 'vuex'
+import Vue from 'vue'
+import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
+
+export const mutations: MutationTree = {
+ reset(state) {
+ Object.assign(state, getDefaultState())
+ },
+
+ initStore(state, payload) {
+ Vue.set(state, 'history', payload.value?.history)
+ },
+
+ updateHistory(state, payload) {
+ Vue.set(state, 'history', payload)
+ },
+}
\ No newline at end of file
diff --git a/src/store/gui/gcodehistory/types.ts b/src/store/gui/gcodehistory/types.ts
new file mode 100644
index 00000000..4fc127dc
--- /dev/null
+++ b/src/store/gui/gcodehistory/types.ts
@@ -0,0 +1,3 @@
+export interface GuiGcodehistoryState {
+ history: string[]
+}
\ No newline at end of file
diff --git a/src/store/gui/index.ts b/src/store/gui/index.ts
index 1d872ffa..684d63da 100644
--- a/src/store/gui/index.ts
+++ b/src/store/gui/index.ts
@@ -7,6 +7,7 @@ import {defaultLogoColor, defaultPrimaryColor} from '@/store/variables'
// load modules
import { consolefilters } from '@/store/gui/consolefilters'
+import { gcodehistory } from '@/store/gui/gcodehistory'
import { macrogroups } from '@/store/gui/macrogroups'
import { presets } from '@/store/gui/presets'
import { remoteprinters } from '@/store/gui/remoteprinters'
@@ -224,6 +225,7 @@ export const gui: Module = {
mutations,
modules: {
consolefilters,
+ gcodehistory,
macrogroups,
presets,
remoteprinters,
diff --git a/src/store/server/actions.ts b/src/store/server/actions.ts
index 90ac0a3c..1dfa2a1e 100644
--- a/src/store/server/actions.ts
+++ b/src/store/server/actions.ts
@@ -27,6 +27,7 @@ export const actions: ActionTree = {
if (payload.namespaces?.includes('webcams')) dispatch('gui/webcams/init', null, { root: true })
if (payload.namespaces?.includes('mainsail_presets')) dispatch('gui/presets/init', null, { root: true })
if (payload.namespaces?.includes('mainsail_consolefilters')) dispatch('gui/consolefilters/init', null, { root: true })
+ if (payload.namespaces?.includes('mainsail_gcodehistory')) dispatch('gui/gcodehistory/init', null, { root: true })
if (payload.namespaces?.includes('mainsail_macrogroups')) dispatch('gui/macrogroups/init', null, { root: true })
if (!rootState.socket?.remoteMode && payload.namespaces?.includes('mainsail_remoteprinters')) dispatch('gui/remoteprinters/init', null, { root: true })
diff --git a/src/store/server/mutations.ts b/src/store/server/mutations.ts
index bc65e9ca..8b3d3a24 100644
--- a/src/store/server/mutations.ts
+++ b/src/store/server/mutations.ts
@@ -97,10 +97,10 @@ export const mutations: MutationTree = {
},
setThrottledState(state, payload) {
- if ('bits' in payload)
+ if (payload && 'bits' in payload)
Vue.set(state.throttled_state, 'bits', payload.bits)
- if ('flags' in payload)
+ if (payload && 'flags' in payload)
Vue.set(state.throttled_state, 'flags', payload.flags)
},
diff --git a/src/store/variables.ts b/src/store/variables.ts
index 7a3ac547..0f05e2b1 100644
--- a/src/store/variables.ts
+++ b/src/store/variables.ts
@@ -79,6 +79,7 @@ export const allowedMetadata = [
]
export const maxEventHistory = 500
+export const maxGcodeHistory = 50
export const allDashboardPanels = [
'control',