diff --git a/app/utils.ts b/app/utils.ts index 9a8bebf38..6483bec91 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -2,8 +2,8 @@ import { useEffect, useState } from "react"; import { showToast } from "./components/ui-lib"; import Locale from "./locales"; import { RequestMessage } from "./client/api"; -import { ServiceProvider, REQUEST_TIMEOUT_MS } from "./constant"; -import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http"; +import { ServiceProvider } from "./constant"; +import { fetch as tauriFetch } from "@tauri-apps/plugin-http"; export function trimTopic(topic: string) { // Fix an issue where double quotes still show in the Indonesian language @@ -287,35 +287,18 @@ export function showPlugins(provider: ServiceProvider, model: string) { return false; } -export function fetch( - url: string, - options?: Record, -): Promise { - if (window.__TAURI__) { - const payload = options?.body || options?.data; - return tauriFetch(url, { - ...options, - body: - payload && - ({ - type: "Text", - payload, - } as any), - timeout: ((options?.timeout as number) || REQUEST_TIMEOUT_MS) / 1000, - responseType: - options?.responseType == "text" ? ResponseType.Text : ResponseType.JSON, - } as any); - } - return window.fetch(url, options); -} - export function adapter(config: Record) { const { baseURL, url, params, ...rest } = config; const path = baseURL ? `${baseURL}${url}` : url; const fetchUrl = params ? `${path}?${new URLSearchParams(params as any).toString()}` : path; - return fetch(fetchUrl as string, { ...rest, responseType: "text" }); + if (window.__TAURI__) { + return tauriFetch(fetchUrl, rest) + .then((res) => res.text()) + .then((data: any) => ({ data })); + } + return window.fetch(fetchUrl as string, rest); } export function safeLocalStorage(): { diff --git a/package.json b/package.json index 0956fcfce..641134cf2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "app:build": "yarn mask && yarn tauri build", "ios:init": "yarn tauri ios init", "ios:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri ios dev\"", - "ios:build": "yarn mask && yarn tauri ios build", + "ios:build": "yarn mask && yarn tauri ios build", "prompts": "node ./scripts/fetch-prompts.mjs", "prepare": "husky install", "proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev" @@ -25,6 +25,7 @@ "@hello-pangea/dnd": "^16.5.0", "@next/third-parties": "^14.1.0", "@svgr/webpack": "^6.5.1", + "@tauri-apps/plugin-http": "^2.0.0-rc.2", "@vercel/analytics": "^0.1.11", "@vercel/speed-insights": "^1.0.2", "axios": "^1.7.5", @@ -55,7 +56,6 @@ "zustand": "^4.3.8" }, "devDependencies": { - "@tauri-apps/api": "^1.6.0", "@tauri-apps/cli": "^2.0.0-rc.0", "@types/js-yaml": "4.0.9", "@types/lodash-es": "^4.17.12", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index de2e2dce1..687d8d022 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3820,7 +3820,7 @@ dependencies = [ "webkit2gtk", "webview2-com", "windows 0.58.0", - "wry", + "wry 0.43.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4594,7 +4594,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4945,6 +4945,12 @@ name = "wry" version = "0.43.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4d715cf5fe88e9647f3d17b207b6d060d4a88e7171d4ccb2d2c657dd1d44728" +replace = "wry 0.43.1 (git+https://github.com/lloydzhou/wry?branch=webkitgtk-data_manager-directory)" + +[[package]] +name = "wry" +version = "0.43.1" +source = "git+https://github.com/lloydzhou/wry?branch=webkitgtk-data_manager-directory#b854092847fadbc398aa727a1ed710adb3f4c8ea" dependencies = [ "base64 0.22.1", "block", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d8fa41d2e..651e8184a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "A cross platform app for LLM ChatBot." authors = ["GPTsMotion Tech LLC"] license = "mit" -repository = "" +repository = "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web" default-run = "nextchat" edition = "2021" rust-version = "1.71" @@ -24,7 +24,7 @@ serde = { version = "1.0", features = ["derive"] } log = "0.4" tauri = { version = "2.0.0-rc.15", features = [] } tauri-plugin-log = "2.0.0-rc" -tauri-plugin-http = "2.0.0-rc" +tauri-plugin-http = "2.0.0-rc.5" [replace] # using this version from github fixed data_directory for webkitgtk @@ -36,7 +36,7 @@ panic = "abort" # Strip expensive panic clean-up logic codegen-units = 1 # Compile crates one after another so the compiler can optimize better lto = true # Enables link to optimizations opt-level = "s" # Optimize for binary size -strip = true # Remove debug symbols +# strip = true # Remove debug symbols [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/capabilities/main.json b/src-tauri/capabilities/main.json index 6cedc90a6..a7ab79f16 100644 --- a/src-tauri/capabilities/main.json +++ b/src-tauri/capabilities/main.json @@ -7,13 +7,8 @@ "core:default", "core:window:allow-start-dragging", "core:window:allow-maximize", - "http:default", - "http:allow-fetch", - "http:allow-fetch-cancel", - "http:allow-fetch-read-body", - "http:allow-fetch-send", { - "identifier": "http:allow-fetch", + "identifier": "http:default", "allow": [ { "url": "https://*" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index a4579c0f8..c2bd8dc3b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,6 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/schema.json", "productName": "NextChat", + "mainBinaryName": "next-chat", "identifier": "com.yida.chatgpt.next.web", "version": "2.15.4", "build": { @@ -45,4 +46,4 @@ "icons/icon.ico" ] } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 7ba4d7d26..b5e07677e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1490,10 +1490,10 @@ "@swc/counter" "^0.1.3" tslib "^2.4.0" -"@tauri-apps/api@^1.6.0": - version "1.6.0" - resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.6.0.tgz#745b7e4e26782c3b2ad9510d558fa5bb2cf29186" - integrity sha512-rqI++FWClU5I2UBp4HXFvl+sBWkdigBkxnpJDQUWttNyG7IZP4FwQGhTNL5EOw0vI8i6eSAJ5frLqO7n7jbJdg== +"@tauri-apps/api@^2.0.0-rc.4": + version "2.0.0-rc.5" + resolved "https://registry.npmjs.org/@tauri-apps/api/-/api-2.0.0-rc.5.tgz#9e790680f5cf691b0ae4c25c4de6696f340df401" + integrity sha512-JWs69pE9NsQdcqTpEVBepAZ08+jgQWuthIiTiaWRq/YlCLgnqq0KfC9sDem55uJ0YpgsytZuyj+m6b6q8oiD2g== "@tauri-apps/cli-darwin-arm64@2.0.0-rc.16": version "2.0.0-rc.16" @@ -1561,6 +1561,13 @@ "@tauri-apps/cli-win32-ia32-msvc" "2.0.0-rc.16" "@tauri-apps/cli-win32-x64-msvc" "2.0.0-rc.16" +"@tauri-apps/plugin-http@^2.0.0-rc.2": + version "2.0.0-rc.2" + resolved "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.0.0-rc.2.tgz#385a3c0808db86b59ab0b183c85e4fd2de989cbd" + integrity sha512-s/AbbMaQPgqnIOoObvWNAjJOV17gyf9G+U6gmvjLoFbt7D6jsujOUW6fn+Oe/+rzNSEeo1ZSVrUoMen5DgM+OA== + dependencies: + "@tauri-apps/api" "^2.0.0-rc.4" + "@trysound/sax@0.2.0": version "0.2.0" resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"