Skip to content

Commit

Permalink
Update init.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Aug 1, 2024
1 parent 8e3320a commit 04803ba
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,37 +222,41 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P
configLoaded = true
}

// apiConfig could have empty strings, meaning we have no valid connection.
await store.dispatch('init', { apiConfig, hostConfig, apiConnected })

// Ensure users start on the dash.
if (router.currentRoute.path !== '/' && store.state.auth.authenticated) router.push('/')

// 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'])
// const defaultTemplateFile = 'http://vc4.local:8081/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) {
console.error('6')
const backupData = JSON.parse(defaults)
console.error('7')
if (isFluiddContent<Record<string, unknown>>('settings-backup', backupData)) {
console.error('8')
for (const key in backupData.data) {
console.error('9')
await httpClientActions.serverDatabaseItemPost('fluidd', key, backupData.data[key])
}
}
}
}
}
} catch (e) {
console.error('Error loading default settings')
consola.debug('Error loading default settings', e)
console.error('Error loading default settings: ' + e)
}
}

// apiConfig could have empty strings, meaning we have no valid connection.
await store.dispatch('init', { apiConfig, hostConfig, apiConnected })

// Ensure users start on the dash.
if (router.currentRoute.path !== '/' && store.state.auth.authenticated) router.push('/')

return { apiConfig, hostConfig, apiConnected, apiAuthenticated }
}

0 comments on commit 04803ba

Please sign in to comment.