mirror of
				https://github.com/kenzok8/openwrt-packages.git
				synced 2025-10-30 07:50:37 +08:00 
			
		
		
		
	update 2025-08-12 02:29:38
This commit is contained in:
		| @ -7,7 +7,7 @@ | ||||
| include $(TOPDIR)/rules.mk | ||||
|  | ||||
| LUCI_TITLE:=Argon Theme | ||||
| LUCI_DEPENDS:=+curl +jsonfilter | ||||
| LUCI_DEPENDS:=+wget +jsonfilter | ||||
| PKG_VERSION:=2.4.3 | ||||
| PKG_RELEASE:=20250722 | ||||
|  | ||||
|  | ||||
| @ -27,7 +27,6 @@ | ||||
| 	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() | ||||
|  | ||||
| 	-- Fetch Local Background Media | ||||
| @ -74,9 +73,9 @@ | ||||
| 		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", "" | ||||
| 				local picurl = util.ubus("luci.argon_wallpaper", "get_url") or {} | ||||
| 				if (picurl.url and picurl.url ~= '') then | ||||
| 					return picurl.url, "Image", "" | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
|  | ||||
| @ -1,105 +0,0 @@ | ||||
| #!/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') | ||||
| # For now, the next two variables are used for wallhaven.cc with specified Tag ID | ||||
| # API_KEY if user has an account with wallhaven and want to use their apikey to allow for more images | ||||
| # EXACT_RESO is used for exact resolution by default, if not use 'atleast' instead of 'resolutions' | ||||
| API_KEY=$(uci -q get argon.@global[0].use_api_key) | ||||
| EXACT_RESO=$(uci -q get argon.@global[0].use_exact_resolution || echo '1') | ||||
| 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) | ||||
|         if [ -z "$API_KEY" ]; then | ||||
|             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#' | ||||
|         else | ||||
|             curl -fks --max-time 3 \ | ||||
|                 "https://api.unsplash.com/photos/random?client_id=${API_KEY}" | | ||||
|                 jsonfilter -qe '@["urls"]["regular"]' | ||||
|         fi | ||||
|         ;; | ||||
|     unsplash_*) | ||||
|         local collection_id=${WEB_PIC_SRC#unsplash_} | ||||
|         if [ -z "$API_KEY" ]; then | ||||
|             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#' | ||||
|         else | ||||
|             curl -fks --max-time 3 \ | ||||
|                 "https://api.unsplash.com/photos/random?client_id=${API_KEY}&collections=${collection_id}" | | ||||
|                 jsonfilter -qe '@["urls"]["regular"]' | ||||
|         fi | ||||
|         ;; | ||||
|     wallhaven) | ||||
|         curl -fks --max-time 3 \ | ||||
|             "https://wallhaven.cc/api/v1/search?resolutions=1920x1080&sorting=random" | | ||||
|             jsonfilter -qe '@.data[0].path' | ||||
|         ;; | ||||
|     wallhaven_*) | ||||
|         local tag_id=${WEB_PIC_SRC#wallhaven_} | ||||
|         local has_api_key="" | ||||
|         [ -n "$API_KEY" ] && has_api_key="apikey=$API_KEY&" || has_api_key="" | ||||
|         local use_reso="resolutions" | ||||
|         [ "$EXACT_RESO" -eq "1" ] && use_reso='resolutions' || use_reso='atleast' | ||||
|         curl -fks --max-time 3 \ | ||||
|             "https://wallhaven.cc/api/v1/search?${has_api_key}q=id%3A${tag_id}&${use_reso}=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 [[ "$WEB_PIC_SRC" == wallhave* ]] ; then | ||||
|             curl -fks --max-time 3 --url "${picurl}" > /dev/null | ||||
|         fi | ||||
|         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 | ||||
							
								
								
									
										129
									
								
								luci-theme-argon/root/usr/libexec/rpcd/luci.argon_wallpaper
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										129
									
								
								luci-theme-argon/root/usr/libexec/rpcd/luci.argon_wallpaper
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,129 @@ | ||||
| #!/bin/sh | ||||
| # author jjm2473 | ||||
|  | ||||
| . /lib/functions.sh | ||||
| . /usr/share/libubox/jshn.sh | ||||
|  | ||||
| # 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')" | ||||
|  | ||||
| # For now, the next two variables are used for wallhaven.cc with specified Tag ID | ||||
| # API_KEY if user has an account with wallhaven and want to use their apikey to allow for more images | ||||
| # EXACT_RESO is used for exact resolution by default, if not use 'atleast' instead of 'resolutions' | ||||
| API_KEY="$(uci -q get argon.@global[0].use_api_key)" | ||||
| EXACT_RESO="$(uci -q get argon.@global[0].use_exact_resolution || echo '1')" | ||||
|  | ||||
| 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="$(wget -T3 -qO- \ | ||||
| 			"https://www.bing.com/HPImageArchive.aspx?format=js&n=1" | | ||||
| 			jsonfilter -qe '@.images[0].url' | | ||||
| 			sed 's/1920x1080/UHD/g')" | ||||
| 		[ -n "${picpath}" ] && echo "//www.bing.com${picpath}" | ||||
| 		;; | ||||
| 	unsplash) | ||||
| 		if [ -z "$API_KEY" ]; then | ||||
| 			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" | ||||
| 		else | ||||
| 			wget -T3 -qO- "https://api.unsplash.com/photos/random?client_id=${API_KEY}" | | ||||
| 				jsonfilter -qe '@["urls"]["regular"]' | ||||
| 		fi | ||||
| 		;; | ||||
| 	unsplash_*) | ||||
| 		local collection_id="${WEB_PIC_SRC#unsplash_}" | ||||
| 		if [ -z "$API_KEY" ]; then | ||||
| 			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" | ||||
| 		else | ||||
| 			wget -T3 -qO- \ | ||||
| 				"https://api.unsplash.com/photos/random?client_id=${API_KEY}&collections=${collection_id}" | | ||||
| 				jsonfilter -qe '@["urls"]["regular"]' | ||||
| 		fi | ||||
| 		;; | ||||
| 	wallhaven) | ||||
| 		wget -T3 -qO- \ | ||||
| 			"https://wallhaven.cc/api/v1/search?resolutions=1920x1080&sorting=random" | | ||||
| 			jsonfilter -qe "@.data[0].path" | ||||
| 		;; | ||||
| 	wallhaven_*) | ||||
| 		local tag_id="${WEB_PIC_SRC#wallhaven_}" | ||||
| 		local use_reso="resolutions" | ||||
| 		[ "$EXACT_RESO" -eq "1" ] || use_reso="atleast" | ||||
| 		[ -z "$API_KEY" ] || API_KEY="apikey=$API_KEY&" | ||||
| 		wget -T3 -qO- \ | ||||
| 			"https://wallhaven.cc/api/v1/search?${API_KEY}q=id%3A${tag_id}&${use_reso}=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 | ||||
| } | ||||
|  | ||||
| case "$1" in | ||||
| "list") | ||||
| 	json_init | ||||
| 	json_add_object "get_url" | ||||
| 	json_close_object | ||||
| 	json_dump | ||||
| 	json_cleanup | ||||
| 	;; | ||||
| "call") | ||||
| 	case "$2" in | ||||
| 	"get_url") | ||||
| 		read -r input | ||||
| 		if [ -f "$CACHE" ]; then | ||||
| 			idle_t="$(($(date '+%s') - $(date -r "$CACHE" '+%s' 2>/dev/null || echo '0')))" | ||||
| 			if [ -s "$CACHE" ]; then | ||||
| 				if [ "$idle_t" -le "43200" ]; then | ||||
| 					json_init | ||||
| 					json_add_string "url" "$(cat "$CACHE")" | ||||
| 					json_dump | ||||
| 					json_cleanup | ||||
| 					return 0 | ||||
| 				fi | ||||
| 			else | ||||
| 				if [ "$idle_t" -le 120 ]; then | ||||
| 					echo '{ "url": "" }' | ||||
| 					return 1 | ||||
| 				fi | ||||
| 			fi | ||||
| 		fi | ||||
|  | ||||
| 		json_init | ||||
| 		json_add_string "url" "$(try_update)" | ||||
| 		json_dump | ||||
| 		json_cleanup | ||||
| 		return 0 | ||||
| 		;; | ||||
| 	esac | ||||
| 	;; | ||||
| esac | ||||
		Reference in New Issue
	
	Block a user
	 actions-user
					actions-user