3 Commits

Author SHA1 Message Date
BiggerRain
8f992bfa92 chore: bump version number to 0.7.1 (#830) 2025-07-27 17:26:08 +08:00
BiggerRain
e7dd27c744 chore: add toggle_move_to_active_space_attribute (#829)
* chore: add toggle_move_to_active_space_attribute

* chore: pin

* chore: add

* update

---------

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2025-07-27 16:50:11 +08:00
ayangweb
7914836c3e fix: correct enter key behavior (#828) 2025-07-27 11:52:40 +08:00
11 changed files with 180 additions and 54 deletions

View File

@@ -11,12 +11,11 @@ Information about release notes of Coco Server is provided here.
### ❌ Breaking changes ### ❌ Breaking changes
### 🚀 Features ### 🚀 Features
### 🐛 Bug fix ### 🐛 Bug fix
- fix: correct enter key behavior #828
### ✈️ Improvements ### ✈️ Improvements

View File

@@ -1,7 +1,7 @@
{ {
"name": "coco", "name": "coco",
"private": true, "private": true,
"version": "0.7.0", "version": "0.7.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

83
src-tauri/Cargo.lock generated
View File

@@ -840,7 +840,7 @@ dependencies = [
[[package]] [[package]]
name = "coco" name = "coco"
version = "0.7.0" version = "0.7.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"applications", "applications",
@@ -852,6 +852,7 @@ dependencies = [
"cfg-if", "cfg-if",
"chinese-number", "chinese-number",
"chrono", "chrono",
"cocoa 0.24.1",
"derive_more 2.0.1", "derive_more 2.0.1",
"dirs 5.0.1", "dirs 5.0.1",
"enigo", "enigo",
@@ -914,6 +915,22 @@ dependencies = [
"zip 4.0.0", "zip 4.0.0",
] ]
[[package]]
name = "cocoa"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a"
dependencies = [
"bitflags 1.3.2",
"block",
"cocoa-foundation 0.1.2",
"core-foundation 0.9.4",
"core-graphics 0.22.3",
"foreign-types 0.3.2",
"libc",
"objc",
]
[[package]] [[package]]
name = "cocoa" name = "cocoa"
version = "0.26.0" version = "0.26.0"
@@ -922,14 +939,28 @@ checksum = "f79398230a6e2c08f5c9760610eb6924b52aa9e7950a619602baba59dcbbdbb2"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"block", "block",
"cocoa-foundation", "cocoa-foundation 0.2.0",
"core-foundation 0.10.0", "core-foundation 0.10.0",
"core-graphics", "core-graphics 0.24.0",
"foreign-types 0.5.0", "foreign-types 0.5.0",
"libc", "libc",
"objc", "objc",
] ]
[[package]]
name = "cocoa-foundation"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7"
dependencies = [
"bitflags 1.3.2",
"block",
"core-foundation 0.9.4",
"core-graphics-types 0.1.3",
"libc",
"objc",
]
[[package]] [[package]]
name = "cocoa-foundation" name = "cocoa-foundation"
version = "0.2.0" version = "0.2.0"
@@ -939,7 +970,7 @@ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"block", "block",
"core-foundation 0.10.0", "core-foundation 0.10.0",
"core-graphics-types", "core-graphics-types 0.2.0",
"libc", "libc",
"objc", "objc",
] ]
@@ -1056,6 +1087,19 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "core-graphics"
version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
dependencies = [
"bitflags 1.3.2",
"core-foundation 0.9.4",
"core-graphics-types 0.1.3",
"foreign-types 0.3.2",
"libc",
]
[[package]] [[package]]
name = "core-graphics" name = "core-graphics"
version = "0.24.0" version = "0.24.0"
@@ -1064,11 +1108,22 @@ checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"core-foundation 0.10.0", "core-foundation 0.10.0",
"core-graphics-types", "core-graphics-types 0.2.0",
"foreign-types 0.5.0", "foreign-types 0.5.0",
"libc", "libc",
] ]
[[package]]
name = "core-graphics-types"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf"
dependencies = [
"bitflags 1.3.2",
"core-foundation 0.9.4",
"libc",
]
[[package]] [[package]]
name = "core-graphics-types" name = "core-graphics-types"
version = "0.2.0" version = "0.2.0"
@@ -1472,8 +1527,8 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67fd9ae1736d6ebb2e472740fbee86fb2178b8d56feb98a6751411d4c95b7e72" checksum = "67fd9ae1736d6ebb2e472740fbee86fb2178b8d56feb98a6751411d4c95b7e72"
dependencies = [ dependencies = [
"cocoa", "cocoa 0.26.0",
"core-graphics", "core-graphics 0.24.0",
"dunce", "dunce",
"gdk", "gdk",
"gdkx11", "gdkx11",
@@ -1562,7 +1617,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cf6f550bbbdd5fe66f39d429cb2604bcdacbf00dca0f5bbe2e9306a0009b7c6" checksum = "0cf6f550bbbdd5fe66f39d429cb2604bcdacbf00dca0f5bbe2e9306a0009b7c6"
dependencies = [ dependencies = [
"core-foundation 0.10.0", "core-foundation 0.10.0",
"core-graphics", "core-graphics 0.24.0",
"foreign-types-shared 0.3.1", "foreign-types-shared 0.3.1",
"libc", "libc",
"log", "log",
@@ -2714,7 +2769,7 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"wasm-bindgen", "wasm-bindgen",
"windows-core 0.59.0", "windows-core 0.61.2",
] ]
[[package]] [[package]]
@@ -5721,7 +5776,7 @@ checksum = "18051cdd562e792cad055119e0cdb2cfc137e44e3987532e0f9659a77931bb08"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cfg_aliases", "cfg_aliases",
"core-graphics", "core-graphics 0.24.0",
"foreign-types 0.5.0", "foreign-types 0.5.0",
"js-sys", "js-sys",
"log", "log",
@@ -5889,7 +5944,7 @@ dependencies = [
"ntapi", "ntapi",
"objc2-core-foundation", "objc2-core-foundation",
"objc2-io-kit", "objc2-io-kit",
"windows 0.59.0", "windows 0.61.3",
] ]
[[package]] [[package]]
@@ -5947,7 +6002,7 @@ checksum = "1e59c1f38e657351a2e822eadf40d6a2ad4627b9c25557bc1180ec1b3295ef82"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"core-foundation 0.10.0", "core-foundation 0.10.0",
"core-graphics", "core-graphics 0.24.0",
"crossbeam-channel", "crossbeam-channel",
"dispatch", "dispatch",
"dlopen2", "dlopen2",
@@ -6145,9 +6200,9 @@ source = "git+https://github.com/ahkohd/tauri-nspanel?branch=v2#d4b9df797959f8fa
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"block", "block",
"cocoa", "cocoa 0.26.0",
"core-foundation 0.10.0", "core-foundation 0.10.0",
"core-graphics", "core-graphics 0.24.0",
"objc", "objc",
"objc-foundation", "objc-foundation",
"objc_id", "objc_id",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "coco" name = "coco"
version = "0.7.0" version = "0.7.1"
description = "Search, connect, collaborate all in one place." description = "Search, connect, collaborate all in one place."
authors = ["INFINI Labs"] authors = ["INFINI Labs"]
edition = "2024" edition = "2024"
@@ -109,6 +109,7 @@ sysinfo = "0.35.2"
[target."cfg(target_os = \"macos\")".dependencies] [target."cfg(target_os = \"macos\")".dependencies]
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" } tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }
cocoa = "0.24"
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies] [target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] } tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }

