From 98afd5516b697d3a8cafe12e9aeac09aba79e45c Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Thu, 29 Jun 2023 00:27:18 +0800 Subject: [PATCH] feat: close #1994 add clipboard write api --- app/global.d.ts | 6 ++++++ app/utils.ts | 7 ++++++- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 17 ++++++++++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/global.d.ts b/app/global.d.ts index bd1c062d..524ce77d 100644 --- a/app/global.d.ts +++ b/app/global.d.ts @@ -9,3 +9,9 @@ declare module "*.scss" { } declare module "*.svg"; + +declare interface Window { + __TAURI__?: { + writeText(text: string): Promise; + }; +} diff --git a/app/utils.ts b/app/utils.ts index c083c34f..37c17dd7 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -8,7 +8,12 @@ export function trimTopic(topic: string) { export async function copyToClipboard(text: string) { try { - await navigator.clipboard.writeText(text); + if (window.__TAURI__) { + window.__TAURI__.writeText(text); + } else { + await navigator.clipboard.writeText(text); + } + showToast(Locale.Copy.Success); } catch (error) { const textArea = document.createElement("textarea"); diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 694f62cb..ac5d04e8 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ tauri-build = { version = "1.3.0", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.3.0", features = ["clipboard-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-icon", "window-set-ignore-cursor-events", "window-set-resizable", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] } +tauri = { version = "1.3.0", features = ["clipboard-all", "dialog-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-icon", "window-set-ignore-cursor-events", "window-set-resizable", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } [features] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 2a8be490..154afc96 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -4,11 +4,12 @@ "beforeBuildCommand": "yarn export", "beforeDevCommand": "yarn export:dev", "devPath": "http://localhost:3000", - "distDir": "../out" + "distDir": "../out", + "withGlobalTauri": true }, "package": { "productName": "chatgpt-next-web", - "version": "2.8.4" + "version": "2.8.5" }, "tauri": { "allowlist": { @@ -17,8 +18,18 @@ "all": false, "open": true }, + "dialog": { + "all": true, + "ask": true, + "confirm": true, + "message": true, + "open": true, + "save": true + }, "clipboard": { - "all": true + "all": true, + "writeText": true, + "readText": true }, "window": { "all": false,