发送系统通知时携带folder名
This commit is contained in:
@@ -21,7 +21,6 @@
|
|||||||
"@tanstack/react-virtual": "^3.13.18",
|
"@tanstack/react-virtual": "^3.13.18",
|
||||||
"@tauri-apps/api": "^2",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/plugin-dialog": "^2.6.0",
|
"@tauri-apps/plugin-dialog": "^2.6.0",
|
||||||
"@tauri-apps/plugin-notification": "^2.3.3",
|
|
||||||
"@tauri-apps/plugin-opener": "^2",
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
"@tauri-apps/plugin-process": "^2.3.1",
|
"@tauri-apps/plugin-process": "^2.3.1",
|
||||||
"@tauri-apps/plugin-updater": "^2.10.0",
|
"@tauri-apps/plugin-updater": "^2.10.0",
|
||||||
|
|||||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -41,9 +41,6 @@ importers:
|
|||||||
'@tauri-apps/plugin-dialog':
|
'@tauri-apps/plugin-dialog':
|
||||||
specifier: ^2.6.0
|
specifier: ^2.6.0
|
||||||
version: 2.6.0
|
version: 2.6.0
|
||||||
'@tauri-apps/plugin-notification':
|
|
||||||
specifier: ^2.3.3
|
|
||||||
version: 2.3.3
|
|
||||||
'@tauri-apps/plugin-opener':
|
'@tauri-apps/plugin-opener':
|
||||||
specifier: ^2
|
specifier: ^2
|
||||||
version: 2.5.3
|
version: 2.5.3
|
||||||
@@ -2533,9 +2530,6 @@ packages:
|
|||||||
'@tauri-apps/plugin-dialog@2.6.0':
|
'@tauri-apps/plugin-dialog@2.6.0':
|
||||||
resolution: {integrity: sha512-q4Uq3eY87TdcYzXACiYSPhmpBA76shgmQswGkSVio4C82Sz2W4iehe9TnKYwbq7weHiL88Yw19XZm7v28+Micg==}
|
resolution: {integrity: sha512-q4Uq3eY87TdcYzXACiYSPhmpBA76shgmQswGkSVio4C82Sz2W4iehe9TnKYwbq7weHiL88Yw19XZm7v28+Micg==}
|
||||||
|
|
||||||
'@tauri-apps/plugin-notification@2.3.3':
|
|
||||||
resolution: {integrity: sha512-Zw+ZH18RJb41G4NrfHgIuofJiymusqN+q8fGUIIV7vyCH+5sSn5coqRv/MWB9qETsUs97vmU045q7OyseCV3Qg==}
|
|
||||||
|
|
||||||
'@tauri-apps/plugin-opener@2.5.3':
|
'@tauri-apps/plugin-opener@2.5.3':
|
||||||
resolution: {integrity: sha512-CCcUltXMOfUEArbf3db3kCE7Ggy1ExBEBl51Ko2ODJ6GDYHRp1nSNlQm5uNCFY5k7/ufaK5Ib3Du/Zir19IYQQ==}
|
resolution: {integrity: sha512-CCcUltXMOfUEArbf3db3kCE7Ggy1ExBEBl51Ko2ODJ6GDYHRp1nSNlQm5uNCFY5k7/ufaK5Ib3Du/Zir19IYQQ==}
|
||||||
|
|
||||||
@@ -9080,10 +9074,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@tauri-apps/api': 2.10.1
|
'@tauri-apps/api': 2.10.1
|
||||||
|
|
||||||
'@tauri-apps/plugin-notification@2.3.3':
|
|
||||||
dependencies:
|
|
||||||
'@tauri-apps/api': 2.10.1
|
|
||||||
|
|
||||||
'@tauri-apps/plugin-opener@2.5.3':
|
'@tauri-apps/plugin-opener@2.5.3':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@tauri-apps/api': 2.10.1
|
'@tauri-apps/api': 2.10.1
|
||||||
|
|||||||
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@@ -804,6 +804,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"keyring",
|
"keyring",
|
||||||
"kill_tree",
|
"kill_tree",
|
||||||
|
"mac-notification-sys",
|
||||||
"notify",
|
"notify",
|
||||||
"portable-pty",
|
"portable-pty",
|
||||||
"regex",
|
"regex",
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ tauri-plugin-process = "2"
|
|||||||
tauri-plugin-notification = "2"
|
tauri-plugin-notification = "2"
|
||||||
|
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
mac-notification-sys = "0.6"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
windows-sys = { version = "0.59", features = ["Win32_Storage_FileSystem"] }
|
windows-sys = { version = "0.59", features = ["Win32_Storage_FileSystem"] }
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ pub mod mcp;
|
|||||||
pub mod system_settings;
|
pub mod system_settings;
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
pub mod version_control;
|
pub mod version_control;
|
||||||
|
pub mod notification;
|
||||||
pub mod windows;
|
pub mod windows;
|
||||||
|
|||||||
38
src-tauri/src/commands/notification.rs
Normal file
38
src-tauri/src/commands/notification.rs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
use tauri::AppHandle;
|
||||||
|
|
||||||
|
use crate::app_error::AppCommandError;
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn send_notification(
|
||||||
|
#[allow(unused_variables)] app: AppHandle,
|
||||||
|
title: String,
|
||||||
|
body: String,
|
||||||
|
) -> Result<(), AppCommandError> {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
let app_id = if tauri::is_dev() {
|
||||||
|
"com.apple.Terminal"
|
||||||
|
} else {
|
||||||
|
"app.codeg"
|
||||||
|
};
|
||||||
|
let _ = mac_notification_sys::set_application(app_id);
|
||||||
|
|
||||||
|
let _ = mac_notification_sys::Notification::default()
|
||||||
|
.title(&title)
|
||||||
|
.message(&body)
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
{
|
||||||
|
use tauri_plugin_notification::NotificationExt;
|
||||||
|
let _ = app
|
||||||
|
.notification()
|
||||||
|
.builder()
|
||||||
|
.title(title)
|
||||||
|
.body(body)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||||||
use acp::manager::ConnectionManager;
|
use acp::manager::ConnectionManager;
|
||||||
use commands::{
|
use commands::{
|
||||||
acp as acp_commands, conversations, folder_commands, folders, mcp as mcp_commands,
|
acp as acp_commands, conversations, folder_commands, folders, mcp as mcp_commands,
|
||||||
system_settings, terminal as terminal_commands, version_control, windows,
|
notification, system_settings, terminal as terminal_commands, version_control, windows,
|
||||||
};
|
};
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
use terminal::manager::TerminalManager;
|
use terminal::manager::TerminalManager;
|
||||||
@@ -319,6 +319,7 @@ pub fn run() {
|
|||||||
mcp_commands::mcp_upsert_local_server,
|
mcp_commands::mcp_upsert_local_server,
|
||||||
mcp_commands::mcp_set_server_apps,
|
mcp_commands::mcp_set_server_apps,
|
||||||
mcp_commands::mcp_remove_server,
|
mcp_commands::mcp_remove_server,
|
||||||
|
notification::send_notification,
|
||||||
])
|
])
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while building tauri application")
|
.expect("error while building tauri application")
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import {
|
|||||||
} from "@/lib/constants"
|
} from "@/lib/constants"
|
||||||
import { notifyTurnComplete } from "@/lib/notification"
|
import { notifyTurnComplete } from "@/lib/notification"
|
||||||
import { useAlertContext, type AlertAction } from "@/contexts/alert-context"
|
import { useAlertContext, type AlertAction } from "@/contexts/alert-context"
|
||||||
|
import { useFolderContext } from "@/contexts/folder-context"
|
||||||
|
|
||||||
// ── Shared types (re-exported for consumers) ──
|
// ── Shared types (re-exported for consumers) ──
|
||||||
|
|
||||||
@@ -1125,6 +1126,11 @@ function isAlertedError(error: unknown): error is AlertedError {
|
|||||||
export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
|
export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
|
||||||
const t = useTranslations("Folder.chat.acpConnections")
|
const t = useTranslations("Folder.chat.acpConnections")
|
||||||
const { pushAlert } = useAlertContext()
|
const { pushAlert } = useAlertContext()
|
||||||
|
const { folder } = useFolderContext()
|
||||||
|
const folderNameRef = useRef(folder?.name)
|
||||||
|
useEffect(() => {
|
||||||
|
folderNameRef.current = folder?.name
|
||||||
|
}, [folder?.name])
|
||||||
const pushAlertRef = useRef(pushAlert)
|
const pushAlertRef = useRef(pushAlert)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pushAlertRef.current = pushAlert
|
pushAlertRef.current = pushAlert
|
||||||
@@ -1551,8 +1557,10 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
|
|||||||
const nc = storeRef.current.connections.get(contextKey)
|
const nc = storeRef.current.connections.get(contextKey)
|
||||||
if (nc) {
|
if (nc) {
|
||||||
const agentLabel = AGENT_LABELS[nc.agentType]
|
const agentLabel = AGENT_LABELS[nc.agentType]
|
||||||
|
const fn = folderNameRef.current
|
||||||
|
const title = fn ? `${fn} - Codeg` : "Codeg"
|
||||||
notifyTurnComplete(
|
notifyTurnComplete(
|
||||||
"Codeg",
|
title,
|
||||||
t("notificationTurnComplete", { agent: agentLabel }),
|
t("notificationTurnComplete", { agent: agentLabel }),
|
||||||
).catch(() => {})
|
).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/lib/notification.ts
Normal file
9
src/lib/notification.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { invoke } from "@tauri-apps/api/core"
|
||||||
|
|
||||||
|
export async function notifyTurnComplete(
|
||||||
|
title: string,
|
||||||
|
body: string,
|
||||||
|
): Promise<void> {
|
||||||
|
if (!document.hidden) return
|
||||||
|
await invoke("send_notification", { title, body })
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user