feat: icons & system_tray
@ -1,5 +1,11 @@
|
|||||||
# UPDATE LOG
|
# UPDATE LOG
|
||||||
|
|
||||||
|
## v0.1.4
|
||||||
|
|
||||||
|
feat:
|
||||||
|
- beautify icons
|
||||||
|
- add system tray menu
|
||||||
|
|
||||||
## v0.1.3
|
## v0.1.3
|
||||||
|
|
||||||
fix: only mac supports `TitleBarStyle`
|
fix: only mac supports `TitleBarStyle`
|
||||||
|
BIN
assets/chat.png
Before Width: | Height: | Size: 754 KiB After Width: | Height: | Size: 726 KiB |
Before Width: | Height: | Size: 218 KiB After Width: | Height: | Size: 192 KiB |
BIN
logo.png
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 104 KiB |
@ -1,7 +1,8 @@
|
|||||||
use crate::utils;
|
use crate::utils;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
utils::assets::EmbeddedAssets, AboutMetadata, AppHandle, Context, CustomMenuItem, Manager,
|
utils::assets::EmbeddedAssets, AboutMetadata, AppHandle, Context, CustomMenuItem, Manager,
|
||||||
Menu, MenuItem, Submenu, SystemTrayEvent, WindowMenuEvent,
|
Menu, MenuItem, Submenu, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
|
||||||
|
WindowMenuEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Menu
|
// --- Menu
|
||||||
@ -82,56 +83,35 @@ pub fn init(context: &Context<EmbeddedAssets>) -> Menu {
|
|||||||
pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||||
let win = Some(event.window()).unwrap();
|
let win = Some(event.window()).unwrap();
|
||||||
let app = win.app_handle();
|
let app = win.app_handle();
|
||||||
|
let script_path = utils::script_path().to_string_lossy().to_string();
|
||||||
|
let issues_url = "https://github.com/lencx/ChatGPT/issues".to_string();
|
||||||
|
|
||||||
match event.menu_item_id() {
|
match event.menu_item_id() {
|
||||||
// App
|
// App
|
||||||
"inject_script" => {
|
"inject_script" => inject_script(&app, script_path),
|
||||||
tauri::api::shell::open(
|
|
||||||
&app.shell_scope(),
|
|
||||||
utils::script_path().to_string_lossy(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
// View
|
// View
|
||||||
"go_back" => {
|
"reload" => win.eval("window.location.reload()").unwrap(),
|
||||||
win.eval("window.history.go(-1)").unwrap();
|
"go_back" => win.eval("window.history.go(-1)").unwrap(),
|
||||||
}
|
"go_forward" => win.eval("window.history.go(1)").unwrap(),
|
||||||
"go_forward" => {
|
"scroll_top" => win
|
||||||
win.eval("window.history.go(1)").unwrap();
|
.eval(
|
||||||
}
|
|
||||||
"scroll_top" => {
|
|
||||||
win.eval(
|
|
||||||
r#"window.scroll({
|
r#"window.scroll({
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
behavior: "smooth"
|
behavior: "smooth"
|
||||||
})"#,
|
})"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap(),
|
||||||
}
|
"scroll_bottom" => win
|
||||||
"scroll_bottom" => {
|
.eval(
|
||||||
win.eval(
|
|
||||||
r#"window.scroll({
|
r#"window.scroll({
|
||||||
top: document.body.scrollHeight,
|
top: document.body.scrollHeight,
|
||||||
left: 0,
|
left: 0,
|
||||||
behavior: "smooth",
|
behavior: "smooth"})"#,
|
||||||
})"#,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap(),
|
||||||
}
|
|
||||||
"reload" => {
|
|
||||||
win.eval("window.location.reload()").unwrap();
|
|
||||||
}
|
|
||||||
// Help
|
// Help
|
||||||
"report_bug" => {
|
"report_bug" => inject_script(&app, issues_url),
|
||||||
tauri::api::shell::open(
|
|
||||||
&app.shell_scope(),
|
|
||||||
"https://github.com/lencx/ChatGPT/issues",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
"dev_tools" => {
|
"dev_tools" => {
|
||||||
win.open_devtools();
|
win.open_devtools();
|
||||||
win.close_devtools();
|
win.close_devtools();
|
||||||
@ -140,20 +120,37 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- SystemTray Menu
|
||||||
|
pub fn tray_menu() -> SystemTray {
|
||||||
|
SystemTray::new().with_menu(
|
||||||
|
SystemTrayMenu::new()
|
||||||
|
.add_item(CustomMenuItem::new("show".to_string(), "Show ChatGPT"))
|
||||||
|
.add_item(CustomMenuItem::new("hide".to_string(), "Hide ChatGPT"))
|
||||||
|
.add_item(CustomMenuItem::new(
|
||||||
|
"inject_script".to_string(),
|
||||||
|
"Inject Script",
|
||||||
|
))
|
||||||
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
|
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// --- SystemTray Event
|
// --- SystemTray Event
|
||||||
pub fn tray_handler(app: &AppHandle, event: SystemTrayEvent) {
|
pub fn tray_handler(app: &AppHandle, event: SystemTrayEvent) {
|
||||||
if let SystemTrayEvent::LeftClick {
|
let script_path = utils::script_path().to_string_lossy().to_string();
|
||||||
position: _,
|
|
||||||
size: _,
|
|
||||||
..
|
|
||||||
} = event
|
|
||||||
{
|
|
||||||
let win = app.get_window("core").unwrap();
|
let win = app.get_window("core").unwrap();
|
||||||
if win.is_visible().unwrap() {
|
|
||||||
win.hide().unwrap();
|
if let SystemTrayEvent::MenuItemClick { id, .. } = event {
|
||||||
} else {
|
match id.as_str() {
|
||||||
win.show().unwrap();
|
"quit" => std::process::exit(0),
|
||||||
win.set_focus().unwrap();
|
"show" => win.show().unwrap(),
|
||||||
|
"hide" => win.hide().unwrap(),
|
||||||
|
"inject_script" => inject_script(app, script_path),
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inject_script(app: &AppHandle, path: String) {
|
||||||
|
tauri::api::shell::open(&app.shell_scope(), path, None).unwrap();
|
||||||
|
}
|
||||||
|
@ -7,7 +7,6 @@ mod app;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use app::{cmd, menu, setup};
|
use app::{cmd, menu, setup};
|
||||||
use tauri::SystemTray;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let context = tauri::generate_context!();
|
let context = tauri::generate_context!();
|
||||||
@ -16,7 +15,7 @@ fn main() {
|
|||||||
.invoke_handler(tauri::generate_handler![cmd::drag_window, cmd::fullscreen])
|
.invoke_handler(tauri::generate_handler![cmd::drag_window, cmd::fullscreen])
|
||||||
.setup(setup::init)
|
.setup(setup::init)
|
||||||
.menu(menu::init(&context))
|
.menu(menu::init(&context))
|
||||||
.system_tray(SystemTray::new())
|
.system_tray(menu::tray_menu())
|
||||||
.on_menu_event(menu::menu_handler)
|
.on_menu_event(menu::menu_handler)
|
||||||
.on_system_tray_event(menu::tray_handler)
|
.on_system_tray_event(menu::tray_handler)
|
||||||
.run(context)
|
.run(context)
|
||||||
|