From 2215269d2dc877c2ccf57b86880f1d403b2238e3 Mon Sep 17 00:00:00 2001 From: HelgeKeck Date: Thu, 1 Aug 2024 20:40:43 +0200 Subject: [PATCH 1/4] load default template --- src/init.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/init.ts b/src/init.ts index 6d1add72e1..bd4d4834b7 100644 --- a/src/init.ts +++ b/src/init.ts @@ -10,6 +10,7 @@ import sanitizeEndpoint from './util/sanitize-endpoint' import webSocketWrapper from './util/web-socket-wrapper' import promiseAny from './util/promise-any' import sleep from './util/sleep' +import { isFluiddContent } from '@/util/fluidd-content' // Load API configuration /** @@ -176,6 +177,7 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P // Load any configuration we may have in moonrakers db let apiConnected = true let apiAuthenticated = true + let configLoaded = false for (const { NAMESPACE, ROOTS } of Object.values(Globals.MOONRAKER_DB)) { if (!apiConnected && !apiAuthenticated) { break @@ -217,6 +219,32 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P }) await Promise.all(promises) + configLoaded = true + } + + // if no moonraker config has been loaded check for a default template inside .fluidd-theme folder + configLoaded = false + if (!configLoaded) { + try { + const defaultTemplateFile = store.getters['config/getCustomThemeFile']('default', ['.json']) + if (defaultTemplateFile?.length > 0) { + const responseDefault = await fetch(defaultTemplateFile) + let defaults: any = {} + if (responseDefault) { + defaults = await responseDefault.json() + if (defaults.error?.code !== 404) { + const backupData = JSON.parse(defaults) + if (isFluiddContent>('settings-backup', backupData)) { + for (const key in backupData.data) { + await httpClientActions.serverDatabaseItemPost('fluidd', key, backupData.data[key]) + } + } + } + } + } + } catch (e) { + consola.debug('Error loading default settings', e) + } } // apiConfig could have empty strings, meaning we have no valid connection. From 5f248dd3dc5721ef414922ba667f7ea46188285e Mon Sep 17 00:00:00 2001 From: HelgeKeck Date: Thu, 1 Aug 2024 20:47:52 +0200 Subject: [PATCH 2/4] removed setting configLoaded for testing pruposes --- src/init.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/init.ts b/src/init.ts index bd4d4834b7..025f4e7e9d 100644 --- a/src/init.ts +++ b/src/init.ts @@ -223,7 +223,6 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P } // if no moonraker config has been loaded check for a default template inside .fluidd-theme folder - configLoaded = false if (!configLoaded) { try { const defaultTemplateFile = store.getters['config/getCustomThemeFile']('default', ['.json']) From c052dba3c504e919739c31530b822d95cbd85344 Mon Sep 17 00:00:00 2001 From: HelgeKeck Date: Fri, 2 Aug 2024 02:10:49 +0200 Subject: [PATCH 3/4] working load default settings at startup --- src/init.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/init.ts b/src/init.ts index 025f4e7e9d..6d50fbf8ce 100644 --- a/src/init.ts +++ b/src/init.ts @@ -225,24 +225,30 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P // if no moonraker config has been loaded check for a default template inside .fluidd-theme folder if (!configLoaded) { try { - const defaultTemplateFile = store.getters['config/getCustomThemeFile']('default', ['.json']) + const defaultTemplateFile = apiConfig.apiUrl + '/server/files/config/.fluidd-theme/default.json' if (defaultTemplateFile?.length > 0) { - const responseDefault = await fetch(defaultTemplateFile) - let defaults: any = {} - if (responseDefault) { - defaults = await responseDefault.json() - if (defaults.error?.code !== 404) { - const backupData = JSON.parse(defaults) - if (isFluiddContent>('settings-backup', backupData)) { - for (const key in backupData.data) { + const backupData = await (await fetch(defaultTemplateFile)).json() + if (backupData) { + if (isFluiddContent>('settings-backup', backupData)) { + for (const key in backupData.data) { + if (key !== 'webcams') { await httpClientActions.serverDatabaseItemPost('fluidd', key, backupData.data[key]) + if (key === 'charts') await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.charts.dispatch, backupData.data[key] || {}) + if (key === 'console') await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.console.dispatch, backupData.data[key] || {}) + if (key === 'layout') await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.layout.dispatch, backupData.data[key] || {}) + if (key === 'macros') await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.macros.dispatch, backupData.data[key] || {}) + if (key === 'uiSettings') await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.uiSettings.dispatch, backupData.data[key] || {}) } } + } else { + console.error('Error loading default settings') } + } else { + console.error('Error loading default settings') } } } catch (e) { - consola.debug('Error loading default settings', e) + console.error('Error loading default settings: ' + e) } } From 3c9d1ca209209d55abf0ada9431b0557580130d5 Mon Sep 17 00:00:00 2001 From: HelgeKeck Date: Fri, 2 Aug 2024 02:11:57 +0200 Subject: [PATCH 4/4] fixed the v detection --- components.d.ts | 14 +------------- src/init.ts | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/components.d.ts b/components.d.ts index dd1589584a..6cacfb3216 100644 --- a/components.d.ts +++ b/components.d.ts @@ -1,10 +1,10 @@ /* eslint-disable */ -/* prettier-ignore */ // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 export {} +/* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { ActionCommandPromptDialog: typeof import('./src/components/common/ActionCommandPromptDialog.vue')['default'] @@ -85,22 +85,15 @@ declare module 'vue' { VDialog: typeof import('vuetify/lib')['VDialog'] VDivider: typeof import('vuetify/lib')['VDivider'] VExpandTransition: typeof import('vuetify/lib')['VExpandTransition'] - VExpansionPanel: typeof import('vuetify/lib')['VExpansionPanel'] - VExpansionPanelContent: typeof import('vuetify/lib')['VExpansionPanelContent'] - VExpansionPanelHeader: typeof import('vuetify/lib')['VExpansionPanelHeader'] - VExpansionPanels: typeof import('vuetify/lib')['VExpansionPanels'] - VFadeTransition: typeof import('vuetify/lib')['VFadeTransition'] VFooter: typeof import('vuetify/lib')['VFooter'] VForm: typeof import('vuetify/lib')['VForm'] VIcon: typeof import('vuetify/lib')['VIcon'] - VItemGroup: typeof import('vuetify/lib')['VItemGroup'] VLayout: typeof import('vuetify/lib')['VLayout'] VList: typeof import('vuetify/lib')['VList'] VListGroup: typeof import('vuetify/lib')['VListGroup'] VListItem: typeof import('vuetify/lib')['VListItem'] VListItemAction: typeof import('vuetify/lib')['VListItemAction'] VListItemContent: typeof import('vuetify/lib')['VListItemContent'] - VListItemGroup: typeof import('vuetify/lib')['VListItemGroup'] VListItemIcon: typeof import('vuetify/lib')['VListItemIcon'] VListItemSubtitle: typeof import('vuetify/lib')['VListItemSubtitle'] VListItemTitle: typeof import('vuetify/lib')['VListItemTitle'] @@ -115,7 +108,6 @@ declare module 'vue' { VRow: typeof import('vuetify/lib')['VRow'] VSelect: typeof import('vuetify/lib')['VSelect'] VSheet: typeof import('vuetify/lib')['VSheet'] - VSimpleCheckbox: typeof import('vuetify/lib')['VSimpleCheckbox'] VSimpleTable: typeof import('vuetify/lib')['VSimpleTable'] VSlider: typeof import('vuetify/lib')['VSlider'] VSnackbar: typeof import('vuetify/lib')['VSnackbar'] @@ -133,12 +125,8 @@ declare module 'vue' { VTabsItems: typeof import('vuetify/lib')['VTabsItems'] VTextarea: typeof import('vuetify/lib')['VTextarea'] VTextField: typeof import('vuetify/lib')['VTextField'] - VTimeline: typeof import('vuetify/lib')['VTimeline'] - VTimelineItem: typeof import('vuetify/lib')['VTimelineItem'] VToolbar: typeof import('vuetify/lib')['VToolbar'] - VToolbarItems: typeof import('vuetify/lib')['VToolbarItems'] VToolbarTitle: typeof import('vuetify/lib')['VToolbarTitle'] VTooltip: typeof import('vuetify/lib')['VTooltip'] - VVirtualScroll: typeof import('vuetify/lib')['VVirtualScroll'] } } diff --git a/src/init.ts b/src/init.ts index 6d50fbf8ce..272a866fec 100644 --- a/src/init.ts +++ b/src/init.ts @@ -209,6 +209,7 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P if (!value) { try { await httpClientActions.serverDatabaseItemPost(NAMESPACE, root.name, {}) + configLoaded = true } catch (e) { consola.debug('Error creating database item', e) } @@ -219,7 +220,6 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P }) await Promise.all(promises) - configLoaded = true } // if no moonraker config has been loaded check for a default template inside .fluidd-theme folder