diff --git a/luci-app-argon-config/htdocs/luci-static/resources/view/argon-config.js b/luci-app-argon-config/htdocs/luci-static/resources/view/argon-config.js index f76641b..8f2db94 100644 --- a/luci-app-argon-config/htdocs/luci-static/resources/view/argon-config.js +++ b/luci-app-argon-config/htdocs/luci-static/resources/view/argon-config.js @@ -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')); diff --git a/luci-app-argon-config/root/etc/config/argon b/luci-app-argon-config/root/etc/config/argon index 0d9d959..5d11d6e 100644 --- a/luci-app-argon-config/root/etc/config/argon +++ b/luci-app-argon-config/root/etc/config/argon @@ -6,4 +6,5 @@ config global option transparency '0.2' option transparency_dark '0.2' option mode 'normal' + option online_wallpaper 'bing' diff --git a/luci-app-argon-config/root/etc/uci-defaults/luci-argon-config b/luci-app-argon-config/root/etc/uci-defaults/luci-argon-config new file mode 100755 index 0000000..9fc0b56 --- /dev/null +++ b/luci-app-argon-config/root/etc/uci-defaults/luci-argon-config @@ -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 diff --git a/luci-theme-argon/Makefile b/luci-theme-argon/Makefile index c1f12a4..8e90e56 100644 --- a/luci-theme-argon/Makefile +++ b/luci-theme-argon/Makefile @@ -7,6 +7,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=Argon Theme +LUCI_DEPENDS:=+curl +jsonfilter PKG_VERSION:=2.3.1 PKG_RELEASE:=20230420 diff --git a/luci-theme-argon/htdocs/luci-static/argon/background/README.md b/luci-theme-argon/htdocs/luci-static/argon/background/README.md index b154d62..c919c6b 100644 --- a/luci-theme-argon/htdocs/luci-static/argon/background/README.md +++ b/luci-theme-argon/htdocs/luci-static/argon/background/README.md @@ -1,3 +1,3 @@ 登录页面背景图片目录 -支持格式:jpg、png、gif、webp、mp4 +支持格式:jpg、png、gif、webp、mp4、webm diff --git a/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm b/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm index 71e0125..710fdcd 100644 --- a/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm +++ b/luci-theme-argon/luasrc/view/themes/argon/sysauth.htm @@ -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) %> +