fix: Esc key failure issue & removing unused code related to the tauri-nspanel plugin & introduct the server variable name (#85)

* fix: Esc key failure issue

* feat: add env

* chore: modify the environment variable name

* chore: modify websocket id  name

* chore: remove tauri-nspanel
This commit is contained in:
BiggerRain
2025-01-06 10:50:44 +08:00
committed by GitHub
parent aafa792d15
commit e2dfda9f1d
16 changed files with 108 additions and 87 deletions

3
.env Normal file
View File

@@ -0,0 +1,3 @@
COCO_SERVER_URL=https://coco.infini.cloud # http://localhost:2900
COCO_WEBSOCKET_URL=wss://coco.infini.cloud/ws # ws://localhost:2900/ws

View File

@@ -33,6 +33,7 @@
"unlisten", "unlisten",
"unlistener", "unlistener",
"unminimize", "unminimize",
"VITE",
"webviews", "webviews",
"zustand" "zustand"
], ],

View File

@@ -21,6 +21,7 @@
"@tauri-apps/plugin-window": "2.0.0-alpha.1", "@tauri-apps/plugin-window": "2.0.0-alpha.1",
"axios": "^1.7.7", "axios": "^1.7.7",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"dotenv": "^16.4.7",
"i18next": "^23.16.2", "i18next": "^23.16.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"lucide-react": "^0.453.0", "lucide-react": "^0.453.0",

22
pnpm-lock.yaml generated
View File

