From cd73c3a7cb062e59bfee60f421be8a3a508bf286 Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 27 Mar 2023 15:01:35 +0800 Subject: [PATCH 1/8] fix: taskbar color follow(#54) --- app/components/home.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/components/home.tsx b/app/components/home.tsx index 1c665f87..fd38ee8c 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -358,12 +358,20 @@ function useSwitchTheme() { const config = useChatStore((state) => state.config); useEffect(() => { + const metaDescription = document.querySelector('meta[name="theme-color"]'); + document.body.classList.remove("light"); document.body.classList.remove("dark"); if (config.theme === "dark") { document.body.classList.add("dark"); + if (metaDescription){ + metaDescription.setAttribute('content', "#151515"); + } } else if (config.theme === "light") { document.body.classList.add("light"); + if (metaDescription){ + metaDescription.setAttribute('content', "#fafafa"); + } } }, [config.theme]); } From 6446692db04b612ab243d19c88c09c3cbee52c29 Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 27 Mar 2023 15:02:12 +0800 Subject: [PATCH 2/8] feat: support safari appleWebApp --- app/layout.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/layout.tsx b/app/layout.tsx index 095d3a18..eea0c9a6 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -13,6 +13,11 @@ const COMMIT_ID = process export const metadata = { title: "ChatGPT Next Web", description: "Your personal ChatGPT Chat Bot.", + appleWebApp: { + title: "ChatGPT Next Web", + statusBarStyle: "black-translucent", + }, + themeColor: "#fafafa" }; function Meta() { From 785372ad73b6691717fb699125bd62fbdc5f078b Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 27 Mar 2023 15:47:46 +0800 Subject: [PATCH 3/8] fix: fix the different colors on mobile --- app/components/home.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index fd38ee8c..bcb71984 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -356,6 +356,7 @@ export function Chat(props: { showSideBar?: () => void }) { function useSwitchTheme() { const config = useChatStore((state) => state.config); + const screenWidth = window.innerWidth; useEffect(() => { const metaDescription = document.querySelector('meta[name="theme-color"]'); @@ -364,16 +365,24 @@ function useSwitchTheme() { document.body.classList.remove("dark"); if (config.theme === "dark") { document.body.classList.add("dark"); - if (metaDescription){ - metaDescription.setAttribute('content', "#151515"); + if (metaDescription) { + if (screenWidth < 600) { + metaDescription.setAttribute('content', "#1a262a"); + } else { + metaDescription.setAttribute('content', "#151515"); + } } } else if (config.theme === "light") { document.body.classList.add("light"); - if (metaDescription){ - metaDescription.setAttribute('content', "#fafafa"); + if (metaDescription) { + if (screenWidth < 600) { + metaDescription.setAttribute('content', "#e7f8ff"); + } else { + metaDescription.setAttribute('content', "#fafafa"); + } } } - }, [config.theme]); + }, [config.theme,screenWidth]); } function exportMessages(messages: Message[], topic: string) { From dd80c4563ddc4b40232fb823405ddd1f31c8f4de Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 27 Mar 2023 17:04:11 +0800 Subject: [PATCH 4/8] feat: adding iOS Webapp support - fix media query about background-color - Use colors from CSS files instead of fixed values --- app/components/home.tsx | 24 ++++++------------------ app/styles/globals.scss | 9 ++++++++- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index bcb71984..a2ef17b7 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -356,33 +356,21 @@ export function Chat(props: { showSideBar?: () => void }) { function useSwitchTheme() { const config = useChatStore((state) => state.config); - const screenWidth = window.innerWidth; useEffect(() => { - const metaDescription = document.querySelector('meta[name="theme-color"]'); - document.body.classList.remove("light"); document.body.classList.remove("dark"); + if (config.theme === "dark") { document.body.classList.add("dark"); - if (metaDescription) { - if (screenWidth < 600) { - metaDescription.setAttribute('content', "#1a262a"); - } else { - metaDescription.setAttribute('content', "#151515"); - } - } } else if (config.theme === "light") { document.body.classList.add("light"); - if (metaDescription) { - if (screenWidth < 600) { - metaDescription.setAttribute('content', "#e7f8ff"); - } else { - metaDescription.setAttribute('content', "#fafafa"); - } - } } - }, [config.theme,screenWidth]); + + const themeColor = getComputedStyle(document.body).getPropertyValue("--theme-color").trim(); + const metaDescription = document.querySelector('meta[name="theme-color"]'); + metaDescription?.setAttribute('content', themeColor); + }, [config.theme]); } function exportMessages(messages: Message[], topic: string) { diff --git a/app/styles/globals.scss b/app/styles/globals.scss index e7d35226..96b6a501 100644 --- a/app/styles/globals.scss +++ b/app/styles/globals.scss @@ -7,6 +7,7 @@ --second: rgb(231, 248, 255); --hover-color: #f3f3f3; --bar-color: rgba(0, 0, 0, 0.1); + --theme-color: var(--gray); /* shadow */ --shadow: 50px 50px 100px 10px rgb(0, 0, 0, 0.1); @@ -28,6 +29,8 @@ --bar-color: rgba(255, 255, 255, 0.1); --border-in-light: 1px solid rgba(255, 255, 255, 0.192); + + --theme-color: var(--gray); } .light { @@ -84,7 +87,11 @@ body { align-items: center; user-select: none; font-family: "Noto Sans SC", "SF Pro SC", "SF Pro Text", "SF Pro Icons", - "PingFang SC", "Helvetica Neue", "Helvetica", "Arial", sans-serif; + "PingFang SC", "Helvetica Neue", "Helvetica", "Arial", sans-serif; + + @media only screen and (max-width: 600px) { + background-color: var(--second); + } } ::-webkit-scrollbar { From bdf17fafff02733c76b8977b2c19bb87db0864d1 Mon Sep 17 00:00:00 2001 From: "jianjian.ma" Date: Mon, 27 Mar 2023 17:41:44 +0800 Subject: [PATCH 5/8] feat: add PWA support --- app/layout.tsx | 1 + public/serviceWorker.js | 35 +++++++++++++++++++++++++++++++++++ public/site.webmanifest | 22 +++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 public/serviceWorker.js diff --git a/app/layout.tsx b/app/layout.tsx index 095d3a18..3a6315f7 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -50,6 +50,7 @@ export default function RootLayout({ href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap" rel="stylesheet" > + {children} diff --git a/public/serviceWorker.js b/public/serviceWorker.js new file mode 100644 index 00000000..dff7af9a --- /dev/null +++ b/public/serviceWorker.js @@ -0,0 +1,35 @@ +const CHATGPT_NEXT_WEB_CACHE = "chatgpt-next-web-cache"; + +self.addEventListener('activate', function (event) { + console.log('ServiceWorker activated.'); +}); + +self.addEventListener('install', function (event) { + event.waitUntil( + caches.open(CHATGPT_NEXT_WEB_CACHE) + .then(function (cache) { + return cache.addAll([ + '/', + ]); + }) + ); +}); + +self.addEventListener('fetch', function (event) { + event.respondWith( + caches.match(event.request) + .then(function (response) { + return response || fetch(event.request); + }) + ); +}); + +if ('serviceWorker' in navigator) { + window.addEventListener('load', function () { + navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) { + console.log('ServiceWorker registration successful with scope: ', registration.scope); + }, function (err) { + console.error('ServiceWorker registration failed: ', err); + }); + }); +} \ No newline at end of file diff --git a/public/site.webmanifest b/public/site.webmanifest index 45dc8a20..117f33b8 100644 --- a/public/site.webmanifest +++ b/public/site.webmanifest @@ -1 +1,21 @@ -{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file +{ + "name": "ChatGPT Next Web", + "short_name": "ChatGPT", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "start_url": "/", + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" + } + \ No newline at end of file From a81e7394f0668316b9e20a964f761b7804d1f831 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 27 Mar 2023 17:45:36 +0800 Subject: [PATCH 6/8] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f20debd0..0c7284bd 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,9 @@ If you would like to contribute your API key, you can email it to the author and [@mushan0x0](https://github.com/mushan0x0) [@ClarenceDan](https://github.com/ClarenceDan) +### 贡献者 Contributor +[@AprilNEA](https://github.com/AprilNEA) + ## LICENSE - [Anti 996 License](https://github.com/kattgu7/Anti-996-License/blob/master/LICENSE_CN_EN) From 689b7bab2692a9fe0271d1392819ba9b7ff59239 Mon Sep 17 00:00:00 2001 From: "jianjian.ma" Date: Mon, 27 Mar 2023 17:53:32 +0800 Subject: [PATCH 7/8] feat: add PWA support --- .eslintignore | 1 + app/layout.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..08975255 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +public/serviceWorker.js \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index 3a6315f7..f42e1044 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -50,7 +50,7 @@ export default function RootLayout({ href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap" rel="stylesheet" > - + {children} From 5593c067c4a576f35ff11e40c2c0e98352a74db5 Mon Sep 17 00:00:00 2001 From: "jianjian.ma" Date: Mon, 27 Mar 2023 18:02:35 +0800 Subject: [PATCH 8/8] feat: add PWA support --- app/layout.tsx | 2 +- public/serviceWorker.js | 13 +------------ public/serviceWorkerRegister.js | 9 +++++++++ 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 public/serviceWorkerRegister.js diff --git a/app/layout.tsx b/app/layout.tsx index f42e1044..e4df377c 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -50,7 +50,7 @@ export default function RootLayout({ href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap" rel="stylesheet" > - + {children} diff --git a/public/serviceWorker.js b/public/serviceWorker.js index dff7af9a..585633fc 100644 --- a/public/serviceWorker.js +++ b/public/serviceWorker.js @@ -9,7 +9,6 @@ self.addEventListener('install', function (event) { caches.open(CHATGPT_NEXT_WEB_CACHE) .then(function (cache) { return cache.addAll([ - '/', ]); }) ); @@ -22,14 +21,4 @@ self.addEventListener('fetch', function (event) { return response || fetch(event.request); }) ); -}); - -if ('serviceWorker' in navigator) { - window.addEventListener('load', function () { - navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) { - console.log('ServiceWorker registration successful with scope: ', registration.scope); - }, function (err) { - console.error('ServiceWorker registration failed: ', err); - }); - }); -} \ No newline at end of file +}); \ No newline at end of file diff --git a/public/serviceWorkerRegister.js b/public/serviceWorkerRegister.js new file mode 100644 index 00000000..8405f21a --- /dev/null +++ b/public/serviceWorkerRegister.js @@ -0,0 +1,9 @@ +if ('serviceWorker' in navigator) { + window.addEventListener('load', function () { + navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) { + console.log('ServiceWorker registration successful with scope: ', registration.scope); + }, function (err) { + console.error('ServiceWorker registration failed: ', err); + }); + }); +} \ No newline at end of file