Keldos MZhaovo commited on
Commit
1e4e3c0
·
1 Parent(s): b6dd0c8

基本PWA功能 & 修改图标

Browse files

😘 icon by @MZhao-ouo

Co-authored-by: mzlegion <[email protected]>

modules/webui.py CHANGED
@@ -56,11 +56,24 @@ def reload_javascript():
56
  js += '<script async type="module" src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>'
57
  js += '<script async type="module" src="http://spin.js.org/spin.umd.js"></script><link type="text/css" href="https://spin.js.org/spin.css" rel="stylesheet" />'
58
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  css = css_html()
60
 
61
  def template_response(*args, **kwargs):
62
  res = GradioTemplateResponseOriginal(*args, **kwargs)
63
- res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
 
64
  res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
65
  res.init_headers()
66
  return res
 
56
  js += '<script async type="module" src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>'
57
  js += '<script async type="module" src="http://spin.js.org/spin.umd.js"></script><link type="text/css" href="https://spin.js.org/spin.css" rel="stylesheet" />'
58
 
59
+ meta = """
60
+ <meta name="apple-mobile-web-app-title" content="川虎 Chat">
61
+ <meta name="apple-mobile-web-app-capable" content="yes">
62
+ <meta name="application-name" content="川虎 Chat">
63
+ <meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover'>
64
+ <meta name="theme-color" content="#ffffff">
65
+
66
+ <link rel="apple-touch-icon-precomposed" href="/file=web_assets/icon/mask-icon-512.png" >
67
+ <link rel="apple-touch-icon" href="/file=web_assets/icon/mask-icon-512.png" >
68
+
69
+ <link rel="manifest" href="/file=web_assets/manifest.json" crossorigin="use-credentials">
70
+ """
71
  css = css_html()
72
 
73
  def template_response(*args, **kwargs):
74
  res = GradioTemplateResponseOriginal(*args, **kwargs)
75
+ res.body = res.body.replace(b'</head>', f'{meta}{js}</head>'.encode("utf8"))
76
+ # res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
77
  res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
78
  res.init_headers()
79
  return res
web_assets/icon/any-icon-512.png ADDED
web_assets/icon/mask-icon-512.png ADDED
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -222,9 +222,11 @@ function checkModel() {
222
  function toggleDarkMode(isEnabled) {
223
  if (isEnabled) {
224
  document.body.classList.add("dark");
 
225
  document.body.style.setProperty("background-color", "var(--neutral-950)", "important");
226
  } else {
227
  document.body.classList.remove("dark");
 
228
  document.body.style.backgroundColor = "";
229
  }
230
  }
 
222
  function toggleDarkMode(isEnabled) {
223
  if (isEnabled) {
224
  document.body.classList.add("dark");
225
+ document.querySelector('meta[name="theme-color"]').setAttribute('content', '#171717');
226
  document.body.style.setProperty("background-color", "var(--neutral-950)", "important");
227
  } else {
228
  document.body.classList.remove("dark");
229
+ document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff');
230
  document.body.style.backgroundColor = "";
231
  }
232
  }
web_assets/manifest.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "川虎Chat",
3
+ "short_name": "川虎Chat",
4
+ "description": "川虎Chat - 为ChatGPT等多种LLM提供了一个轻快好用的Web图形界面和众多附加功能 \nChuanhu Chat - Lightweight and User-friendly Web-UI for LLMs including ChatGPT/ChatGLM/LLaMA ",
5
+ "display": "standalone",
6
+ "scope": "/",
7
+ "start_url": "/",
8
+ "icons": [
9
+ {
10
+ "src": "/file=web_assets/icon/any-icon-512.png",
11
+ "type": "image/png",
12
+ "sizes": "512x512",
13
+ "purpose": "any"
14
+ },
15
+ {
16
+ "src": "/file=web_assets/icon/mask-icon-512.png",
17
+ "type": "image/png",
18
+ "sizes": "512x512",
19
+ "purpose": "maskable"
20
+ }
21
+ ]
22
+ }