Skip to content

Commit

Permalink
make sure to load the latest version of default.json
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Aug 26, 2024
1 parent abef308 commit 873f625
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,35 @@ 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 = apiConfig.apiUrl + '/server/files/config/.fluidd-theme/default.json'
const now = new Date()
const defaultTemplateFile = apiConfig.apiUrl + '/server/files/config/.fluidd-theme/default.json?t=' + now.getTime().toString()
if (defaultTemplateFile?.length > 0) {
const backupData = await (await fetch(defaultTemplateFile)).json()
if (backupData) {
if (isFluiddContent<Record<string, unknown>>('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] || {})
if (key === 'charts') {
console.error(key)
await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.charts.dispatch, backupData.data[key] || {})
}
if (key === 'console') {
console.error(key)
await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.console.dispatch, backupData.data[key] || {})
}
if (key === 'layout') {
console.error(key)
await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.layout.dispatch, backupData.data[key] || {})
}
if (key === 'macros') {
console.error(key)
await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.macros.dispatch, backupData.data[key] || {})
}
if (key === 'uiSettings') {
console.error(key)
await store.dispatch(Globals.MOONRAKER_DB.fluidd.ROOTS.uiSettings.dispatch, backupData.data[key] || {})
}
}
}
} else {
Expand Down

0 comments on commit 873f625

Please sign in to comment.