feat: export history

This commit is contained in:
lencx
2022-12-10 03:23:29 +08:00
parent b4d764abbe
commit 7f480b4943
12 changed files with 265 additions and 104 deletions

View File

@@ -1,8 +1,15 @@
use anyhow::Result;
use std::fs::{self, File};
use std::path::{Path, PathBuf};
use std::{
fs::{self, File},
path::{Path, PathBuf},
process::Command,
};
use tauri::utils::config::Config;
pub fn chat_root() -> PathBuf {
tauri::api::path::home_dir().unwrap().join(".chatgpt")
}
pub fn get_tauri_conf() -> Option<Config> {
let config_file = include_str!("../tauri.conf.json");
let config: Config =
@@ -22,8 +29,7 @@ pub fn create_file(path: &Path) -> Result<File> {
}
pub fn script_path() -> PathBuf {
let root = tauri::api::path::home_dir().unwrap().join(".chatgpt");
let script_file = root.join("main.js");
let script_file = chat_root().join("main.js");
if !exists(&script_file) {
create_file(&script_file).unwrap();
fs::write(&script_file, format!("// *** ChatGPT User Script ***\n// @github: https://github.com/lencx/ChatGPT \n// @path: {}\n\nconsole.log('🤩 Hello ChatGPT!!!');", &script_file.to_string_lossy())).unwrap();
@@ -39,3 +45,19 @@ pub fn user_script() -> String {
user_script_content
)
}
pub fn open_file(path: PathBuf) {
#[cfg(target_os = "macos")]
Command::new("open").arg("-R").arg(path).spawn().unwrap();
#[cfg(target_os = "windows")]
Command::new("explorer")
.arg("/select,")
.arg(path)
.spawn()
.unwrap();
// https://askubuntu.com/a/31071
#[cfg(target_os = "linux")]
Command::new("xdg-open").arg(path).spawn().unwrap();
}