import { v4 as generateId } from "uuid" ; import { DataState } from "../../../store/reducers/types" ; import { defaultData as defaultGiphyData } from "../../../plugins/backgrounds/giphy/types" ; import { defaultData as defaultGradientData } from "../../../plugins/backgrounds/gradient/types" ; import { defaultData as defaultUnsplashData } from "../../../plugins/backgrounds/unsplash/types" ; import { defaultData as defaultSearchData } from "../../../plugins/widgets/search/types" ; import { defaultData as defaultTimeData } from "../../../plugins/widgets/time/types" ; import { defaultData as defaultTodoData } from "../../../plugins/widgets/todo/types" ; export interface Version1Config { dashboard : { background : keyof typeof keyMap ; widgets : ( keyof typeof keyMap ) [ ] ; } ; storage : { [ key ] : { local : { [ key ] : any ; } ; settings : { [ key ] : any ; } ; } ; } ; settings : { locale ? : string ; timezone ? : string ; } ; } /**
 * Migrate Tabliss v1 config to v2
 */ export function migrateVersion1 ( config ) { const data = { } ; const backgrounds = [ { id : generateId ( ) , key : translateKey ( config . dashboard . background ) || "background/unsplash" , active : true , display : { blur : 0 , luminosity : 0 } , } , ] ; data [ backgrounds [ 0 ] . id ] = translateData ( config . dashboard . background , config . storage [ config . dashboard . background ] ) as object ; const fontSettings = config . storage [ "core/widgets/font" ] ; const fontDisplay = fontSettings ? { colour : fontSettings . settings . colour || "#ffffff" , fontFamily : fontSettings . settings . family , fontSize : fontSettings . settings . size || 28 , } : { } ; const widgets = config . dashboard . widgets . filter ( translateKey ) . map ( ( previousType ) => { const id = generateId ( ) ; const key = translateKey ( previousType ) as string ; data [ id ] = translateData ( previousType , config . storage [ previousType ] ) as object ; return { id , key , active : true , display : { ... fontDisplay , position : "middleCentre" , } , } ; } ) ; return { backgrounds , data , widgets , locale : config . settings . locale , timeZone : config . settings . timezone , } ; } const keyMap = { "core/backgrounds/colour" : "background/colour" , "extra/backgrounds/dribbble" : null , "extra/backgrounds/giphy" : "background/giphy" , "core/backgrounds/gradient" : "background/gradient" , "core/backgrounds/image" : "background/image" , "extra/backgrounds/unsplash" : "background/unsplash" , "core/widgets/css" : "widget/css" , "core/widgets/font" : null , "core/widgets/greeting" : "widget/greeting" , "widgets/js" : "widget/js" , "core/widgets/links" : "widget/links" , "widgets/literature-clock" : "widget/literature-clock" , "core/widgets/message" : "widget/message" , "extra/widgets/quote" : "widget/quote" , "core/widgets/reload" : null , "extra/widgets/search" : "widget/search" , "core/widgets/time" : "widget/time" , "widgets/todo" : "widget/todo" , "extra/widgets/weather" : "widget/weather" , } ; function translateKey ( key ) { return keyMap [ key ] ; } type Storage = { local : { [ key ] : any ; } ; settings : { [ key ] : any ; } ; } ; function translateData ( type , storage ? ) { switch ( type ) { case "extra/backgrounds/giphy" : return storage ? { ... defaultGiphyData , ... storage . settings } : undefined ; case "core/backgrounds/gradient" : return storage ? { ... defaultGradientData , ... storage . settings } : undefined ; case "core/backgrounds/image" : return undefined ; case "extra/backgrounds/unsplash" : return storage ? { ... defaultUnsplashData , ... storage . settings } : undefined ; case "core/widgets/links" : return storage ? { columns : 1 , ... storage . settings } : undefined ; case "core/widgets/message" : return storage && storage . settings ? { messages : [ storage . settings . message ] } : undefined ; case "extra/widgets/search" : return storage ? { ... defaultSearchData , ... storage . settings } : undefined ; case "core/widgets/time" : return storage ? { ... defaultTimeData , ... storage . settings } : undefined ; case "widgets/todo" : return storage ? { ... defaultTodoData , ... storage . settings , ... storage . local , } : undefined ; case "extra/widgets/weather" : return storage ? { showDetails : storage . local . details || false , latitude : storage . settings . latitude , longitude : storage . settings . longitude , units : storage . settings . units || "auto" , } : undefined ; default : return storage ? storage . settings : undefined ; } }