2ue 1 miesiąc temu
rodzic
commit
572c11617b

+ 37 - 0
src-tauri/src/lib.rs

@@ -101,6 +101,7 @@ pub fn run() {
             show_coco,
             hide_coco,
             show_settings,
+            show_chat,
             server::servers::get_server_token,
             server::servers::add_coco_server,
             server::servers::remove_coco_server,
@@ -407,6 +408,37 @@ fn open_settings(app: &tauri::AppHandle) {
             .unwrap();
     }
 }
+#[allow(dead_code)]
+fn open_chat(app: &tauri::AppHandle) {
+    use tauri::webview::WebviewBuilder;
+    println!("settings menu item was clicked");
+    let window = app.get_webview_window("chat");
+    if let Some(window) = window {
+        let _ = window.show();
+        let _ = window.unminimize();
+        let _ = window.set_focus();
+    } else {
+        let window = tauri::window::WindowBuilder::new(app, "chat")
+            .title("chat")
+            .fullscreen(false)
+            .resizable(false)
+            .minimizable(false)
+            .maximizable(false)
+            .inner_size(800.0, 600.0)
+            .build()
+            .unwrap();
+
+        let webview_builder =
+            WebviewBuilder::new("chat", tauri::WebviewUrl::App("/".into()));
+        let _webview = window
+            .add_child(
+                webview_builder,
+                tauri::LogicalPosition::new(0, 0),
+                window.inner_size().unwrap(),
+            )
+            .unwrap();
+    }
+}
 
 #[tauri::command]
 async fn get_app_search_source<R: Runtime>(app_handle: AppHandle<R>) -> Result<(), String> {
@@ -421,3 +453,8 @@ async fn get_app_search_source<R: Runtime>(app_handle: AppHandle<R>) -> Result<(
 async fn show_settings(app_handle: AppHandle) {
     open_settings(&app_handle);
 }
+
+#[tauri::command]
+async fn show_chat(app_handle: AppHandle) {
+  open_chat(&app_handle);
+}

+ 48 - 8
src-tauri/tauri.conf.json

@@ -50,7 +50,29 @@
         "hiddenTitle": true,
         "visible": false,
         "windowEffects": {
-          "effects": ["sidebar"],
+          "effects": [
+            "sidebar"
+          ],
+          "state": "active"
+        }
+      },
+      {
+        "label": "chat",
+        "title": "chat",
+        "url": "http://129.226.167.149:36058/#/chat",
+        "width": 1000,
+        "height": 700,
+        "center": true,
+        "transparent": true,
+        "maximizable": false,
+        "skipTaskbar": false,
+        "dragDropEnabled": false,
+        "hiddenTitle": true,
+        "visible": false,
+        "windowEffects": {
+          "effects": [
+            "sidebar"
+          ],
           "state": "active"
         }
       }
@@ -61,7 +83,9 @@
       "assetProtocol": {
         "enable": true,
         "scope": {
-          "allow": ["**/*"],
+          "allow": [
+            "**/*"
+          ],
           "requireLiteralLeadingDot": false
         }
       }
@@ -70,7 +94,14 @@
   "bundle": {
     "active": true,
     "createUpdaterArtifacts": true,
-    "targets": ["nsis", "dmg", "app", "appimage", "deb", "rpm"],
+    "targets": [
+      "nsis",
+      "dmg",
+      "app",
+      "appimage",
+      "deb",
+      "rpm"
+    ],
     "category": "Utility",
     "shortDescription": "Coco AI",
     "icon": [
@@ -105,11 +136,16 @@
         }
       }
     },
-    "resources": ["assets", "icons"]
+    "resources": [
+      "assets",
+      "icons"
+    ]
   },
   "plugins": {
     "features": {
-      "protocol": ["all"]
+      "protocol": [
+        "all"
+      ]
     },
     "window": {},
     "updater": {
@@ -126,13 +162,17 @@
       "mobile": [
         {
           "host": "app.infini.cloud",
-          "pathPrefix": ["/open"]
+          "pathPrefix": [
+            "/open"
+          ]
         }
       ],
       "desktop": {
-        "schemes": ["coco"]
+        "schemes": [
+          "coco"
+        ]
       }
     },
     "os": {}
   }
-}
+}

+ 4 - 0
src/commands/system.ts

@@ -26,4 +26,8 @@ export function show_coco(): Promise<void> {
 
 export function show_settings(): Promise<void> {
   return invoke('show_settings');
+}
+
+export function show_chat(): Promise<void> {
+  return invoke('show_chat');
 }

+ 9 - 1
src/hooks/useTray.ts

@@ -7,7 +7,7 @@ import { exit } from "@tauri-apps/plugin-process";
 
 import { isMac } from "@/utils/platform";
 import { useAppStore } from "@/stores/appStore";
-import { show_coco, show_settings } from "@/commands";
+import { show_coco, show_settings, show_chat } from "@/commands";
 
 const TRAY_ID = "COCO_TRAY";
 
@@ -63,6 +63,14 @@ export const useTray = () => {
         },
       }),
       PredefinedMenuItem.new({ item: "Separator" }),
+      MenuItem.new({
+        text: t("tray.chat"),
+        // accelerator: "CommandOrControl+,",
+        action: () => {
+          show_chat()
+        },
+      }),
+      PredefinedMenuItem.new({ item: "Separator" }),
       MenuItem.new({
         text: t("tray.quitCoco"),
         accelerator: "CommandOrControl+Q",

+ 2 - 1
src/locales/en/translation.json

@@ -351,6 +351,7 @@
   "tray": {
     "showCoco": "Show Coco",
     "settings": "Settings...",
+    "LeiTing Chat": "open chat",
     "quitCoco": "Quit Coco"
   },
   "update": {
@@ -399,4 +400,4 @@
     "remainder": "Remainder",
     "expression": "Expression"
   }
-}
+}

+ 2 - 2
src/locales/zh/translation.json

@@ -163,7 +163,6 @@
     },
     "extensions": {
       "title": "扩展",
-
       "application": {
         "name": "名称",
         "where": "来源",
@@ -353,6 +352,7 @@
   "tray": {
     "showCoco": "显示 Coco",
     "settings": "偏好设置",
+    "chat": "打开雷霆AI对话",
     "quitCoco": "退出 Coco"
   },
   "update": {
@@ -400,4 +400,4 @@
     "remainder": "求余",
     "expression": "表达式"
   }
-}
+}