1
0
mirror of https://github.com/hanxi/xiaomusic.git synced 2026-04-27 22:49:58 +08:00

feat: 一键更新功能

This commit is contained in:
涵曦
2024-12-18 22:51:53 +08:00
parent b0dfb37d98
commit df6b71b47a
3 changed files with 82 additions and 3 deletions

View File

@@ -26,8 +26,7 @@
<body class="index_page">
<div class="player">
<h1>小爱音箱播放器
<a id="version" href="https://xdocs.hanxi.cc/issues/changelog.html" target="_blank">版本
1.0.0</a><span id="versionnew" class="new-badge"></span>
<a id="version" href="javascript:void(0);">1.0.0</a><span id="versionnew" class="new-badge"></span>
</h1>
<label for="did">选择播放设备:</label>
@@ -191,7 +190,32 @@
<button onclick="nowarning()">继续并不再显示</button>
<button onclick="toggleWarning()">取消</button>
</div>
</div>
</div>
<!-- 更新组件 -->
<div class="component" id="update-component" style="display: none;">
<h2>更新</h2>
<label for="update-version" style="display: flex;align-items: center;">选择版本:
<a class="option-inline changelog-button" href="https://xdocs.hanxi.cc/issues/changelog.html" target="_blank">
<span class="material-icons">list_alt</span>
<span>版本日志</span>
</a>
</label>
<select id="update-version" class="version-selector">
<option value="main" selected>测试版</option>
</select>
<label for="lite">选择类型:</label>
<select id="lite" class="version-selector">
<option value="true" selected>轻量(不更新ffmpeg)</option>
<option value="false">完整(更新ffmpeg)</option>
</select>
<div class="component-button-group">
<button onclick="doUpdates()">更新</button>
<button onclick="toggleUpdate()">关闭</button>
</div>
</div>
<div class="footer">
Powered by XiaoMusic
</div>

View File

@@ -313,6 +313,7 @@ textarea {
.playlist-selector,
.device-selector,
.version-selector,
.song-selector {
width: 300px;
}
@@ -342,3 +343,11 @@ span,p {
cursor: pointer;
user-select: none;
}
.changelog-button {
padding: 0px 0px;
margin: 0px;
font-size: 14px;
margin-left: auto;
text-decoration: none;
}

View File

@@ -650,3 +650,49 @@ function timedShutDown(cmd) {
$(".timer-tooltip").fadeOut();
}, 3000);
}
// 绑定点击事件,显示弹窗
$('#version').on('click', function() {
$.get("https://xdocs.hanxi.cc/versions.json", function (data, status) {
console.log(data);
const versionSelect = document.getElementById("update-version");
versionSelect.innerHTML = "";
data.forEach((item) => {
const option = document.createElement("option");
option.value = item.version;
if (item.version=="main"){
option.textContent = "测试版";
} else {
option.textContent = item.version;
}
versionSelect.appendChild(option);
});
});
$('#update-component').show();
});
// 关闭更新弹窗
function toggleUpdate() {
$('#update-component').hide();
}
function doUpdates() {
const version = $("#update-version").val();
let lite = $("#lite").val();
$.ajax({
type: "POST",
url: `/updateversion?version=${version}&lite=${lite}`,
contentType: "application/json; charset=utf-8",
success: (data) => {
if (data.ret == "OK") {
alert(`更新成功,请刷新页面`);
location.reload();
} else {
alert(`更新失败: ${data.ret}`);
}
},
error: () => {
alert(`更新失败`);
},
});
}