diff --git a/.env.development.local.example b/.env.development.local.example index 75e02c500..a818e9f67 100644 --- a/.env.development.local.example +++ b/.env.development.local.example @@ -7,8 +7,8 @@ VUE_APP_PORT=7125 # reconnect interval in ms VUE_APP_RECONNECT_INTERVAL=5000 -# remote mode -VUE_APP_REMOTE_MODE=false +# where should mainsail read the instances from (moonraker, browser or json) +VUE_APP_INSTANCES_DB="moonraker" # defaults for multi language tests VUE_APP_I18N_LOCALE=en diff --git a/public/config.json b/public/config.json index d2a269291..e782b5c4b 100644 --- a/public/config.json +++ b/public/config.json @@ -1,8 +1,6 @@ { "hostname": null, "port": null, - "remoteMode": false, - "instances": [ - - ] + "instancesDB": "moonraker", + "instances": [] } diff --git a/src/App.vue b/src/App.vue index 4aa8e4cfe..45bd13d51 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,7 +40,7 @@ - + diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 34c43913e..8e82c03c6 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -173,31 +173,40 @@ - - -

- {{ $t('SelectPrinterDialog.Hello') }} -

+ + +

- {{ $t('SelectPrinterDialog.RememberToAdd', { cors: currentUrl }) }} -

-

- {{ $t('SelectPrinterDialog.YouCanFindMore') }} -
- - https://docs.mainsail.xyz/remotemode - - . + {{ $t('SelectPrinterDialog.AddPrintersToJson') }}

