소스 검색

feat: support css injection

GyDi 3 년 전
부모
커밋
0290d9ddfc
4개의 변경된 파일20개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 1
      src-tauri/src/core/verge.rs
  2. 14 1
      src/components/layout/use-custom-theme.ts
  3. 4 3
      src/components/setting/setting-theme.tsx
  4. 1 1
      src/services/types.ts

+ 1 - 1
src-tauri/src/core/verge.rs

@@ -63,7 +63,7 @@ pub struct VergeTheme {
   pub success_color: Option<String>,
 
   pub font_family: Option<String>,
-  pub font_face: Option<String>,
+  pub css_injection: Option<String>,
 }
 
 impl VergeConfig {

+ 14 - 1
src/components/layout/use-custom-theme.ts

@@ -40,12 +40,25 @@ export default function useCustomTheme() {
         },
       },
       typography: {
+        // todo
         fontFamily: setting.font_family
-          ? `"${setting.font_family}", ${dt.font_family}`
+          ? `${setting.font_family}, ${dt.font_family}`
           : dt.font_family,
       },
     });
 
+    // inject css
+    let style = document.querySelector("style#verge-theme");
+    if (!style) {
+      style = document.createElement("style");
+      style.id = "verge-theme";
+      document.head.appendChild(style!);
+    }
+    if (style) {
+      style.innerHTML = setting.css_injection || "";
+    }
+
+    // update svg icon
     const { palette } = theme;
 
     setTimeout(() => {

+ 4 - 3
src/components/setting/setting-theme.tsx

@@ -65,6 +65,7 @@ const SettingTheme = (props: Props) => {
     try {
       await patchVergeConfig({ theme_setting: theme });
       mutate();
+      onClose();
     } catch (err: any) {
       onError?.(err);
     }
@@ -186,12 +187,12 @@ const SettingTheme = (props: Props) => {
           </Item>
 
           <Item>
-            <ListItemText primary="Font Face" />
+            <ListItemText primary="CSS Injection" />
 
             <TextField
               {...textProps}
-              value={theme.font_face ?? ""}
-              onChange={handleChange("font_face")}
+              value={theme.css_injection ?? ""}
+              onChange={handleChange("css_injection")}
             />
           </Item>
         </List>

+ 1 - 1
src/services/types.ts

@@ -139,8 +139,8 @@ export namespace CmdType {
       error_color?: string;
       warning_color?: string;
       success_color?: string;
-      font_face?: string;
       font_family?: string;
+      css_injection?: string;
     };
   }