Skip to content

Commit

Permalink
luci-app-argon-config: adapt to theme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MkQtS committed Mar 29, 2024
1 parent 2e5188a commit 0ea325f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,30 @@ return view.extend({
s.addremove = false;
s.anonymous = true;

o = s.option(form.ListValue, 'online_wallpaper', _('Wallpaper source'));
o.value('none', _('Built-in'));
o = s.option(form.ListValue, 'bg_mode', _('Background mode'));
o.value('local_media', _('Local media files'));
o.value('wallpaper_url', _('Wallpaper URL'));
o.value('online_wallpaper', _('Fetch from Internet'));
o.default = 'wallpaper_url';
o.rmempty = false;

o = s.option(form.Value, 'wallpaper_url', _('Wallpaper URL'),
_('Set a picture URL here, some API link also works. Some URL may fail due to CORS policy.'));
o.value('https://source.unsplash.com/1920x1080/daily?wallpapers');
o.value('https://source.unsplash.com/collection/30697288/1920x1080');
o.value('https://cn.bing.com/th?id=OHR.BwindiNationalForest_ZH-CN0436137473_1920x1080.jpg');
o.depends('bg_mode', 'wallpaper_url');
o.retain = true;
o.rmempty = false;

o = s.option(form.ListValue, 'online_wallpaper', _('Online wallpaper source'));
o.value('bing', _('Bing'));
o.value('ghser', _('GHSer'));
o.value('unsplash', _('Unsplash'));
o.value('konachan', _('Konachan'));
o.value('pic.re', _('Pic.re'));
o.value('wallhaven', _('Wallhaven'));
o.depends('bg_mode', 'online_wallpaper')
o.default = 'bing';
o.retain = true;
o.rmempty = false;

o = s.option(form.ListValue, 'mode', _('Theme mode'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
#!/bin/sh

bing_background="$(uci -q get "argon.@global[0].bing_background")"
[ -n "$bing_background" ] || exit 0
[ $(uci -q get "argon.@global[0].bg_mode") ] && exit 0

bing_background="$(uci -q get "argon.@global[0].bing_background")"
if [ "$bing_background" = "1" ]; then
uci -q set "argon.@global[0].online_wallpaper"="bing"
uci -q del "argon.@global[0].bing_background"
elif [ "$bing_background" = "0" ]; then
uci -q del "argon.@global[0].bing_background"
fi

online_wallpaper="$(uci -q get "argon.@global[0].online_wallpaper")"
if [ ! "$online_wallpaper" ]; then
uci -q set "argon.@global[0].bg_mode"="local_media"
elif [ "$online_wallpaper" = "none" ]; then
uci -q set "argon.@global[0].bg_mode"="local_media"
uci -q del "argon.@global[0].online_wallpaper"
else
uci -q set "argon.@global[0].online_wallpaper"="none"
uci -q set "argon.@global[0].bg_mode"="online_wallpaper"
fi
uci -q delete "argon.@global[0].bing_background"
uci -q commit "argon"

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,28 @@ WRLOCK="/var/lock/argon_${PIC_SRC}.lock"

fetch_pic_url() {
case "$PIC_SRC" in
bing)
local picpath="$(wget -T3 -qO- \
"https://www.bing.com/HPImageArchive.aspx?format=js&n=1" |
jsonfilter -qe '@.images[0].url')"
[ -n "${picpath}" ] && echo "//www.bing.com${picpath}"
;;
ghser)
echo "https://api.vvhan.com/api/wallpaper/acg"
;;
unsplash)
local pic_id="$(wget -T3 --spider \
"https://source.unsplash.com/1920x1080/daily?wallpapers" 2>&1 |
grep -Eo "photo-\w+-\w+" | head -n1)"
[ -n "${pic_id}" ] && echo "https://images.unsplash.com/${pic_id}?fm=jpg&fit=crop&w=1920&h=1080"
;;
unsplash_*)
local collection_id="${PIC_SRC#unsplash_}"
local pic_id="$(wget -T3 --spider \
"https://source.unsplash.com/collection/${collection_id}/1920x1080" 2>&1 |
grep -Eo "photo-\w+-\w+" | head -n1)"
[ -n "${pic_id}" ] && echo "https://images.unsplash.com/${pic_id}?fm=jpg&fit=crop&w=1920&h=1080"
;;
wallhaven)
wget -T3 -qO- \
"https://wallhaven.cc/api/v1/search?resolutions=1920x1080&sorting=random" |
jsonfilter -qe "@.data[0].path"
;;
*)
exit 1
;;
'bing')
local picpath="$(wget -T3 -qO- "https://www.bing.com/HPImageArchive.aspx?format=js&n=1" |
jsonfilter -qe '@.images[0].url')"
[ -n "$picpath" ] && echo "//www.bing.com${picpath}"
;;
'konachan')
local tagday="date:$(date -d @$(( $(date +%s) - 86400 )) +"%Y-%m-%d")"
wget -T3 -qO- "https://konachan.net/post.json?tags=${tagday}&limit=2" |
jsonfilter -qe '@[1].file_url'
;;
'pic.re')
local fileurl="$(wget -T3 -qO- "https://pic.re/image.json" |
jsonfilter -qe '@.file_url')"
[ -n "$fileurl" ] && echo "//${fileurl}"
;;
'wallhaven')
wget -T3 -qO- "https://wallhaven.cc/api/v1/search?resolutions=1920x1080&sorting=random" |
jsonfilter -qe "@.data[0].path"
;;
*)
exit 1
;;
esac
}

Expand Down

0 comments on commit 0ea325f

Please sign in to comment.