Skip to content

Commit

Permalink
chore: optim
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Jan 30, 2023
1 parent ffef57e commit 171ac94
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 88 deletions.
26 changes: 0 additions & 26 deletions AWESOME.md

This file was deleted.

6 changes: 6 additions & 0 deletions UPDATE_LOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 0 additions & 3 deletions chat.model.md

This file was deleted.

74 changes: 45 additions & 29 deletions src-tauri/src/app/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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(),
]),
);
Expand Down Expand Up @@ -247,7 +247,13 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
"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();
Expand Down Expand Up @@ -396,22 +402,29 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
// --- 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")),
)
Expand Down Expand Up @@ -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() {
Expand All @@ -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),
_ => (),
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/app/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
let handle = app.app_handle();

tauri::async_runtime::spawn(async move {
info!("stepup_tray");
window::tray_window(&handle);
});

Expand Down Expand Up @@ -56,6 +57,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
} else {
&url
};
info!("main_window: {}", link);
let mut main_win = WindowBuilder::new(&app, "core", WindowUrl::App(link.into()))
.title("ChatGPT")
.resizable(true)
Expand Down
17 changes: 7 additions & 10 deletions src-tauri/src/app/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub mod cmd {
}

#[command]
pub async fn wa_window(
pub fn wa_window(
app: tauri::AppHandle,
label: String,
title: String,
Expand All @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
38 changes: 19 additions & 19 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,25 @@ pub async fn get_data(
pub fn run_check_update(app: AppHandle<Wry>, silent: bool, has_msg: Option<bool>) {
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",
);
}
}
}
});
Expand Down

0 comments on commit 171ac94

Please sign in to comment.