From 171ac94f77172e3c730659df7c29560bef57fa57 Mon Sep 17 00:00:00 2001 From: lencx Date: Mon, 30 Jan 2023 23:55:43 +0800 Subject: [PATCH] chore: optim --- AWESOME.md | 26 ------------- UPDATE_LOG.md | 6 +++ chat.model.md | 3 -- src-tauri/src/app/menu.rs | 74 ++++++++++++++++++++++--------------- src-tauri/src/app/setup.rs | 2 + src-tauri/src/app/window.rs | 17 ++++----- src-tauri/src/conf.rs | 2 +- src-tauri/src/main.rs | 1 + src-tauri/src/utils.rs | 38 +++++++++---------- 9 files changed, 81 insertions(+), 88 deletions(-) delete mode 100644 AWESOME.md delete mode 100644 chat.model.md diff --git a/AWESOME.md b/AWESOME.md deleted file mode 100644 index 9f1d3a117..000000000 --- a/AWESOME.md +++ /dev/null @@ -1,26 +0,0 @@ -# Awesome ChatGPT - -- [Awesome ChatGPT Prompts](https://github.com/f/awesome-chatgpt-prompts) - This repo includes ChatGPT prompt curation to use ChatGPT better. -- [Awesome ChatGPT](https://github.com/humanloop/awesome-chatgpt) - Curated list of awesome tools, demos, docs for ChatGPT and GPT-3 - -## Extension - -`Browser` - -- [ChatGPT Export and Share](https://github.com/liady/ChatGPT-pdf) - A Chrome extension for downloading your ChatGPT history to PNG, PDF or creating a sharable link -- [ChatGPT for Google](https://github.com/wong2/chat-gpt-google-extension) - A browser extension to display ChatGPT response alongside Google Search results -- [ChatGPT Extension](https://github.com/kazuki-sf/ChatGPT_Extension) - ChatGPT Extension is a really simple Chrome Extension (manifest v3) that you can access OpenAI's ChatGPT from anywhere on the web. -- [ChatGPT-Google](https://github.com/ZohaibAhmed/ChatGPT-Google) - Chrome Extension that Integrates ChatGPT (Unofficial) into Google Search - -`VSCode` - -- [ChatGPT Extension for VSCode](https://github.com/mpociot/chatgpt-vscode) - A VSCode extension that allows you to use ChatGPT - -`Bot` - -- [ChatGPT Telegram Bot](https://github.com/altryne/chatGPT-telegram-bot) - This is a very early attempt at having chatGPT work within a telegram bot - -## Tools - -- [commitgpt](https://github.com/RomanHotsiy/commitgpt) - Automatically generate commit messages using ChatGPT -- [ShareGPT](https://sharegpt.com/) - ShareGPT: Share your wildest ChatGPT conversations with one click. diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index affbc859c..0f28507d1 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,11 @@ # UPDATE LOG +## v0.10.2 + +Fix: + +- PNG and PDF buttons do not work (https://github.com/lencx/ChatGPT/issues/274) + ## v0.10.1 Fix: diff --git a/chat.model.md b/chat.model.md deleted file mode 100644 index 9a80fc841..000000000 --- a/chat.model.md +++ /dev/null @@ -1,3 +0,0 @@ -# ChatGPT Model - -- [Awesome ChatGPT Prompts](https://github.com/f/awesome-chatgpt-prompts) diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 2b41c478c..0e3aac819 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -81,6 +81,7 @@ pub fn init() -> Menu { CustomMenuItem::new("control_center".to_string(), "Control Center") .accelerator("CmdOrCtrl+Shift+P") .into(), + CustomMenuItem::new("app_website".to_string(), "ChatGPT User's Guide").into(), MenuItem::Separator.into(), stay_on_top_menu.into(), #[cfg(target_os = "macos")] @@ -143,7 +144,6 @@ pub fn init() -> Menu { .into(), CustomMenuItem::new("clear_conf".to_string(), "Clear Config").into(), MenuItem::Separator.into(), - CustomMenuItem::new("awesome".to_string(), "Awesome ChatGPT").into(), CustomMenuItem::new("buy_coffee".to_string(), "Buy lencx a coffee").into(), ]), ); @@ -247,7 +247,13 @@ pub fn menu_handler(event: WindowMenuEvent) { "inject_script" => open(&app, script_path), "go_conf" => utils::open_file(utils::app_root()), "clear_conf" => utils::clear_conf(&app), - "awesome" => open(&app, conf::AWESOME_URL.to_string()), + "app_website" => window::cmd::wa_window( + app, + "app_website".into(), + "ChatGPT User's Guide".into(), + conf::APP_WEBSITE.into(), + None, + ), "buy_coffee" => open(&app, conf::BUY_COFFEE.to_string()), "popup_search" => { let app_conf = AppConf::read(); @@ -396,22 +402,29 @@ pub fn menu_handler(event: WindowMenuEvent) { // --- SystemTray Menu pub fn tray_menu() -> SystemTray { if cfg!(target_os = "macos") { - SystemTray::new().with_menu( - SystemTrayMenu::new() - .add_item(CustomMenuItem::new( - "control_center".to_string(), - "Control Center", - )) - .add_native_item(SystemTrayMenuItem::Separator) - .add_item(CustomMenuItem::new( - "show_dock_icon".to_string(), - "Show Dock Icon", - )) + let mut tray_menu = SystemTrayMenu::new() + .add_item(CustomMenuItem::new( + "control_center".to_string(), + "Control Center", + )) + .add_native_item(SystemTrayMenuItem::Separator); + + if AppConf::read().hide_dock_icon { + tray_menu = tray_menu.add_item(CustomMenuItem::new( + "show_dock_icon".to_string(), + "Show Dock Icon", + )); + } else { + tray_menu = tray_menu .add_item(CustomMenuItem::new( "hide_dock_icon".to_string(), "Hide Dock Icon", )) - .add_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT")) + .add_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT")); + } + + SystemTray::new().with_menu( + tray_menu .add_native_item(SystemTrayMenuItem::Separator) .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), ) @@ -440,17 +453,19 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) { let app_conf = AppConf::read(); if !app_conf.hide_dock_icon { - let core_win = handle.get_window("core").unwrap(); - core_win.minimize().unwrap(); + if let Some(core_win) = handle.get_window("core") { + core_win.minimize().unwrap(); + } } - let tray_win = handle.get_window("tray").unwrap(); - tray_win.move_window(Position::TrayCenter).unwrap(); + if let Some(tray_win) = handle.get_window("tray") { + tray_win.move_window(Position::TrayCenter).unwrap(); - if tray_win.is_visible().unwrap() { - tray_win.hide().unwrap(); - } else { - tray_win.show().unwrap(); + if tray_win.is_visible().unwrap() { + tray_win.hide().unwrap(); + } else { + tray_win.show().unwrap(); + } } } SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { @@ -472,13 +487,14 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) { } } "show_core" => { - let core_win = app.get_window("core").unwrap(); - let tray_win = app.get_window("tray").unwrap(); - if !core_win.is_visible().unwrap() { - core_win.show().unwrap(); - core_win.set_focus().unwrap(); - tray_win.hide().unwrap(); - } + if let Some(core_win) = app.get_window("core") { + let tray_win = app.get_window("tray").unwrap(); + if !core_win.is_visible().unwrap() { + core_win.show().unwrap(); + core_win.set_focus().unwrap(); + tray_win.hide().unwrap(); + } + }; } "quit" => std::process::exit(0), _ => (), diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index 8ed87cf37..6f9a16bac 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -11,6 +11,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box let handle = app.app_handle(); tauri::async_runtime::spawn(async move { + info!("stepup_tray"); window::tray_window(&handle); }); @@ -56,6 +57,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box } else { &url }; + info!("main_window: {}", link); let mut main_win = WindowBuilder::new(&app, "core", WindowUrl::App(link.into())) .title("ChatGPT") .resizable(true) diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index b03e805ca..ee3c39865 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -130,7 +130,7 @@ pub mod cmd { } #[command] - pub async fn wa_window( + pub fn wa_window( app: tauri::AppHandle, label: String, title: String, @@ -148,16 +148,13 @@ pub mod cmd { .build() .unwrap(); }); - } else { - if !win.clone().unwrap().is_visible().unwrap() { - win.clone().unwrap().show().unwrap(); + } + if let Some(v) = win { + if !v.is_visible().unwrap() { + v.show().unwrap(); } - win - .clone() - .unwrap() - .eval("window.location.reload()") - .unwrap(); - win.unwrap().set_focus().unwrap(); + v.eval("window.location.reload()").unwrap(); + v.set_focus().unwrap(); } } diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index 97bf20263..99349d297 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -8,9 +8,9 @@ use tauri::TitleBarStyle; use crate::utils::{app_root, create_file, exists}; +pub const APP_WEBSITE: &str = "https://lencx.github.io/app/"; pub const ISSUES_URL: &str = "https://github.com/lencx/ChatGPT/issues"; pub const UPDATE_LOG_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/UPDATE_LOG.md"; -pub const AWESOME_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/AWESOME.md"; pub const BUY_COFFEE: &str = "https://www.buymeacoffee.com/lencx"; pub const GITHUB_PROMPTS_CSV_URL: &str = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 01c042f37..74590ccc3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,6 +9,7 @@ mod utils; use app::{cmd, fs_extra, gpt, menu, setup, window}; use conf::AppConf; +use log::info; use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_log::{ fern::colors::{Color, ColoredLevelConfig}, diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index bb03d9aff..d37f03383 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -156,25 +156,25 @@ pub async fn get_data( pub fn run_check_update(app: AppHandle, silent: bool, has_msg: Option) { info!("run_check_update: silent={} has_msg={:?}", silent, has_msg); tauri::async_runtime::spawn(async move { - let result = app.updater().check().await; - let update_resp = result.unwrap(); - if update_resp.is_update_available() { - if silent { - tauri::async_runtime::spawn(async move { - silent_install(app, update_resp).await.unwrap(); - }); - } else { - tauri::async_runtime::spawn(async move { - prompt_for_install(app, update_resp).await.unwrap(); - }); - } - } else if let Some(v) = has_msg { - if v { - tauri::api::dialog::message( - app.app_handle().get_window("core").as_ref(), - "ChatGPT", - "Your ChatGPT is up to date", - ); + if let Ok(update_resp) = app.updater().check().await { + if update_resp.is_update_available() { + if silent { + tauri::async_runtime::spawn(async move { + silent_install(app, update_resp).await.unwrap(); + }); + } else { + tauri::async_runtime::spawn(async move { + prompt_for_install(app, update_resp).await.unwrap(); + }); + } + } else if let Some(v) = has_msg { + if v { + tauri::api::dialog::message( + app.app_handle().get_window("core").as_ref(), + "ChatGPT", + "Your ChatGPT is up to date", + ); + } } } });