package/luci-app-ota: jump to download progress on task running on checking update

show steps on UI
This commit is contained in:
jjm2473 2023-02-02 15:49:11 +08:00
parent cfd3dd4af6
commit 8f60ffa09c
7 changed files with 55 additions and 17 deletions

View File

@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI for OTA upgrade
LUCI_PKGARCH:=all
PKG_VERSION:=1.2.2
PKG_VERSION:=1.2.3
PKG_RELEASE:=1
PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com>

View File

@ -83,11 +83,8 @@ function action_check()
code = 500,
msg = "Unknown"
}
if r == 0 then
ret.code = 0
ret.msg = o
elseif r == 1 then
ret.code = 1
if r == 0 or r == 1 or r == 2 then
ret.code = r
ret.msg = o
else
ret.code = 500
@ -123,7 +120,7 @@ function action_progress()
if r == 0 then
ret.code = 0
ret.msg = "done"
elseif r == 1 or r == 2 then
elseif r == 1 or r == 2 or r == 254 then
ret.code = r
ret.msg = o
else

View File

@ -41,6 +41,7 @@
<label class="cbi-value-title" id="check_result"></label>
<div class="cbi-value-field">
<input class="cbi-button cbi-button-reload" type="button" name="check" value="<%:Check update%>" />
<div class="cbi-value-description">Step 1/3: <%:Check update%></div>
</div>
</div>
</form>
@ -51,6 +52,7 @@
<label class="cbi-value-title" id="download_result"><%:Found new firmware%></label>
<div class="cbi-value-field">
<input class="cbi-button cbi-button-apply" type="button" name="download" value="<%:Download firmware%>" />
<div class="cbi-value-description">Step 2/3: <%:Download firmware%></div>
</div>
</div>
</form>
@ -61,6 +63,7 @@
<label class="cbi-value-title" id="download_progress">0%</label>
<div class="cbi-value-field">
<input class="cbi-button cbi-button-reset" type="button" name="cancel" value="<%:Cancel download%>" />
<div class="cbi-value-description">Step 2/3: <%:Download firmware%></div>
</div>
</div>
</form>
@ -74,6 +77,7 @@
<label class="cbi-value-title"><%:Firmware downloaded%></label>
<div class="cbi-value-field">
<input type="submit" class="cbi-button cbi-input-apply" value="<%:Flash image...%>" />
<div class="cbi-value-description">Step 3/3: <%:Flash image...%></div>
</div>
</div>
</form>
@ -90,7 +94,8 @@
<div class="cbi-value cbi-value-last">
<label class="cbi-value-title"><%:Firmware downloaded%></label>
<div class="cbi-value-field">
<input type="submit" class="cbi-button cbi-input-apply" value="<%:Flash image...%>" />
<input type="submit" class="cbi-button cbi-input-apply" value="<%:Flash image%>" />
<div class="cbi-value-description">Step 3/3: <%:Flash image%></div>
</div>
</div>
</form>
@ -141,9 +146,18 @@
check.disabled = undefined;
switch(d.code){
case 0:
case 2:
check_result.innerText = "";
upgrade_log.innerHTML = d.msg;
state_switch("unchecked", "checked");
if (d.code == 0) {
state_switch("unchecked", "checked");
} else {
alert("<%:Found downloading firmware, will show progress%>");
download_progress.innerText = "<%:Downloading%>: ...";
cancel.disabled = 'disabled';
state_switch("unchecked", "downloading");
refresh_download_progress_timer = setTimeout(refresh_download_progress, 500);
}
break;
case 1:
check_result.innerText = "<%:Already the latest firmware%>";
@ -185,6 +199,9 @@
download_result.innerText = "<%:Download canceled%>";
state_switch("downloading", "checked");
break;
case 254:
state_switch("downloading", "unchecked");
break;
default:
download_result.innerText = "<%:Download failed%>";
state_switch("downloading", "checked");

View File

@ -25,6 +25,9 @@ msgstr ""
msgid "Flash image..."
msgstr ""
msgid "Flash image"
msgstr ""
msgid "Checking..."
msgstr ""
@ -54,3 +57,6 @@ msgstr ""
msgid "History Log"
msgstr ""
msgid "Found downloading firmware, will show progress"
msgstr ""

View File

@ -25,6 +25,9 @@ msgstr ""
msgid "Flash image..."
msgstr ""
msgid "Flash image"
msgstr ""
msgid "Checking..."
msgstr ""
@ -54,3 +57,6 @@ msgstr ""
msgid "History Log"
msgstr ""
msgid "Found downloading firmware, will show progress"
msgstr ""

View File

@ -25,6 +25,9 @@ msgstr "固件已下载"
msgid "Flash image..."
msgstr "刷写固件..."
msgid "Flash image"
msgstr "刷写固件"
msgid "Checking..."
msgstr "检查中..."
@ -54,3 +57,6 @@ msgstr "镜像文件格式不支持或损坏。也许稍候再试试"
msgid "History Log"
msgstr "历史更新日志"
msgid "Found downloading firmware, will show progress"
msgstr "发现下载中的固件,将显示当前进度"

View File

@ -94,24 +94,30 @@ prepare_check() {
return $latest
}
# 0: found newer fw, 1: already newest fw, *: err
# 0: found newer fw, 1: already newest fw, 2: found running task, *: err
do_check() {
local ret=0
local lock="$WRLOCK"
exec 200>$lock
flock -n 200 || return 255
prepare_check
ret=$?
flock -u 200 >/dev/null 2>&1
if flock -n 200; then
prepare_check
ret=$?
flock -u 200 >/dev/null 2>&1
elif [ -f /tmp/firmware.img.progress -o -f /tmp/firmware.img.sha256sum ]; then
ret=2
else
echo "lock failed!" >&2
return 255
fi
if [ "$ret" -eq 0 ]; then
if [ "$ret" -eq 0 -o "$ret" -eq 2 ]; then
# output
echo "<pre>"
sed -E 's/.*\((.+)\).*/\1/' /var/run/ota/ota.latest
echo "</pre>"
echo "<br><h2>ChangeLog:</h2>"
fi
[ "$ret" -eq 0 -o "$ret" -eq 1 ] && cat /var/run/ota/ota.log
[ "$ret" -eq 0 -o "$ret" -eq 1 -o "$ret" -eq 2 ] && cat /var/run/ota/ota.log
return $ret
}
@ -124,7 +130,7 @@ do_download(){
return 0
}
# 0: done, 1: downloading, 2: failed, *: err
# 0: done, 1: downloading, 2: failed, 254: wrong state, *: err
do_progress() {
local sum=`grep 'SHA256: ' /var/run/ota/ota.latest | cut -d' ' -f2`
[ -z "$sum" ] && { echo "do check first" >&2 ; return 254; }