Skip to content

Commit

Permalink
🎨 设置网页依赖本地化
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed Aug 15, 2024
1 parent a861e09 commit a4322c2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/top/yogiczy/mytv/ui/utils/HttpServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ object HttpServer : Loggable() {
server.listen(AsyncServer.getDefault(), SERVER_PORT)

server.get("/") { _, response ->
handleHomePage(response, context)
handleRawResource(response, context, "text/html", R.raw.index)
}
server.get("/index_css.css") { _, response ->
handleRawResource(response, context, "text/css", R.raw.index_css)
}
server.get("/index_js.js") { _, response ->
handleRawResource(response, context, "text/javascript", R.raw.index_js)
}

server.get("/api/settings") { _, response ->
Expand Down Expand Up @@ -83,10 +89,15 @@ object HttpServer : Loggable() {
)
}

private fun handleHomePage(response: AsyncHttpServerResponse, context: Context) {
private fun handleRawResource(
response: AsyncHttpServerResponse,
context: Context,
contentType: String,
id: Int,
) {
wrapResponse(response).apply {
setContentType("text/html; charset=utf-8")
send(context.resources.openRawResource(R.raw.index).readBytes().decodeToString())
setContentType(contentType)
send(context.resources.openRawResource(id).readBytes().decodeToString())
}
}

Expand Down
17 changes: 2 additions & 15 deletions app/src/main/res/raw/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,8 @@
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>我的电视</title>
<!-- 重置css -->
<link href="https://jsd.cdn.zzko.cn/npm/@unocss/reset/tailwind.min.css" rel="stylesheet">

<!-- 核心 -->
<script src="https://jsd.cdn.zzko.cn/npm/[email protected]/dist/vue.global.prod.js"></script>
<script src="https://jsd.cdn.zzko.cn/npm/@unocss/runtime"></script>

<!-- 日期格式化 -->
<script src="https://jsd.cdn.zzko.cn/npm/dayjs@1/dayjs.min.js"></script>
<script src="https://jsd.cdn.zzko.cn/npm/dayjs@1/locale/zh-cn.js"></script>
<script src="https://jsd.cdn.zzko.cn/npm/dayjs@1/plugin/relativeTime.js"></script>

<!-- vant -->
<link href="https://jsd.cdn.zzko.cn/npm/vant@4/lib/index.css" rel="stylesheet" />
<script src="https://jsd.cdn.zzko.cn/npm/vant@4/lib/vant.min.js"></script>
<link href="./index_css.css" rel="stylesheet" />
<script src="./index_js.js"></script>

<style>
.van-theme-dark body {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/raw/index_css.css

Large diffs are not rendered by default.

Loading

0 comments on commit a4322c2

Please sign in to comment.