mirror of
https://github.com/lencx/ChatGPT.git
synced 2024-10-01 01:06:13 -04:00
chore: chatgpt prompts & tray menu
This commit is contained in:
parent
1e7c0fe02a
commit
4df09113b5
@ -79,7 +79,7 @@ cask "popcorn-time", args: { "no-quarantine": true }
|
||||
- `Titlebar`: 是否显示 `Titlebar`,仅 macOS 支持
|
||||
- `Inject Script`: 用于修改网站的用户自定义脚本
|
||||
- `Hide Dock Icon` ([#35](https://github.com/lencx/ChatGPT/issues/35)): 隐藏 Dock 中的应用图标 (仅 macOS 支持)
|
||||
- 右键单击系统托盘图标来显示或隐藏在 Dock 里的应用图标
|
||||
- 系统图盘右键单击打开菜单,然后在菜单项中点击 `Show Dock Icon` 可以重新将应用图标显示在 Dock(`SystemTrayMenu -> Show Dock Icon`)
|
||||
- `Control Center`: ChatGPT 应用的控制中心,它将为应用提供无限的可能
|
||||
- 设置 `Theme`,`Stay On Top`,`Titlebar` 等
|
||||
- `User Agent` ([#17](https://github.com/lencx/ChatGPT/issues/17)): 自定义 `user agent` 防止网站安全检测,默认值为空
|
||||
|
@ -79,7 +79,7 @@ In the chatgpt text input area, type a character starting with `/` to bring up t
|
||||
- `Stay On Top`: The window is stay on top of other windows.
|
||||
- `Titlebar`: Whether to display the titlebar, supported by macOS only.
|
||||
- `Hide Dock Icon` ([#35](https://github.com/lencx/ChatGPT/issues/35)): Hide application icons from the Dock(support macOS only).
|
||||
- Right-click on the system tray icon to show or hide the application icons in the Dock
|
||||
- Right-click on the SystemTray to open the menu, then click `Show Dock Icon` in the menu item to re-display the application icon in the Dock (`SystemTrayMenu -> Show Dock Icon`).
|
||||
- `Inject Script`: Using scripts to modify pages.
|
||||
- `Control Center`: The control center of ChatGPT application, it will give unlimited imagination to the application.
|
||||
- `Theme`, `Stay On Top`, `Titlebar`, ...
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 294 KiB After Width: | Height: | Size: 1.1 MiB |
@ -4,7 +4,7 @@ use crate::{
|
||||
};
|
||||
use tauri::{
|
||||
AboutMetadata, AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray,
|
||||
SystemTrayEvent, SystemTrayMenu, WindowMenuEvent,
|
||||
SystemTrayEvent, SystemTrayMenu, WindowMenuEvent, SystemTrayMenuItem,
|
||||
};
|
||||
use tauri_plugin_positioner::{on_tray_event, Position, WindowExt};
|
||||
|
||||
@ -238,13 +238,22 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
|
||||
// --- SystemTray Menu
|
||||
pub fn tray_menu() -> SystemTray {
|
||||
SystemTray::new().with_menu(SystemTrayMenu::new())
|
||||
SystemTray::new().with_menu(
|
||||
SystemTrayMenu::new()
|
||||
.add_item(CustomMenuItem::new("control_center".to_string(), "Control Center"))
|
||||
.add_item(CustomMenuItem::new("show_dock_icon".to_string(), "Show Dock Icon"))
|
||||
.add_item(CustomMenuItem::new("hide_dock_icon".to_string(), "Hide Dock Icon"))
|
||||
.add_native_item(SystemTrayMenuItem::Separator)
|
||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT"))
|
||||
)
|
||||
}
|
||||
|
||||
// --- SystemTray Event
|
||||
pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) {
|
||||
on_tray_event(handle, &event);
|
||||
|
||||
let app = handle.clone();
|
||||
|
||||
match event {
|
||||
SystemTrayEvent::LeftClick { .. } => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
@ -263,36 +272,59 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) {
|
||||
tray_win.show().unwrap();
|
||||
}
|
||||
}
|
||||
SystemTrayEvent::RightClick { .. } => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
let hide_dock = !chat_conf.hide_dock_icon;
|
||||
let title;
|
||||
let msg;
|
||||
|
||||
if !hide_dock {
|
||||
title = "Show Dock Icon";
|
||||
msg = "Are you sure you want to show the ChatGPT icon in the Dock?";
|
||||
} else {
|
||||
title = "Hide Dock Icon";
|
||||
msg = "Are you sure you want to hide the ChatGPT icon in the Dock?";
|
||||
}
|
||||
|
||||
let app = handle.clone();
|
||||
tauri::api::dialog::ask(
|
||||
handle.get_window("tray").as_ref(),
|
||||
title,
|
||||
msg,
|
||||
move |is_ok| {
|
||||
if is_ok {
|
||||
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
|
||||
"control_center" => app.get_window("main").unwrap().show().unwrap(),
|
||||
"restart" => tauri::api::process::restart(&handle.env()),
|
||||
"show_dock_icon" => {
|
||||
ChatConfJson::amend(
|
||||
&serde_json::json!({ "hide_dock_icon": hide_dock }),
|
||||
&serde_json::json!({ "hide_dock_icon": false }),
|
||||
Some(app),
|
||||
)
|
||||
.unwrap();
|
||||
},
|
||||
"hide_dock_icon" => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
if !chat_conf.hide_dock_icon {
|
||||
ChatConfJson::amend(
|
||||
&serde_json::json!({ "hide_dock_icon": true }),
|
||||
Some(app),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
},
|
||||
);
|
||||
"quit" => std::process::exit(0),
|
||||
_ => (),
|
||||
}
|
||||
// SystemTrayEvent::RightClick { tray_id, .. } => {
|
||||
// let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
// let hide_dock = !chat_conf.hide_dock_icon;
|
||||
// let title;
|
||||
// let msg;
|
||||
|
||||
// if !hide_dock {
|
||||
// title = "Show Dock Icon";
|
||||
// msg = "Are you sure you want to show the ChatGPT icon in the Dock?";
|
||||
// } else {
|
||||
// title = "Hide Dock Icon";
|
||||
// msg = "Are you sure you want to hide the ChatGPT icon in the Dock?";
|
||||
// }
|
||||
|
||||
// let app = handle.clone();
|
||||
// tauri::api::dialog::ask(
|
||||
// handle.get_window("tray").as_ref(),
|
||||
// title,
|
||||
// msg,
|
||||
// move |is_ok| {
|
||||
// if is_ok {
|
||||
// ChatConfJson::amend(
|
||||
// &serde_json::json!({ "hide_dock_icon": hide_dock }),
|
||||
// Some(app),
|
||||
// )
|
||||
// .unwrap();
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
73
src-tauri/src/assets/cmd.js
vendored
73
src-tauri/src/assets/cmd.js
vendored
@ -66,29 +66,65 @@ async function cmdTip() {
|
||||
const itemDom = (v) => `<div class="cmd-item" data-prompt="${encodeURIComponent(v.prompt)}"><b>/${v.cmd}</b><i>${v.act}</i></div>`;
|
||||
const searchInput = document.querySelector('form textarea');
|
||||
|
||||
searchInput.addEventListener('input', debounce(function() {
|
||||
const query = this.value;
|
||||
console.log(query);
|
||||
// const handle = debounce(function() {
|
||||
// console.log('«70» /src/assets/cmd.js ~> ', 5667);
|
||||
|
||||
// const query = this.value;
|
||||
// console.log(query);
|
||||
// if (!query || !/^\//.test(query)) {
|
||||
// modelDom.innerHTML = '';
|
||||
// return;
|
||||
// }
|
||||
// const result = data.filter(i => i.enable && new RegExp(query.substring(1)).test(i.cmd));
|
||||
// if (result.length > 0) {
|
||||
// modelDom.innerHTML = `<div>${result.map(itemDom).join('')}</div>`;
|
||||
// }
|
||||
// }, 250);
|
||||
|
||||
|
||||
// Enter a command starting with `/` and press a space to automatically fill `chatgpt prompt`.
|
||||
// If more than one command appears in the search results, the first one will be used by default.
|
||||
searchInput.addEventListener('keydown', (event) => {
|
||||
if (!window.__CHAT_MODEL_CMD__) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.keyCode === 32) {
|
||||
searchInput.value = window.__CHAT_MODEL_CMD__;
|
||||
modelDom.innerHTML = '';
|
||||
delete window.__CHAT_MODEL_CMD__;
|
||||
}
|
||||
if (event.keyCode === 13) {
|
||||
modelDom.innerHTML = '';
|
||||
delete window.__CHAT_MODEL_CMD__;
|
||||
}
|
||||
});
|
||||
|
||||
searchInput.addEventListener('input', (event) => {
|
||||
const query = searchInput.value;
|
||||
// console.log(query);
|
||||
if (!query || !/^\//.test(query)) {
|
||||
modelDom.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// all cmd result
|
||||
if (query === '/') {
|
||||
const result = data.filter(i => i.enable);
|
||||
modelDom.innerHTML = `<div>${result.map(itemDom).join('')}</div>`;
|
||||
window.__CHAT_MODEL_CMD__ = result[0]?.prompt.trim();
|
||||
return;
|
||||
}
|
||||
|
||||
const result = data.filter(i => i.enable && new RegExp(query.substring(1)).test(i.cmd));
|
||||
if (result.length > 0) {
|
||||
modelDom.innerHTML = `<div>${result.map(itemDom).join('')}</div>`;
|
||||
}
|
||||
// Enter a command starting with `/` and press a space to automatically fill `chatgpt prompt`.
|
||||
// If more than one command appears in the search results, the first one will be used by default.
|
||||
searchInput.addEventListener('keydown', (event) => {
|
||||
if (event.keyCode === 32) {
|
||||
searchInput.value = result[0]?.prompt.trim();
|
||||
}
|
||||
if (event.keyCode = 13) {
|
||||
window.__CHAT_MODEL_CMD__ = result[0]?.prompt.trim();
|
||||
} else {
|
||||
modelDom.innerHTML = '';
|
||||
delete window.__CHAT_MODEL_CMD__;
|
||||
}
|
||||
});
|
||||
}, 250),
|
||||
{
|
||||
}, {
|
||||
capture: false,
|
||||
passive: true,
|
||||
once: false
|
||||
@ -105,9 +141,16 @@ async function cmdTip() {
|
||||
// .cmd-item
|
||||
const item = event.target.closest("div");
|
||||
if (item) {
|
||||
document.querySelector('form textarea').value = decodeURIComponent(item.getAttribute('data-prompt'));
|
||||
const val = decodeURIComponent(item.getAttribute('data-prompt'));
|
||||
searchInput.value = val;
|
||||
document.querySelector('form textarea').focus();
|
||||
window.__CHAT_MODEL_CMD__ = val;
|
||||
modelDom.innerHTML = '';
|
||||
}
|
||||
}, {
|
||||
capture: false,
|
||||
passive: true,
|
||||
once: false
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
|
@ -19,7 +19,8 @@
|
||||
},
|
||||
"systemTray": {
|
||||
"iconPath": "icons/tray-icon.png",
|
||||
"iconAsTemplate": true
|
||||
"iconAsTemplate": true,
|
||||
"menuOnLeftClick": false
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
|
Loading…
Reference in New Issue
Block a user