From 29f87f75c19ba58b20ff6ca1d645d2fa1ad38c73 Mon Sep 17 00:00:00 2001
From: tiny-craft <137850705+tiny-craft@users.noreply.github.com>
Date: Thu, 13 Jul 2023 15:46:12 +0800
Subject: [PATCH] feat: support custom theme color and dark mode perf: replace
css variables to theme variables
---
frontend/src/App.vue | 68 +++++++++-
frontend/src/AppContent.vue | 120 ++++++++----------
frontend/src/components/content/content.scss | 2 +-
.../content_value/ContentValueString.vue | 4 +-
.../components/dialogs/PreferencesDialog.vue | 7 +
.../src/components/sidebar/BrowserPane.vue | 30 ++---
.../src/components/sidebar/ConnectionPane.vue | 13 +-
.../src/components/sidebar/ConnectionTree.vue | 4 +-
frontend/src/components/sidebar/NavMenu.vue | 6 +-
frontend/src/langs/en.json | 4 +
frontend/src/langs/zh-cn.json | 4 +
frontend/src/stores/preferences.js | 33 ++++-
frontend/src/style.scss | 18 ++-
13 files changed, 193 insertions(+), 120 deletions(-)
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 4b45ee6..78d00f9 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -11,18 +11,30 @@ import AddFieldsDialog from './components/dialogs/AddFieldsDialog.vue'
import AppContent from './AppContent.vue'
import GroupDialog from './components/dialogs/GroupDialog.vue'
import DeleteKeyDialog from './components/dialogs/DeleteKeyDialog.vue'
+import { computed, onBeforeMount, ref } from 'vue'
+import { get } from 'lodash'
+import usePreferencesStore from './stores/preferences.js'
+import useConnectionStore from './stores/connections.js'
+import { useI18n } from 'vue-i18n'
+import { darkTheme, lightTheme, useOsTheme } from 'naive-ui'
hljs.registerLanguage('json', json)
hljs.registerLanguage('plaintext', plaintext)
+/**
+ *
+ * @type import('naive-ui').GlobalThemeOverrides
+ */
const themeOverrides = {
common: {
- // primaryColor: '#409EFF',
+ primaryColor: '#D33A31',
+ primaryColorHover: '#FF6B6B',
+ primaryColorPressed: '#D5271C',
+ primaryColorSuppl: '#FF6B6B',
borderRadius: '4px',
borderRadiusSmall: '3px',
- fontFamily: `"Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
- "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue"`,
lineHeight: 1.5,
+ scrollbarWidth: '8px',
},
Tag: {
// borderRadius: '3px'
@@ -33,13 +45,52 @@ const themeOverrides = {
tabGapLargeCard: '1px',
},
}
+
+const prefStore = usePreferencesStore()
+const connectionStore = useConnectionStore()
+const i18n = useI18n()
+const initializing = ref(false)
+onBeforeMount(async () => {
+ try {
+ initializing.value = true
+ await prefStore.loadPreferences()
+ i18n.locale.value = get(prefStore.general, 'language', 'en')
+ await prefStore.loadFontList()
+ await connectionStore.initConnections()
+ } finally {
+ initializing.value = false
+ }
+})
+
+const osTheme = useOsTheme()
+const theme = computed(() => {
+ if (prefStore.general.theme === 'auto') {
+ if (osTheme.value === 'dark') {
+ return darkTheme
+ }
+ } else if (prefStore.general.theme === 'dark') {
+ return darkTheme
+ }
+ return lightTheme
+})
-
+
+
-
+
+ {{ $t('launching') }}
+
+
+
@@ -55,4 +106,9 @@ const themeOverrides = {
-
+
diff --git a/frontend/src/AppContent.vue b/frontend/src/AppContent.vue
index 82eb95c..1e704aa 100644
--- a/frontend/src/AppContent.vue
+++ b/frontend/src/AppContent.vue
@@ -1,8 +1,7 @@