Skip to content

Commit

Permalink
feat: add hotkey hook (#101)
Browse files Browse the repository at this point in the history
* feat: add hotkey hook

* chore: debug shortcut keys

* chore: shortcut key echo

* chore: add number key

* chore: remove log

* build: build config
  • Loading branch information
RainyNight9 authored Jan 15, 2025
1 parent 9279e46 commit 711f7cf
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 272 deletions.
16 changes: 14 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ fn change_shortcut<R: Runtime>(

let main_window = app.get_webview_window("main").unwrap();

if key.trim().is_empty() {
let path = app.path().app_config_dir().unwrap();
if !path.exists() {
create_dir(&path).unwrap();
}

let file_path = path.join("shortcut.txt");
let mut file = File::create(file_path).unwrap();
file.write_all(b"").unwrap();
return Ok(());
}

let shortcut: Shortcut = key
.parse()
.map_err(|_| "The format of the shortcut key is incorrect".to_owned())?;
Expand Down Expand Up @@ -364,12 +376,12 @@ fn enable_tray(app: &mut tauri::App) {
let settings_i = MenuItem::with_id(app, "settings", "Settings...", true, None::<&str>).unwrap();
let open_i = MenuItem::with_id(app, "open", "Open Coco", true, None::<&str>).unwrap();
let about_i = MenuItem::with_id(app, "about", "About Coco", true, None::<&str>).unwrap();
let hide_i = MenuItem::with_id(app, "hide", "Hide Coco", true, None::<&str>).unwrap();
// let hide_i = MenuItem::with_id(app, "hide", "Hide Coco", true, None::<&str>).unwrap();

let menu = MenuBuilder::new(app)
.item(&open_i)
.separator()
.item(&hide_i)
// .item(&hide_i)
.item(&about_i)
.item(&settings_i)
.separator()
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"maximizable": false,
"skipTaskbar": true,
"resizable": false,
"shadow": false,
"shadow": true,
"transparent": true,
"fullscreen": false,
"center": false,
Expand Down
11 changes: 6 additions & 5 deletions src/components/AppAI/DropdownList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEffect, useRef, useState } from "react";
import { CircleAlert, Bolt, X } from "lucide-react";

import { isTauri } from "@tauri-apps/api/core";
import { open } from "@tauri-apps/plugin-shell";

import { useAppStore } from "@/stores/appStore";

interface DropdownListProps {
Expand All @@ -24,7 +25,6 @@ function DropdownList({ selected, suggests, IsError }: DropdownListProps) {
if (!url) return;
try {
if (isTauri()) {
const { open } = await import("@tauri-apps/plugin-shell");
await open(url);
console.log("URL opened in default browser");
}
Expand Down Expand Up @@ -107,10 +107,11 @@ function DropdownList({ selected, suggests, IsError }: DropdownListProps) {
}, [selectedItem]);

function getIcon(_source: any) {
const name = _source?.source?.name || ""
const result = connector_data.find((item: any) => item._source.category === name);
const name = _source?.source?.name || "";
const result = connector_data.find(
(item: any) => item._source.category === name
);
const icons = result?._source?.assets?.icons || {};
console.log(11111, icons,name, _source.icon, icons[_source.icon])
return icons[_source.icon] || _source.icon;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchChat/DropdownList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { isTauri } from "@tauri-apps/api/core";
import { open } from "@tauri-apps/plugin-shell";

interface DropdownListProps {
selected: (item: any) => void;
Expand All @@ -17,7 +18,6 @@ function DropdownList({ selected, suggests }: DropdownListProps) {
if (!url) return;
try {
if (isTauri()) {
const { open } = await import("@tauri-apps/plugin-shell");
await open(url);
console.log("URL opened in default browser");
}
Expand Down
7 changes: 2 additions & 5 deletions src/components/SearchChat/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect, useState, useCallback, useRef } from "react";
import { isTauri } from "@tauri-apps/api/core";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { LogicalSize } from "@tauri-apps/api/dpi";

import DropdownList from "./DropdownList";
import { Footer } from "./Footer";
Expand Down Expand Up @@ -32,11 +34,6 @@ function Search({ isTransitioned, isChatMode, input }: SearchProps) {
if (!element) return;

const resizeObserver = new ResizeObserver(async (entries) => {
const { getCurrentWebviewWindow } = await import(
"@tauri-apps/api/webviewWindow"
);
const { LogicalSize } = await import("@tauri-apps/api/dpi");

for (let entry of entries) {
let newHeight = entry.contentRect.height;
console.log("Height updated:", newHeight);
Expand Down
11 changes: 2 additions & 9 deletions src/components/SearchChat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect, useState, useRef } from "react";
import { isTauri } from "@tauri-apps/api/core";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { LogicalSize } from "@tauri-apps/api/dpi";

// import { Window, LogicalPosition } from "@tauri-apps/api/window";
// import { currentMonitor } from "@tauri-apps/plugin-window";
Expand Down Expand Up @@ -62,10 +64,6 @@ export default function SearchChat() {

async function setWindowSize() {
if (isTauri() && !isTransitioned) {
const { getCurrentWebviewWindow } = await import(
"@tauri-apps/api/webviewWindow"
);
const { LogicalSize } = await import("@tauri-apps/api/dpi");
await getCurrentWebviewWindow()?.setSize(new LogicalSize(680, 90));
}
}
Expand All @@ -89,11 +87,6 @@ export default function SearchChat() {
setInput(value);
if (isChatMode) {
if (isTauri()) {
const { getCurrentWebviewWindow } = await import(
"@tauri-apps/api/webviewWindow"
);
const { LogicalSize } = await import("@tauri-apps/api/dpi");

await getCurrentWebviewWindow()?.setSize(new LogicalSize(680, 596));
}
setIsTransitioned(true);
Expand Down
Loading

0 comments on commit 711f7cf

Please # to comment.