-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
main.rs
134 lines (124 loc) 路 3.68 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
mod app;
mod conf;
mod utils;
use app::{cmd, fs_extra, gpt, menu, script, setup, window};
use conf::AppConf;
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_log::{
fern::colors::{Color, ColoredLevelConfig},
LogTarget,
};
#[tokio::main]
async fn main() {
let app_conf = AppConf::read().write();
// If the file does not exist, creating the file will block menu synchronization
utils::create_chatgpt_prompts();
let context = tauri::generate_context!();
gpt::download_list("chat.download.json", "download", None, None);
gpt::download_list("chat.notes.json", "notes", None, None);
let mut log = tauri_plugin_log::Builder::default()
.targets([
// LogTarget::LogDir,
// LOG PATH: ~/.chatgpt/ChatGPT.log
LogTarget::Folder(utils::app_root()),
LogTarget::Stdout,
LogTarget::Webview,
])
.level(log::LevelFilter::Debug);
if cfg!(debug_assertions) {
log = log.with_colors(ColoredLevelConfig {
error: Color::Red,
warn: Color::Yellow,
debug: Color::Blue,
info: Color::BrightGreen,
trace: Color::Cyan,
});
}
let mut builder = tauri::Builder::default()
.plugin(log.build())
.plugin(tauri_plugin_positioner::init())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
None,
))
.invoke_handler(tauri::generate_handler![
cmd::drag_window,
cmd::fullscreen,
cmd::save_file,
cmd::open_link,
cmd::run_check_update,
cmd::open_file,
cmd::download_file,
cmd::get_data,
cmd::fetch_image,
gpt::get_chat_prompt_cmd,
gpt::parse_prompt,
gpt::sync_prompts,
gpt::sync_user_prompts,
gpt::cmd_list,
gpt::download_list,
gpt::get_download_list,
fs_extra::metadata,
conf::cmd::get_app_conf,
conf::cmd::reset_app_conf,
conf::cmd::get_theme,
conf::cmd::form_confirm,
conf::cmd::form_cancel,
conf::cmd::form_msg,
script::cmd::sync_scripts,
script::cmd::get_script_info,
window::cmd::wa_window,
window::cmd::control_window,
window::cmd::window_reload,
window::cmd::dalle2_search_window,
])
.setup(setup::init)
.menu(menu::init());
if app_conf.tray {
builder = builder.system_tray(menu::tray_menu());
}
if app_conf.save_window_state {
builder = builder.plugin(tauri_plugin_window_state::Builder::default().build());
}
builder
.on_menu_event(menu::menu_handler)
.on_system_tray_event(menu::tray_handler)
.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() {
let win = event.window().clone();
let app_conf = AppConf::read();
if win.label() == "core" {
if app_conf.isinit {
tauri::api::dialog::ask(
Some(event.window()),
"",
"Do you want to exit the application when you click the [x] button?",
move |is_ok| {
app_conf
.amend(serde_json::json!({ "isinit" : false, "main_close": is_ok }))
.write();
if is_ok {
std::process::exit(0);
} else {
win.minimize().unwrap();
}
},
);
} else if app_conf.main_close {
std::process::exit(0);
} else {
win.minimize().unwrap();
}
} else {
event.window().close().unwrap();
}
api.prevent_close();
}
})
.run(context)
.expect("error while running ChatGPT application");
}