恢复在线壁纸

This commit is contained in:
sbwml 2023-08-23 12:32:06 +08:00
parent f5a3312827
commit da6a2422d6
7 changed files with 177 additions and 38 deletions

View File

@ -49,6 +49,14 @@ return view.extend({
s.addremove = false;
s.anonymous = true;
o = s.option(form.ListValue, 'online_wallpaper', _('Wallpaper source'));
o.value('none', _('Built-in'));
o.value('bing', _('Bing'));
o.value('unsplash', _('Unsplash'));
o.value('wallhaven', _('Wallhaven'));
o.default = 'bing';
o.rmempty = false;
o = s.option(form.ListValue, 'mode', _('Theme mode'));
o.value('normal', _('Follow system'));
o.value('light', _('Light mode'));

View File

@ -6,4 +6,5 @@ config global
option transparency '0.2'
option transparency_dark '0.2'
option mode 'normal'
option online_wallpaper 'bing'

View File

@ -0,0 +1,14 @@
#!/bin/sh
bing_background="$(uci -q get "argon.@global[0].bing_background")"
[ -n "$bing_background" ] || exit 0
if [ "$bing_background" = "1" ]; then
uci -q set "argon.@global[0].online_wallpaper"="bing"
else
uci -q set "argon.@global[0].online_wallpaper"="none"
fi
uci -q delete "argon.@global[0].bing_background"
uci -q commit "argon"
exit 0

View File

@ -7,6 +7,7 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=Argon Theme
LUCI_DEPENDS:=+curl +jsonfilter
PKG_VERSION:=2.3.1
PKG_RELEASE:=20230420

View File

@ -1,3 +1,3 @@
登录页面背景图片目录
支持格式jpg、png、gif、webp、mp4
支持格式jpg、png、gif、webp、mp4、webm

View File

@ -23,12 +23,16 @@
<%+themes/argon/out_header_login%>
<%
local util = require "luci.util"
local boardinfo = util.ubus("system", "board")
local fs = require "nixio.fs"
local nutil = require "nixio.util"
local util = require "luci.util"
local fs = require "nixio.fs"
local nutil = require "nixio.util"
local json = require "luci.jsonc"
local sys = require "luci.sys"
local uci = require 'luci.model.uci'.cursor()
function glob(...)
-- Fetch Local Background Media
local function glob(...)
local iter, code, msg = fs.glob(...)
if iter then
return nutil.consume(iter)
@ -37,37 +41,70 @@
end
end
function getExtension(str)
return str:match(".+%.(%w+)$")
end
local bgcount = 0
local currentBg = {}
local bgs,attr = {}
local theme_dir = media .. "/background/"
for i, f in ipairs(glob("/www" .. theme_dir .. "*")) do
attr = fs.stat(f)
if attr then
local ext = getExtension(fs.basename(f))
if ext == "jpg" or ext == "png" or ext == "webp" or ext == "gif" or ext == "mp4" then
local bg = {}
bg.type = ext
bg.url = theme_dir .. fs.basename(f)
table.insert(bgs,bg)
bgcount = bgcount + 1
local imageTypes = " jpg png gif webp "
local videoTypes = " mp4 webm "
local allTypes = imageTypes .. videoTypes
local function fetchMedia(path, themeDir)
local backgroundTable = {}
local backgroundCount = 0
for i, f in ipairs(glob(path)) do
attr = fs.stat(f)
if attr then
local ext = fs.basename(f):match(".+%.(%w+)$")
if ext ~= nil then
ext = ext:lower()
end
if ext ~= nil and string.match(allTypes, " "..ext.." ") ~= nil then
local bg = {}
bg.type = ext
bg.url = themeDir .. fs.basename(f)
table.insert(backgroundTable, bg)
backgroundCount = backgroundCount + 1
end
end
end
return backgroundTable, backgroundCount
end
local function selectBackground(themeDir)
local bgUrl = media .. "/img/bg.webp"
local backgroundType = "Image"
local mimeType = ""
if fs.access("/etc/config/argon") then
local online_wallpaper = uci:get_first('argon', 'global', 'online_wallpaper') or (uci:get_first('argon', 'global', 'bing_background') == '1' and 'bing')
if (online_wallpaper and online_wallpaper ~= "none") then
local picurl = sys.exec("/usr/libexec/argon/online_wallpaper")
if (picurl and picurl ~= '') then
return picurl, "Image", ""
end
end
end
local backgroundTable, backgroundCount = fetchMedia("/www" .. themeDir .. "*", themeDir)
if ( backgroundCount > 0 ) then
local currentBg = backgroundTable[math.random(1, backgroundCount)]
bgUrl = currentBg.url
if (string.match(videoTypes, " "..currentBg.type.." ") ~= nil) then
backgroundType = "Video"
mimeType = "video/" .. currentBg.type
end
end
return bgUrl, backgroundType, mimeType
end
if bgcount > 0 then
currentBg = bgs[math.random(1,bgcount)]
end
local boardinfo = util.ubus("system", "board")
local themeDir = media .. "/background/"
local bgUrl, backgroundType, mimeType = selectBackground(themeDir)
%>
<!-- Login Page Start -->
<div class="login-page">
<% if (bgcount > 0 and currentBg.type == "mp4") then %>
<% if ( backgroundType == "Video" ) then %>
<!-- Video Player Start -->
<div class="video">
<video autoplay loop muted id="video">
<source src="<%=currentBg.url%>" type="video/mp4">
<source src="<%=bgUrl%>" type="<%=mimeType%>">
</video>
</div>
<div class="volume-control mute"></div>
@ -82,18 +119,21 @@
}
})
</script>
<% else
local bg_url = media .. "/img/bg.webp"
if (bgcount > 0 and currentBg["type"] ~= "mp4") then
bg_url = currentBg.url
end
%>
<div class="main-bg" id="main-bg" style="background-image:url(<%=bg_url%>)"></div>
<!-- Video Player End -->
<% else %>
<!-- Image Background Start -->
<div class="main-bg" id="main-bg" style="background-image:url(<%=bgUrl%>)"></div>
<!-- Image Background End -->
<% end %>
<!-- Login Container Start -->
<div class="login-container">
<div class="login-form">
<a class="brand" href="/"><img src="<%=media%>/img/argon.svg" class="icon"><span
class="brand-text"><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %></span></a>
<!-- Logo Start -->
<a class="brand" href="/"><img src="<%=media%>/img/argon.svg" class="icon">
<span class="brand-text"><%=striptags( (boardinfo.hostname or "?") ) %></span>
</a>
<!-- Logo End -->
<!-- Login Form Start -->
<form class="form-login" method="post" action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
<%- if fuser then %>
@ -114,7 +154,7 @@
<input type="submit" value="<%:Login%>" class="cbi-button cbi-button-apply" />
</div>
</form>
<!-- Login Form End -->
<script type="text/javascript">//<![CDATA[
var input = document.getElementsByName('luci_password')[0];
if (input)

