Skip to content

Commit

Permalink
Add wallhaven
Browse files Browse the repository at this point in the history
  • Loading branch information
trmdi committed Nov 24, 2024
1 parent bdce899 commit 541f75f
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/scripts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export const SYNC_DEFAULT: Sync.Storage = {
pausedImage: undefined,
time: undefined,
},
wallhaven: {
every: 'hour',
parameters: '',
lastParams: 'day',
pausedImage: undefined,
time: undefined,
},
weather: {
ccode: undefined,
city: undefined,
Expand Down Expand Up @@ -193,4 +200,11 @@ export const LOCAL_DEFAULT: Local.Storage = {
night: [],
user: [],
},
wallhavenCache: {
noon: [],
day: [],
evening: [],
night: [],
user: [],
},
}
27 changes: 23 additions & 4 deletions src/scripts/features/backgrounds/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unsplashBackgrounds from './unsplash'
import wallhavenBackgrounds from './wallhaven'
import localBackgrounds from './local'
import { rgbToHex } from '../../utils'
import { eventDebounce } from '../../utils/debounce'
Expand Down Expand Up @@ -30,7 +31,13 @@ export default function initBackground(data: Sync.Storage, local: Local.Storage)
bgsecond.style.transform = 'scale(1.1) translateX(0px) translate3d(0, 0, 0)'
}

type === 'local' ? localBackgrounds() : unsplashBackgrounds({ unsplash: data.unsplash, cache: local.unsplashCache })
if (type === 'local') {
localBackgrounds()
} else if (type === 'unsplash') {
unsplashBackgrounds({ unsplash: data.unsplash, cache: local.unsplashCache })
} else if (type === 'wallhaven') {
wallhavenBackgrounds({ wallhaven: data.wallhaven, cache: local.wallhavenCache })
}
}

//
Expand Down Expand Up @@ -86,14 +93,26 @@ export function backgroundFilter({ blur, brightness, isEvent }: FilterOptions) {

export function updateBackgroundOption({ freq, refresh }: UpdateOptions) {
const i_type = document.getElementById('i_type') as HTMLInputElement
const isLocal = i_type.value === 'local'
const type = i_type.value || 'unsplash'

if (freq !== undefined) {
isLocal ? localBackgrounds({ freq }) : unsplashBackgrounds(undefined, { every: freq })
if (type === 'local') {
localBackgrounds({ freq })
} else if (type === 'unsplash') {
unsplashBackgrounds(undefined, { every: freq })
} else if (type === 'wallhaven') {
wallhavenBackgrounds(undefined, { every: freq })
}
}

if (refresh) {
isLocal ? localBackgrounds({ refresh }) : unsplashBackgrounds(undefined, { refresh })
if (type === 'local') {
localBackgrounds({ refresh })
} else if (type === 'unsplash') {
unsplashBackgrounds(undefined, { refresh })
} else if (type === 'wallhaven') {
wallhavenBackgrounds(undefined, { refresh })
}
}
}

Expand Down
Loading

0 comments on commit 541f75f

Please sign in to comment.