@@ -41,6 +41,9 @@ importers:
clsx: clsx:
specifier: ^2.1.1 specifier: ^2.1.1
version: 2.1.1 version: 2.1.1
dotenv:
specifier: ^16.4.7
version: 16.4.7
i18next: i18next:
specifier: ^23.16.2 specifier: ^23.16.2
version: 23.16.2 version: 23.16.2
@@ -533,46 +536,55 @@ packages:
resolution: {integrity: sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==} resolution: {integrity: sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==}
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-arm-musleabihf@4.24.0': '@rollup/rollup-linux-arm-musleabihf@4.24.0':
resolution: {integrity: sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==} resolution: {integrity: sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==}
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
libc: [musl]
'@rollup/rollup-linux-arm64-gnu@4.24.0': '@rollup/rollup-linux-arm64-gnu@4.24.0':
resolution: {integrity: sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==} resolution: {integrity: sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-arm64-musl@4.24.0': '@rollup/rollup-linux-arm64-musl@4.24.0':
resolution: {integrity: sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==} resolution: {integrity: sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
libc: [musl]
'@rollup/rollup-linux-powerpc64le-gnu@4.24.0': '@rollup/rollup-linux-powerpc64le-gnu@4.24.0':
resolution: {integrity: sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==} resolution: {integrity: sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==}
cpu: [ppc64] cpu: [ppc64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-riscv64-gnu@4.24.0': '@rollup/rollup-linux-riscv64-gnu@4.24.0':
resolution: {integrity: sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==} resolution: {integrity: sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==}
cpu: [riscv64] cpu: [riscv64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-s390x-gnu@4.24.0': '@rollup/rollup-linux-s390x-gnu@4.24.0':
resolution: {integrity: sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==} resolution: {integrity: sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==}
cpu: [s390x] cpu: [s390x]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-x64-gnu@4.24.0': '@rollup/rollup-linux-x64-gnu@4.24.0':
resolution: {integrity: sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==} resolution: {integrity: sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-x64-musl@4.24.0': '@rollup/rollup-linux-x64-musl@4.24.0':
resolution: {integrity: sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==} resolution: {integrity: sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
libc: [musl]
'@rollup/rollup-win32-arm64-msvc@4.24.0': '@rollup/rollup-win32-arm64-msvc@4.24.0':
resolution: {integrity: sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==} resolution: {integrity: sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==}
@@ -631,24 +643,28 @@ packages:
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
libc: [glibc]
'@tauri-apps/cli-linux-arm64-musl@2.0.3': '@tauri-apps/cli-linux-arm64-musl@2.0.3':
resolution: {integrity: sha512-I4MVD7nf6lLLRmNQPpe5beEIFM6q7Zkmh77ROA5BNu/+vHNL5kiTMD+bmd10ZL2r753A6pO7AvqkIxcBuIl0tg==} resolution: {integrity: sha512-I4MVD7nf6lLLRmNQPpe5beEIFM6q7Zkmh77ROA5BNu/+vHNL5kiTMD+bmd10ZL2r753A6pO7AvqkIxcBuIl0tg==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
libc: [musl]
'@tauri-apps/cli-linux-x64-gnu@2.0.3': '@tauri-apps/cli-linux-x64-gnu@2.0.3':
resolution: {integrity: sha512-C6Jkx2zZGKkoi+sg5FK9GoH/0EvAaOgrZfF5azV5EALGba46g7VpWcZgp9zFUd7K2IzTi+0OOY8TQ2OVfKZgew==} resolution: {integrity: sha512-C6Jkx2zZGKkoi+sg5FK9GoH/0EvAaOgrZfF5azV5EALGba46g7VpWcZgp9zFUd7K2IzTi+0OOY8TQ2OVfKZgew==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
libc: [glibc]
'@tauri-apps/cli-linux-x64-musl@2.0.3': '@tauri-apps/cli-linux-x64-musl@2.0.3':
resolution: {integrity: sha512-qi4ghmTfSAl+EEUDwmwI9AJUiOLNSmU1RgiGgcPRE+7A/W+Am9UnxYySAiRbB/gJgTl9sj/pqH5Y9duP1/sqHg==} resolution: {integrity: sha512-qi4ghmTfSAl+EEUDwmwI9AJUiOLNSmU1RgiGgcPRE+7A/W+Am9UnxYySAiRbB/gJgTl9sj/pqH5Y9duP1/sqHg==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
libc: [musl]
'@tauri-apps/cli-win32-arm64-msvc@2.0.3': '@tauri-apps/cli-win32-arm64-msvc@2.0.3':
resolution: {integrity: sha512-UXxHkYmFesC97qVmZre4vY7oDxRDtC2OeKNv0bH+iSnuUp/ROxzJYGyaelnv9Ybvgl4YVqDCnxgB28qMM938TA==} resolution: {integrity: sha512-UXxHkYmFesC97qVmZre4vY7oDxRDtC2OeKNv0bH+iSnuUp/ROxzJYGyaelnv9Ybvgl4YVqDCnxgB28qMM938TA==}
@@ -1237,6 +1253,10 @@ packages:
dompurify@3.1.6: dompurify@3.1.6:
resolution: {integrity: sha512-cTOAhc36AalkjtBpfG6O8JimdTMWNXjiePT2xQH/ppBGi/4uIpmj8eKyIkMJErXWARyINV/sB38yf8JCLF5pbQ==} resolution: {integrity: sha512-cTOAhc36AalkjtBpfG6O8JimdTMWNXjiePT2xQH/ppBGi/4uIpmj8eKyIkMJErXWARyINV/sB38yf8JCLF5pbQ==}
dotenv@16.4.7:
resolution: {integrity: sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==}
engines: {node: '>=12'}
eastasianwidth@0.2.0: eastasianwidth@0.2.0:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
@@ -3317,6 +3337,8 @@ snapshots:
dompurify@3.1.6: {} dompurify@3.1.6: {}
dotenv@16.4.7: {}
eastasianwidth@0.2.0: {} eastasianwidth@0.2.0: {}
electron-to-chromium@1.5.36: {} electron-to-chromium@1.5.36: {}

37
src-tauri/Cargo.lock generated
View File

@@ -546,7 +546,6 @@ dependencies = [
"serde_json", "serde_json",
"tauri", "tauri",
"tauri-build", "tauri-build",
"tauri-nspanel",
"tauri-plugin-autostart", "tauri-plugin-autostart",
"tauri-plugin-global-shortcut", "tauri-plugin-global-shortcut",
"tauri-plugin-http", "tauri-plugin-http",
@@ -2328,17 +2327,6 @@ dependencies = [
"malloc_buf", "malloc_buf",
] ]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]] [[package]]
name = "objc-sys" name = "objc-sys"
version = "0.3.5" version = "0.3.5"
@@ -2557,15 +2545,6 @@ dependencies = [
"objc2-foundation", "objc2-foundation",
] ]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.36.5" version = "0.36.5"
@@ -4023,22 +4002,6 @@ dependencies = [
"tauri-utils", "tauri-utils",
] ]
[[package]]
name = "tauri-nspanel"
version = "2.0.0"
source = "git+https://github.com/ahkohd/tauri-nspanel?branch=v2#23b30f0f1974c35673db3234f1f1bd214fa9c4e9"
dependencies = [
"bitflags 2.6.0",
"block",
"cocoa",
"core-foundation 0.10.0",
"core-graphics",
"objc",
"objc-foundation",
"objc_id",
"tauri",
]
[[package]] [[package]]
name = "tauri-plugin" name = "tauri-plugin"
version = "2.0.1" version = "2.0.1"

View File

@@ -27,7 +27,7 @@ tauri-plugin-http = "2"
tauri-plugin-websocket = "2" tauri-plugin-websocket = "2"
tauri-plugin-theme = "2.1.2" tauri-plugin-theme = "2.1.2"
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" } # tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }
[profile.dev] [profile.dev]
incremental = true # Compile your binary in smaller steps. incremental = true # Compile your binary in smaller steps.

View File

@@ -49,6 +49,9 @@
"allow": [ "allow": [
{ {
"url": "http://localhost:2900" "url": "http://localhost:2900"
},
{
"url": "https://coco.infini.cloud"
} }
], ],
"deny": [] "deny": []

View File

@@ -1,7 +1,7 @@
use std::{fs::create_dir, io::Read}; use std::{fs::create_dir, io::Read};
use tauri::{AppHandle, Emitter, Listener, Manager, Runtime, WebviewWindow}; use tauri::{AppHandle, Emitter, Listener, Manager, Runtime, WebviewWindow};
use tauri_nspanel::{panel_delegate, ManagerExt, WebviewWindowExt}; // use tauri_nspanel::{panel_delegate, ManagerExt, WebviewWindowExt};
use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut}; use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
@@ -32,28 +32,28 @@ fn change_window_height(handle: AppHandle, height: u32) {
window.set_size(size).unwrap(); window.set_size(size).unwrap();
} }
#[tauri::command] // #[tauri::command]
fn show_panel(handle: AppHandle) { // fn show_panel(handle: AppHandle) {
let panel = handle.get_webview_panel("main").unwrap(); // let panel = handle.get_webview_panel("main").unwrap();
panel.show(); // panel.show();
} // }
#[tauri::command] // #[tauri::command]
fn hide_panel(handle: AppHandle) { // fn hide_panel(handle: AppHandle) {
let panel = handle.get_webview_panel("main").unwrap(); // let panel = handle.get_webview_panel("main").unwrap();
panel.order_out(None); // panel.order_out(None);
} // }
#[tauri::command] // #[tauri::command]
fn close_panel(handle: AppHandle) { // fn close_panel(handle: AppHandle) {
let panel = handle.get_webview_panel("main").unwrap(); // let panel = handle.get_webview_panel("main").unwrap();
panel.released_when_closed(true); // panel.released_when_closed(true);
panel.close(); // panel.close();
} // }
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
struct ThemeChangedPayload { struct ThemeChangedPayload {
@@ -65,7 +65,7 @@ pub fn run() {
let mut ctx = tauri::generate_context!(); let mut ctx = tauri::generate_context!();
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_nspanel::init()) // .plugin(tauri_nspanel::init())
.plugin(tauri_plugin_http::init()) .plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_autostart::init( .plugin(tauri_plugin_autostart::init(
@@ -81,9 +81,9 @@ pub fn run() {
change_autostart, change_autostart,
hide_coco, hide_coco,
switch_tray_icon, switch_tray_icon,
show_panel, // show_panel,
hide_panel, // hide_panel,
close_panel // close_panel
]) ])
.setup(|app| { .setup(|app| {
init(app.app_handle()); init(app.app_handle());
@@ -108,33 +108,33 @@ pub fn run() {
.expect("error while running tauri application"); .expect("error while running tauri application");
} }
fn init(app_handle: &AppHandle) { fn init(_app_handle: &AppHandle) {
let window: WebviewWindow = app_handle.get_webview_window("main").unwrap(); // let window: WebviewWindow = app_handle.get_webview_window("main").unwrap();
let panel = window.to_panel().unwrap(); // let panel = window.to_panel().unwrap();
let delegate = panel_delegate!(MyPanelDelegate { // let delegate = panel_delegate!(MyPanelDelegate {
window_did_become_key, // window_did_become_key,
window_did_resign_key // window_did_resign_key
}); // });
let handle = app_handle.to_owned(); // let handle = app_handle.to_owned();
delegate.set_listener(Box::new(move |delegate_name: String| { // delegate.set_listener(Box::new(move |delegate_name: String| {
match delegate_name.as_str() { // match delegate_name.as_str() {
"window_did_become_key" => { // "window_did_become_key" => {
let app_name = handle.package_info().name.to_owned(); // let app_name = handle.package_info().name.to_owned();
println!("[info]: {:?} panel becomes key window!", app_name); // println!("[info]: {:?} panel becomes key window!", app_name);
} // }
"window_did_resign_key" => { // "window_did_resign_key" => {
println!("[info]: panel resigned from key window!"); // println!("[info]: panel resigned from key window!");
} // }
_ => (), // _ => (),
} // }
})); // }));
panel.set_delegate(delegate); // panel.set_delegate(delegate);
} }
fn enable_shortcut(app: &mut tauri::App) { fn enable_shortcut(app: &mut tauri::App) {

View File

@@ -1,6 +1,10 @@
import { isTauri } from "@tauri-apps/api/core"; import { isTauri } from "@tauri-apps/api/core";
import { fetch as tauriFetchModule } from "@tauri-apps/plugin-http"; import { fetch as tauriFetchModule } from "@tauri-apps/plugin-http";
import { clientEnv } from "@/utils/env";
const baseURL = `${clientEnv.COCO_SERVER_URL}`
// Use a conditional fetch depending on whether it's in a Tauri environment or web // Use a conditional fetch depending on whether it's in a Tauri environment or web
let customFetch: typeof window.fetch | typeof tauriFetchModule = window.fetch; let customFetch: typeof window.fetch | typeof tauriFetchModule = window.fetch;
@@ -8,8 +12,6 @@ if (isTauri()) {
customFetch = tauriFetchModule; customFetch = tauriFetchModule;
} }
const baseURL = "http://localhost:2900";
interface FetchRequestConfig { interface FetchRequestConfig {
url: string; url: string;
method?: "GET" | "POST" | "PUT" | "DELETE"; method?: "GET" | "POST" | "PUT" | "DELETE";

View File

@@ -1,6 +1,8 @@
import { fetch } from "@tauri-apps/plugin-http"; import { fetch } from "@tauri-apps/plugin-http";
const baseURL = "http://localhost:2900"; import { clientEnv } from "@/utils/env";
const baseURL = `${clientEnv.COCO_SERVER_URL}`
interface FetchRequestConfig { interface FetchRequestConfig {
url: string; url: string;

View File

@@ -14,6 +14,7 @@ import { tauriFetch } from "../../api/tauriFetchClient";
import { useWebSocket } from "../../hooks/useWebSocket"; import { useWebSocket } from "../../hooks/useWebSocket";
import { useChatStore } from "../../stores/chatStore"; import { useChatStore } from "../../stores/chatStore";
import { useWindows } from "../../hooks/useWindows"; import { useWindows } from "../../hooks/useWindows";
import { clientEnv } from "@/utils/env";
interface ChatAIProps { interface ChatAIProps {
inputValue: string; inputValue: string;
@@ -51,7 +52,7 @@ const ChatAI = forwardRef<ChatAIRef, ChatAIProps>(
const curIdRef = useRef(curId); const curIdRef = useRef(curId);
curIdRef.current = curId; curIdRef.current = curId;
const { messages, setMessages } = useWebSocket( const { messages, setMessages } = useWebSocket(
"ws://localhost:2900/ws", `${clientEnv.COCO_WEBSOCKET_URL}`,
(msg) => { (msg) => {
console.log("msg", msg); console.log("msg", msg);
if (msg.includes("websocket-session-id")) { if (msg.includes("websocket-session-id")) {

View File

@@ -9,6 +9,7 @@ import type { Chat, Message } from "./types";
import { tauriFetch } from "../../api/tauriFetchClient"; import { tauriFetch } from "../../api/tauriFetchClient";
import { useWebSocket } from "../../hooks/useWebSocket"; import { useWebSocket } from "../../hooks/useWebSocket";
import { useWindows } from "../../hooks/useWindows"; import { useWindows } from "../../hooks/useWindows";
import { clientEnv } from "@/utils/env";
interface ChatAIProps {} interface ChatAIProps {}
@@ -33,7 +34,7 @@ export default function ChatAI({}: ChatAIProps) {
const curIdRef = useRef(curId); const curIdRef = useRef(curId);
curIdRef.current = curId; curIdRef.current = curId;
const { messages, setMessages } = useWebSocket( const { messages, setMessages } = useWebSocket(
"ws://localhost:2900/ws", `${clientEnv.COCO_WEBSOCKET_URL}`,
(msg) => { (msg) => {
if (msg.includes("websocket-session-id")) { if (msg.includes("websocket-session-id")) {
const array = msg.split(" "); const array = msg.split(" ");

View File

@@ -14,6 +14,7 @@ const useEscape = () => {
useEffect(() => { useEffect(() => {
if(!isTauri()) return; if(!isTauri()) return;
const unlisten = listen("tauri://focus", () => { const unlisten = listen("tauri://focus", () => {
// Add event listener for keydown // Add event listener for keydown
window.addEventListener("keydown", handleEscape); window.addEventListener("keydown", handleEscape);

7
src/utils/env.ts Normal file
View File

@@ -0,0 +1,7 @@
export const clientEnv = {
COCO_SERVER_URL: import.meta.env.COCO_SERVER_URL ?? "https://coco.infini.cloud",
COCO_WEBSOCKET_URL: import.meta.env.COCO_WEBSOCKET_URL ?? "wss://coco.infini.cloud/ws",
};
// http://localhost:2900
// ws://localhost:2900/ws

10
src/vite-env.d.ts vendored
View File

@@ -1 +1,11 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
interface ImportMetaEnv {
readonly COCO_SERVER_URL: string;
readonly COCO_WEBSOCKET_URL: string;
// more env variables...
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}

View File

@@ -1,8 +1,12 @@
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import react from "@vitejs/plugin-react"; import react from "@vitejs/plugin-react";
import path from 'path'; import path from 'path';
import { config } from "dotenv";
config();
const host = process.env.TAURI_DEV_HOST; const host = process.env.TAURI_DEV_HOST;
// console.log("process.env", process.env)
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(async () => ({ export default defineConfig(async () => ({
@@ -34,12 +38,12 @@ export default defineConfig(async () => ({
}, },
proxy: { proxy: {
"/chat": { "/chat": {
target: "http://localhost:2900", target: process.env.COCO_SERVER_URL,
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
}, },
"/query": { "/query": {
target: "http://localhost:2900", target: process.env.COCO_SERVER_URL,
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
}, },