View File

@ -0,0 +1,75 @@
#!/bin/sh
# author jjm2473
# the script will be excuted when `argon.@global[0].bing_background == '1'`
# defaults to 'bing' to be compatible with old config
WEB_PIC_SRC=$(uci -q get argon.@global[0].online_wallpaper || echo 'bing')
CACHE=/var/run/argon_${WEB_PIC_SRC}.url
WRLOCK=/var/lock/argon_${WEB_PIC_SRC}.lock
fetch_pic_url() {
case $WEB_PIC_SRC in
bing)
local picpath=$(curl -fks --max-time 3 \
"https://www.bing.com/HPImageArchive.aspx?format=js&n=1" |
jsonfilter -qe '@.images[0].url')
[ -n "${picpath}" ] && echo "//www.bing.com${picpath}"
;;
unsplash)
curl -fks --max-time 3 \
"https://source.unsplash.com/1920x1080/daily?wallpapers" |
sed -E 's#^.*href="([^?]+)\?.*$#\1?fm=jpg\&fit=crop\&w=1920\&h=1080#'
;;
unsplash_*)
local collection_id=${WEB_PIC_SRC#unsplash_}
curl -fks --max-time 3 \
"https://source.unsplash.com/collection/${collection_id}/1920x1080" |
sed -E 's#^.*href="([^?]+)\?.*$#\1?fm=jpg\&fit=crop\&w=1920\&h=1080#'
;;
wallhaven)
curl -fks --max-time 3 \
"https://wallhaven.cc/api/v1/search?resolutions=1920x1080&sorting=random" |
jsonfilter -qe '@.data[0].path'
;;
esac
}
try_update() {
local lock="$WRLOCK"
exec 200>$lock
if flock -n 200 >/dev/null 2>&1; then
local picurl=$(fetch_pic_url)
if [ -n "$picurl" ]; then
echo "${picurl}" | tee "$CACHE"
else
if [ -s "$CACHE" ]; then
cat "$CACHE"
else
touch "$CACHE"
fi
fi
flock -u 200 >/dev/null 2>&1
elif [ -s "$CACHE" ]; then
cat "$CACHE"
fi
}
get_url() {
if [ -f "$CACHE" ]; then
local idle_t=$(($(date '+%s') - $(date -r "$CACHE" '+%s' 2>/dev/null || echo '0')))
if [ -s "$CACHE" ]; then
if [ $idle_t -le 43200 ]; then
cat "$CACHE"
return
fi
else
if [ $idle_t -le 120 ]; then
return
fi
fi
fi
try_update
}
get_url