- - - - {{ $t('SelectPrinterDialog.AddPrinter') }} - - - @@ -254,7 +263,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { } get canAddPrinters() { - return this.$store.state.configInstances.length === 0 + return this.instancesDB !== 'json' } get protocol() { diff --git a/src/components/mixins/base.ts b/src/components/mixins/base.ts index c1e486863..3c9863431 100644 --- a/src/components/mixins/base.ts +++ b/src/components/mixins/base.ts @@ -11,8 +11,8 @@ export default class BaseMixin extends Vue { return this.$store.getters['socket/getHostUrl'] } - get remoteMode() { - return this.$store.state.remoteMode + get instancesDB() { + return this.$store.state.instancesDB ?? 'moonraker' } get socketIsConnected(): boolean { diff --git a/src/components/settings/SettingsRemotePrintersTab.vue b/src/components/settings/SettingsRemotePrintersTab.vue index 28c3e4e21..be8c806e6 100644 --- a/src/components/settings/SettingsRemotePrintersTab.vue +++ b/src/components/settings/SettingsRemotePrintersTab.vue @@ -3,6 +3,9 @@

{{ $t('Settings.RemotePrintersTab.RemotePrinters') }}

+ + {{ $t('Settings.RemotePrintersTab.UseConfigJson') }} +
1) || (!this.remoteMode && this.countPrinters) + return ( + (this.instancesDB !== 'moonraker' && this.countPrinters > 1) || + (this.instancesDB === 'moonraker' && this.countPrinters) + ) } get printers() { diff --git a/src/locales/de.json b/src/locales/de.json index ff8b5004d..afa2e89e8 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -663,6 +663,7 @@ }, "SelectPrinterDialog": { "AddPrinter": "Drucker hinzufügen", + "AddPrintersToJson": "Bitte füge einen Drucker in der config.json hinzu.", "CannotConnectTo": "Kann keine Verbindung zu {host} herstellen.", "ChangePrinter": "Drucker ändern", "Connecting": "Verbinde zu {host}", @@ -852,7 +853,8 @@ "Hostname": "Hostname", "Port": "Port", "RemotePrinters": "Remote Drucker", - "UpdatePrinter": "Drucker aktualisieren" + "UpdatePrinter": "Drucker aktualisieren", + "UseConfigJson": "InstanceDB = JSON erkannt. Bitte bearbeite die config.json um die Druckerliste zu modifizieren." }, "TimelapseTab": { "Autorender": "Autorender", diff --git a/src/locales/en.json b/src/locales/en.json index 5e3993527..3bfac7a9c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -654,6 +654,7 @@ "HostnameInvalid": "invalid Hostname/IP", "HostnameIp": "Hostname/IP", "HostnameRequired": "Hostname is required", + "AddPrintersToJson": "Please add the Printers to the config.json.", "Port": "Port", "PortRequired": "Port is required", "RememberToAdd": "Please remember to add '{cors}' in moonraker.conf within 'cors_domains'.", @@ -834,7 +835,8 @@ "Hostname": "Hostname", "Port": "Port", "RemotePrinters": "Printers", - "UpdatePrinter": "Update Printer" + "UpdatePrinter": "Update Printer", + "UseConfigJson": "InstanceDB = JSON detected. Please use the config.json to modify the printers list." }, "TimelapseTab": { "Autorender": "Autorender", diff --git a/src/main.ts b/src/main.ts index 738efd42d..452fd1ccc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,7 +89,7 @@ const initLoad = async () => { const url = store.getters['socket/getWebsocketUrl'] Vue.use(WebSocketPlugin, { url, store }) - if (!store?.state?.remoteMode) Vue.$socket.connect() + if (store?.state?.instancesDB === 'moonraker') Vue.$socket.connect() } initLoad() diff --git a/src/store/actions.ts b/src/store/actions.ts index 087371ab4..966101e52 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -8,8 +8,6 @@ export const actions: ActionTree = { }, changePrinter({ dispatch, getters, state }, payload) { - const remoteMode = state.remoteMode - dispatch('files/reset') dispatch('gui/reset') dispatch('printer/reset') @@ -32,11 +30,21 @@ export const actions: ActionTree = { * This function will parse the config.json content and config mainsail */ importConfigJson({ commit, dispatch }, payload: ConfigJson) { - const remoteMode = payload.remoteMode ?? false - if (remoteMode) { - commit('setRemoteMode', true) - - if ('instances' in payload && Array.isArray(payload.instances) && payload.instances.length) { + type RootStateInstancesDbType = 'moonraker' | 'browser' | 'json' + let instancesDB: RootStateInstancesDbType = payload.instancesDB ?? 'moonraker' + if (document.location.hostname === 'my.mainsail.xyz') instancesDB = 'browser' + if (import.meta.env.VUE_APP_INSTANCES_DB) + instancesDB = import.meta.env.VUE_APP_INSTANCES_DB as RootStateInstancesDbType + + if (instancesDB !== 'moonraker') { + commit('setInstancesDB', instancesDB) + + if ( + instancesDB === 'json' && + 'instances' in payload && + Array.isArray(payload.instances) && + payload.instances.length + ) { commit('setConfigInstances', payload.instances) } diff --git a/src/store/gui/actions.ts b/src/store/gui/actions.ts index 3904606c4..aab4627f2 100644 --- a/src/store/gui/actions.ts +++ b/src/store/gui/actions.ts @@ -26,7 +26,8 @@ export const actions: ActionTree = { const mainsailUrl = baseUrl + '?namespace=mainsail' if ('remoteprinters' in payload.value) { - if (!rootState.remoteMode) dispatch('remoteprinters/initStore', payload.value.remoteprinters.printers) + if (rootState.instancesDB === 'moonraker') + dispatch('remoteprinters/initStore', payload.value.remoteprinters.printers) delete payload.value.remoteprinters } diff --git a/src/store/gui/remoteprinters/actions.ts b/src/store/gui/remoteprinters/actions.ts index 452b1ebd1..93d9abf5f 100644 --- a/src/store/gui/remoteprinters/actions.ts +++ b/src/store/gui/remoteprinters/actions.ts @@ -15,7 +15,7 @@ export const actions: ActionTree = { initFromLocalstorage({ dispatch, rootState }) { let value = rootState.configInstances ?? [] - if (value.length === 0) value = JSON.parse(localStorage.getItem('printers') ?? '{}') + if (rootState.instancesDB === 'moonraker') value = JSON.parse(localStorage.getItem('printers') ?? '{}') if (Array.isArray(value)) { const printers: any = {} @@ -47,7 +47,7 @@ export const actions: ActionTree = { }, upload({ state, rootState }, id) { - if (rootState.remoteMode) { + if (rootState.instancesDB === 'browser') { const printers: any[] = [] Object.keys(state.printers).forEach((id: string) => { @@ -59,7 +59,7 @@ export const actions: ActionTree = { }) localStorage.setItem('printers', JSON.stringify(printers)) - } else if (id in state.printers) { + } else if (rootState.instancesDB === 'moonraker' && id in state.printers) { const value = { hostname: state.printers[id].hostname, port: state.printers[id].port, @@ -112,7 +112,7 @@ export const actions: ActionTree = { commit('delete', id) dispatch('farm/unregisterPrinter', id, { root: true }) - if (rootState.remoteMode) dispatch('upload') + if (rootState.instancesDB === 'browser') dispatch('upload') else { Vue.$socket.emit('server.database.delete_item', { namespace: 'mainsail', diff --git a/src/store/index.ts b/src/store/index.ts index 8820032b4..5ff2eee83 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -18,20 +18,11 @@ import { gcodeviewer } from '@/store/gcodeviewer' Vue.use(Vuex) export const getDefaultState = (): RootState => { - let remoteMode = false - - if ( - document.location.hostname === 'my.mainsail.xyz' || - String(import.meta.env.VUE_APP_REMOTE_MODE).toLowerCase() === 'true' || - String(import.meta.env.VUE_APP_REMOTE_MODE) === '1' - ) - remoteMode = true - return { packageVersion: (import.meta.env.PACKAGE_VERSION as string) || '0.0.0', debugMode: (import.meta.env.VUE_APP_DEBUG_MODE as boolean) || false, naviDrawer: null, - remoteMode, + instancesDB: 'moonraker', configInstances: [], } } diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 8827a6122..1186708d7 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -7,8 +7,8 @@ export const mutations: MutationTree = { Vue.set(state, 'naviDrawer', payload) }, - setRemoteMode(state, payload) { - Vue.set(state, 'remoteMode', payload) + setInstancesDB(state, payload) { + Vue.set(state, 'instancesDB', payload) }, setConfigInstances(state, payload) { diff --git a/src/store/types.ts b/src/store/types.ts index 8a8d7ba08..1c48ecfb7 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -8,7 +8,7 @@ export interface RootState { packageVersion: string debugMode: boolean naviDrawer: boolean | null - remoteMode: boolean + instancesDB: 'moonraker' | 'browser' | 'json' configInstances: ConfigJsonInstance[] socket?: SocketState @@ -27,7 +27,7 @@ export interface RootStateDependency { export interface ConfigJson { hostname?: string | null port?: string | number | null - remoteMode?: boolean + instancesDB?: 'moonraker' | 'browser' | 'json' instances?: ConfigJsonInstance[] }