ChatALL icon indicating copy to clipboard operation
ChatALL copied to clipboard

Add theme setting

Open tanchekwei opened this issue 2 years ago • 2 comments
trafficstars

Add theme setting to setting page.

Allow user to choose between System, Light, and Dark mode.

No impact for Light theme as using current color scheme.

By default, use system theme when user first time launches the app.

If System mode, update theme when system theme changed.

Fix white screen on startup by delaying showing window only after URL is loaded.

image

tanchekwei avatar Jun 20 '23 23:06 tanchekwei

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chatall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2023 2:27pm

vercel[bot] avatar Jun 20 '23 23:06 vercel[bot]

Change to draft, as found low contrast issue to be fixed

image

tanchekwei avatar Jun 21 '23 01:06 tanchekwei

This is amazing! Can't wait for a merging!

There is a suggest that ChatMessage.vue always:

import "github-markdown-css/github-markdown-light.css";

But there is also a *-dark.css can be used.

Moreover, the following information may be helpful to you.

I imported github-markdown.css at first and found that the code style can changed lively when the system theme changed. So I enforce it to *-light.css (Yes, it is an ugly). I didn't dig deep to know why the css can know the system theme changing. But it is a good experience. FYI.

Thank you very much again!

sunner avatar Jun 21 '23 02:06 sunner

This is amazing! Can't wait for a merging!

There is a suggest that ChatMessage.vue always:

import "github-markdown-css/github-markdown-light.css";

But there is also a *-dark.css can be used.

Moreover, the following information may be helpful to you.

I imported github-markdown.css at first and found that the code style can changed lively when the system theme changed. So I enforce it to *-light.css (Yes, it is an ugly). I didn't dig deep to know why the css can know the system theme changing. But it is a good experience. FYI.

Thank you very much again!

Thanks for the info.

I have successfully loaded github-markdown-light.css or dark.css depending on the data-theme set on the body tag using SCSS.

However, I am facing a roadblock when trying to dynamically load highlight.js/styles/github.css or github-dark.css used to highlight code block. When switching between themes, at best, it reloads once, but then the code block theme gets stuck unless the page is reloaded. I have tried combining it with the markdown style depending on the data-theme, but it doesn't work.

import hightlight js

I attempted to delete the existing CSS before reloading, but I encountered a "module not found" error, and I'm not sure why.

const themeModule = require.resolve('../node_modules/highlight.js/styles/github-dark.css');
delete require.cache[themeModule];
const newModule = require.resolve('../node_modules/highlight.js/styles/github.css');
import(newModule);

I also tried doing this in the main process, but it didn't work, no style show up in the document.

cssId = mainWindow.webContents.insertCSS(`@import url('${cssPath}');
window.webContents.removeInsertedCSS(cssId);

Then I tried looping through the <style> tags in the document and removing the existing highlight styles before adding the new ones. However, this method not working if building in release version.

Feel free to give suggestions, or do you think this issue is acceptable since we don't change the theme very frequently?

tanchekwei avatar Jun 21 '23 15:06 tanchekwei

I think I will spend 1 more day on the issue, see if I can find any solution for that.

tanchekwei avatar Jun 21 '23 23:06 tanchekwei

I think your work is good enough to present to users. Some little pities can be resolved as things going. What do you think?

sunner avatar Jun 22 '23 01:06 sunner

I think your work is good enough to present to users. Some little pities can be resolved as things going. What do you think?

Okay, I got it. A good night's sleep helps. Kindly review and let me know if there is anything I can do.

tanchekwei avatar Jun 22 '23 03:06 tanchekwei

Done @sunner.

tanchekwei avatar Jun 22 '23 13:06 tanchekwei

Thank you very much! The PR will be included in next release!

sunner avatar Jun 22 '23 14:06 sunner