View File

@@ -180,6 +180,8 @@ pub fn run() {
server::synthesize::synthesize, server::synthesize::synthesize,
util::file::get_file_icon, util::file::get_file_icon,
util::app_lang::update_app_lang, util::app_lang::update_app_lang,
#[cfg(target_os = "macos")]
setup::toggle_move_to_active_space_attribute,
]) ])
.setup(|app| { .setup(|app| {
let app_handle = app.handle().clone(); let app_handle = app.handle().clone();

View File

@@ -1,5 +1,8 @@
//credits to: https://github.com/ayangweb/ayangweb-EcoPaste/blob/169323dbe6365ffe4abb64d867439ed2ea84c6d1/src-tauri/src/core/setup/mac.rs //! credits to: https://github.com/ayangweb/ayangweb-EcoPaste/blob/169323dbe6365ffe4abb64d867439ed2ea84c6d1/src-tauri/src/core/setup/mac.rs
use tauri::{App, Emitter, EventTarget, WebviewWindow};
use cocoa::appkit::NSWindow;
use tauri::Manager;
use tauri::{App, AppHandle, Emitter, EventTarget, WebviewWindow};
use tauri_nspanel::{WebviewWindowExt, cocoa::appkit::NSWindowCollectionBehavior, panel_delegate}; use tauri_nspanel::{WebviewWindowExt, cocoa::appkit::NSWindowCollectionBehavior, panel_delegate};
use crate::common::MAIN_WINDOW_LABEL; use crate::common::MAIN_WINDOW_LABEL;
@@ -29,7 +32,7 @@ pub fn platform(
// Share the window across all desktop spaces and full screen // Share the window across all desktop spaces and full screen
panel.set_collection_behaviour( panel.set_collection_behaviour(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace
| NSWindowCollectionBehavior::NSWindowCollectionBehaviorStationary | NSWindowCollectionBehavior::NSWindowCollectionBehaviorStationary
| NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary, | NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary,
); );
@@ -78,3 +81,50 @@ pub fn platform(
// Set the delegate object for the window to handle window events // Set the delegate object for the window to handle window events
panel.set_delegate(delegate); panel.set_delegate(delegate);
} }
/// Change NS window attribute between `NSWindowCollectionBehaviorCanJoinAllSpaces`
/// and `NSWindowCollectionBehaviorMoveToActiveSpace` accordingly.
///
/// NOTE: this tauri command is not async because we should run it in the main
/// thread, or `ns_window.setCollectionBehavior_(collection_behavior)` would lead
/// to UB.
#[tauri::command]
pub(crate) fn toggle_move_to_active_space_attribute(tauri_app_hanlde: AppHandle) {
use cocoa::appkit::NSWindowCollectionBehavior;
use cocoa::base::id;
let main_window = tauri_app_hanlde
.get_webview_window(MAIN_WINDOW_LABEL)
.unwrap();
let ns_window = main_window.ns_window().unwrap() as id;
let mut collection_behavior = unsafe { ns_window.collectionBehavior() };
let join_all_spaces = collection_behavior
.contains(NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces);
let move_to_active_space = collection_behavior
.contains(NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace);
match (join_all_spaces, move_to_active_space) {
(true, false) => {
collection_behavior
.remove(NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces);
collection_behavior
.insert(NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace);
}
(false, true) => {
collection_behavior
.remove(NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace);
collection_behavior
.insert(NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces);
}
_ => {
panic!(
"invalid NS window attribute, NSWindowCollectionBehaviorCanJoinAllSpaces is set [{}], NSWindowCollectionBehaviorMoveToActiveSpace is set [{}]",
join_all_spaces, move_to_active_space
);
}
}
unsafe {
ns_window.setCollectionBehavior_(collection_behavior);
}
}

View File

@@ -34,4 +34,8 @@ export function show_check(): Promise<void> {
export function hide_check(): Promise<void> { export function hide_check(): Promise<void> {
return invoke('hide_check'); return invoke('hide_check');
}
export function toggle_move_to_active_space_attribute(): Promise<void> {
return invoke('toggle_move_to_active_space_attribute');
} }

View File

@@ -7,12 +7,12 @@ import PinIcon from "@/icons/Pin";
import WindowsFullIcon from "@/icons/WindowsFull"; import WindowsFullIcon from "@/icons/WindowsFull";
import { useAppStore } from "@/stores/appStore"; import { useAppStore } from "@/stores/appStore";
import type { Chat } from "@/types/chat"; import type { Chat } from "@/types/chat";
import platformAdapter from "@/utils/platformAdapter";
import VisibleKey from "../Common/VisibleKey"; import VisibleKey from "../Common/VisibleKey";
import { useShortcutsStore } from "@/stores/shortcutsStore"; import { useShortcutsStore } from "@/stores/shortcutsStore";
import { HISTORY_PANEL_ID } from "@/constants"; import { HISTORY_PANEL_ID } from "@/constants";
import { AssistantList } from "./AssistantList"; import { AssistantList } from "./AssistantList";
import { ServerList } from "./ServerList"; import { ServerList } from "./ServerList";
import { useTogglePin } from "@/hooks/useTogglePin";
interface ChatHeaderProps { interface ChatHeaderProps {
clearChat: () => void; clearChat: () => void;
@@ -35,22 +35,12 @@ export function ChatHeader({
showChatHistory = true, showChatHistory = true,
assistantIDs, assistantIDs,
}: ChatHeaderProps) { }: ChatHeaderProps) {
const { isPinned, setIsPinned, isTauri } = useAppStore(); const { isTauri } = useAppStore();
const { isPinned, togglePin } = useTogglePin();
const { historicalRecords, newSession, fixedWindow, external } = const { historicalRecords, newSession, fixedWindow, external } =
useShortcutsStore(); useShortcutsStore();
const togglePin = async () => {
try {
const newPinned = !isPinned;
await platformAdapter.setAlwaysOnTop(newPinned);
setIsPinned(newPinned);
} catch (err) {
console.error("Failed to toggle window pin state:", err);
setIsPinned(isPinned);
}
};
return ( return (
<header <header
className="flex items-center justify-between py-2 px-3 select-none" className="flex items-center justify-between py-2 px-3 select-none"

View File

@@ -19,6 +19,7 @@ import source_default_dark_img from "@/assets/images/source_default_dark.png";
import { useThemeStore } from "@/stores/themeStore"; import { useThemeStore } from "@/stores/themeStore";
import platformAdapter from "@/utils/platformAdapter"; import platformAdapter from "@/utils/platformAdapter";
import FontIcon from "../Icons/FontIcon"; import FontIcon from "../Icons/FontIcon";
import { useTogglePin } from "@/hooks/useTogglePin";
interface FooterProps { interface FooterProps {
setIsPinnedWeb?: (value: boolean) => void; setIsPinnedWeb?: (value: boolean) => void;
@@ -37,28 +38,16 @@ export default function Footer({ setIsPinnedWeb }: FooterProps) {
const isDark = useThemeStore((state) => state.isDark); const isDark = useThemeStore((state) => state.isDark);
const { isTauri, isPinned, setIsPinned } = useAppStore(); const { isTauri } = useAppStore();
const { isPinned, togglePin } = useTogglePin({
onPinChange: setIsPinnedWeb,
});
const { setVisible, updateInfo } = useUpdateStore(); const { setVisible, updateInfo } = useUpdateStore();
const { fixedWindow, modifierKey } = useShortcutsStore(); const { fixedWindow, modifierKey } = useShortcutsStore();
const setWindowAlwaysOnTop = useCallback(async (isPinned: boolean) => {
setIsPinnedWeb?.(isPinned);
return platformAdapter.setAlwaysOnTop(isPinned);
}, []);
const togglePin = async () => {
try {
const newPinned = !isPinned;
await setWindowAlwaysOnTop(newPinned);
setIsPinned(newPinned);
} catch (err) {
console.error("Failed to toggle window pin state:", err);
setIsPinned(isPinned);
}
};
const openSetting = useCallback(() => { const openSetting = useCallback(() => {
return platformAdapter.emitEvent("open_settings", ""); return platformAdapter.emitEvent("open_settings", "");
}, []); }, []);

View File

@@ -135,12 +135,13 @@ export function useAssistantManager({
} }
if (key === "Enter" && !shiftKey) { if (key === "Enter" && !shiftKey) {
if (!isEmpty(value)) {
e.stopPropagation();
}
e.preventDefault(); e.preventDefault();
if (isTauri && !isChatMode && goAskAi) { if (isTauri && !isChatMode && goAskAi) {
if (!isEmpty(value)) {
e.stopPropagation();
}
return handleAskAi(); return handleAskAi();
} }

35
src/hooks/useTogglePin.ts Normal file
View File

@@ -0,0 +1,35 @@
import { useCallback } from "react";
import { useAppStore } from "@/stores/appStore";
import platformAdapter from "@/utils/platformAdapter";
import { toggle_move_to_active_space_attribute } from "@/commands/system";
import { isMac } from "@/utils/platform";
interface UseTogglePinOptions {
onPinChange?: (isPinned: boolean) => void;
}
export const useTogglePin = (options?: UseTogglePinOptions) => {
const { isPinned, setIsPinned } = useAppStore();
const togglePin = useCallback(async () => {
try {
const newPinned = !isPinned;
if (options?.onPinChange) {
options.onPinChange(newPinned);
}
await platformAdapter.setAlwaysOnTop(newPinned);
setIsPinned(newPinned);
isMac && toggle_move_to_active_space_attribute();
} catch (err) {
console.error("Failed to toggle window pin state:", err);
}
}, [isPinned, setIsPinned, options?.onPinChange]);
return {
isPinned,
togglePin,
};
};