mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
feat: add menu item
This commit is contained in:
10
package.json
10
package.json
@@ -12,7 +12,15 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "lencx <cxin1314@gmail.com>",
|
"author": "lencx <cxin1314@gmail.com>",
|
||||||
"keywords": ["chatgpt", "app", "desktop", "tauri", "macos", "linux", "windows"],
|
"keywords": [
|
||||||
|
"chatgpt",
|
||||||
|
"app",
|
||||||
|
"desktop",
|
||||||
|
"tauri",
|
||||||
|
"macos",
|
||||||
|
"linux",
|
||||||
|
"windows"
|
||||||
|
],
|
||||||
"homepage": "https://github.com/lencx/ChatGPT",
|
"homepage": "https://github.com/lencx/ChatGPT",
|
||||||
"bugs": "https://github.com/lencx/ChatGPT/issues",
|
"bugs": "https://github.com/lencx/ChatGPT/issues",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
app::window,
|
||||||
conf::{self, ChatConfJson},
|
conf::{self, ChatConfJson},
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
@@ -69,6 +70,9 @@ pub fn init(chat_conf: &conf::ChatConfJson, context: &Context<EmbeddedAssets>) -
|
|||||||
always_on_top_menu.into(),
|
always_on_top_menu.into(),
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
titlebar_menu.into(),
|
titlebar_menu.into(),
|
||||||
|
CustomMenuItem::new("switch_origin".to_string(), "Switch Origin")
|
||||||
|
.accelerator("CmdOrCtrl+O")
|
||||||
|
.into(),
|
||||||
CustomMenuItem::new("inject_script".to_string(), "Inject Script")
|
CustomMenuItem::new("inject_script".to_string(), "Inject Script")
|
||||||
.accelerator("CmdOrCtrl+J")
|
.accelerator("CmdOrCtrl+J")
|
||||||
.into(),
|
.into(),
|
||||||
@@ -152,6 +156,10 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
// Preferences
|
// Preferences
|
||||||
"inject_script" => open(&app, script_path),
|
"inject_script" => open(&app, script_path),
|
||||||
"awesome" => open(&app, conf::AWESOME_URL.to_string()),
|
"awesome" => open(&app, conf::AWESOME_URL.to_string()),
|
||||||
|
"switch_origin" => {
|
||||||
|
window::origin_window(&app);
|
||||||
|
// app.get_window("origin").unwrap().show();
|
||||||
|
}
|
||||||
"titlebar" => {
|
"titlebar" => {
|
||||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
ChatConfJson::amend(&serde_json::json!({ "titlebar": !chat_conf.titlebar })).unwrap();
|
ChatConfJson::amend(&serde_json::json!({ "titlebar": !chat_conf.titlebar })).unwrap();
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
use crate::{app::window, conf, utils};
|
use crate::{
|
||||||
|
app::window,
|
||||||
|
conf::{ChatConfJson, USER_AGENT},
|
||||||
|
utils,
|
||||||
|
};
|
||||||
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, Manager};
|
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, Manager};
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
app: &mut App,
|
app: &mut App,
|
||||||
chat_conf: conf::ChatConfJson,
|
chat_conf: ChatConfJson,
|
||||||
) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
let tauri_conf = utils::get_tauri_conf().unwrap();
|
let url = chat_conf.origin.to_string();
|
||||||
let url = tauri_conf.build.dev_path.to_string();
|
let theme = ChatConfJson::theme();
|
||||||
let theme = conf::ChatConfJson::theme();
|
|
||||||
window::mini_window(&app.app_handle());
|
window::mini_window(&app.app_handle());
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@@ -18,13 +21,13 @@ pub fn init(
|
|||||||
.hidden_title(true)
|
.hidden_title(true)
|
||||||
.theme(theme)
|
.theme(theme)
|
||||||
.always_on_top(chat_conf.always_on_top)
|
.always_on_top(chat_conf.always_on_top)
|
||||||
.title_bar_style(conf::ChatConfJson::titlebar())
|
.title_bar_style(ChatConfJson::titlebar())
|
||||||
.initialization_script(&utils::user_script())
|
.initialization_script(&utils::user_script())
|
||||||
.initialization_script(include_str!("../assets/html2canvas.js"))
|
.initialization_script(include_str!("../assets/html2canvas.js"))
|
||||||
.initialization_script(include_str!("../assets/jspdf.js"))
|
.initialization_script(include_str!("../assets/jspdf.js"))
|
||||||
.initialization_script(include_str!("../assets/core.js"))
|
.initialization_script(include_str!("../assets/core.js"))
|
||||||
.initialization_script(include_str!("../assets/export.js"))
|
.initialization_script(include_str!("../assets/export.js"))
|
||||||
.user_agent(conf::USER_AGENT)
|
.user_agent(USER_AGENT)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
@@ -40,7 +43,7 @@ pub fn init(
|
|||||||
.initialization_script(include_str!("../assets/jspdf.js"))
|
.initialization_script(include_str!("../assets/jspdf.js"))
|
||||||
.initialization_script(include_str!("../assets/core.js"))
|
.initialization_script(include_str!("../assets/core.js"))
|
||||||
.initialization_script(include_str!("../assets/export.js"))
|
.initialization_script(include_str!("../assets/export.js"))
|
||||||
.user_agent(conf::USER_AGENT)
|
.user_agent(USER_AGENT)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ use crate::{conf, utils};
|
|||||||
use tauri::{utils::config::WindowUrl, window::WindowBuilder};
|
use tauri::{utils::config::WindowUrl, window::WindowBuilder};
|
||||||
|
|
||||||
pub fn mini_window(handle: &tauri::AppHandle) {
|
pub fn mini_window(handle: &tauri::AppHandle) {
|
||||||
let tauri_conf = utils::get_tauri_conf().unwrap();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
let url = tauri_conf.build.dev_path.to_string();
|
|
||||||
// let chat_conf = conf::ChatConfJson::get_chat_conf();
|
|
||||||
let theme = conf::ChatConfJson::theme();
|
let theme = conf::ChatConfJson::theme();
|
||||||
|
|
||||||
WindowBuilder::new(handle, "mini", WindowUrl::App(url.into()))
|
WindowBuilder::new(handle, "mini", WindowUrl::App(chat_conf.origin.into()))
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.fullscreen(false)
|
.fullscreen(false)
|
||||||
.inner_size(360.0, 540.0)
|
.inner_size(360.0, 540.0)
|
||||||
@@ -25,3 +23,16 @@ pub fn mini_window(handle: &tauri::AppHandle) {
|
|||||||
.hide()
|
.hide()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn origin_window(handle: &tauri::AppHandle) {
|
||||||
|
let theme = conf::ChatConfJson::theme();
|
||||||
|
|
||||||
|
WindowBuilder::new(handle, "main", WindowUrl::External("/".parse().unwrap()))
|
||||||
|
.resizable(false)
|
||||||
|
.fullscreen(false)
|
||||||
|
.inner_size(400.0, 300.0)
|
||||||
|
.always_on_top(true)
|
||||||
|
.theme(theme)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|||||||
2
src-tauri/src/assets/core.js
vendored
2
src-tauri/src/assets/core.js
vendored
@@ -71,7 +71,7 @@ async function init() {
|
|||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest("a");
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
if (origin && origin.href && origin.target !== '_self') {
|
||||||
origin.target = "_self";
|
invoke('open_link', { url: origin.href });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
0
src-tauri/src/assets/origin.js
vendored
Normal file
0
src-tauri/src/assets/origin.js
vendored
Normal file
@@ -8,6 +8,12 @@ pub const USER_AGENT: &str = "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKi
|
|||||||
pub const PHONE_USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
|
pub const PHONE_USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
|
||||||
pub const ISSUES_URL: &str = "https://github.com/lencx/ChatGPT/issues";
|
pub const ISSUES_URL: &str = "https://github.com/lencx/ChatGPT/issues";
|
||||||
pub const AWESOME_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/AWESOME.md";
|
pub const AWESOME_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/AWESOME.md";
|
||||||
|
pub const DEFAULT_CHAT_CONF: &str = r#"{
|
||||||
|
"always_on_top": false,
|
||||||
|
"theme": "Light",
|
||||||
|
"titlebar": true,
|
||||||
|
"origin": "https://chat.openai.com/"
|
||||||
|
}"#;
|
||||||
|
|
||||||
pub struct ChatState {
|
pub struct ChatState {
|
||||||
pub always_on_top: Mutex<bool>,
|
pub always_on_top: Mutex<bool>,
|
||||||
@@ -26,6 +32,7 @@ pub struct ChatConfJson {
|
|||||||
pub always_on_top: bool,
|
pub always_on_top: bool,
|
||||||
pub theme: String,
|
pub theme: String,
|
||||||
pub titlebar: bool,
|
pub titlebar: bool,
|
||||||
|
pub origin: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatConfJson {
|
impl ChatConfJson {
|
||||||
@@ -35,22 +42,10 @@ impl ChatConfJson {
|
|||||||
let conf_file = ChatConfJson::conf_path();
|
let conf_file = ChatConfJson::conf_path();
|
||||||
if !exists(&conf_file) {
|
if !exists(&conf_file) {
|
||||||
create_file(&conf_file).unwrap();
|
create_file(&conf_file).unwrap();
|
||||||
|
fs::write(&conf_file, DEFAULT_CHAT_CONF).unwrap();
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let content = r#"{
|
ChatConfJson::amend(&serde_json::json!({ "titlebar": false })).unwrap();
|
||||||
"always_on_top": false,
|
|
||||||
"theme": "Light",
|
|
||||||
"titlebar": false
|
|
||||||
}"#;
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
let content = r#"{
|
|
||||||
"always_on_top": false,
|
|
||||||
"theme": "Light",
|
|
||||||
"titlebar": true
|
|
||||||
}"#;
|
|
||||||
|
|
||||||
fs::write(&conf_file, content).unwrap();
|
|
||||||
}
|
}
|
||||||
conf_file
|
conf_file
|
||||||
}
|
}
|
||||||
@@ -77,7 +72,10 @@ impl ChatConfJson {
|
|||||||
config.insert(k, v);
|
config.insert(k, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::write(ChatConfJson::conf_path(), serde_json::to_string(&config)?)?;
|
fs::write(
|
||||||
|
ChatConfJson::conf_path(),
|
||||||
|
serde_json::to_string_pretty(&config)?,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,11 +98,6 @@ impl ChatConfJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn chat_conf_default() -> Self {
|
pub fn chat_conf_default() -> Self {
|
||||||
serde_json::from_value(serde_json::json!({
|
serde_json::from_value(serde_json::json!(DEFAULT_CHAT_CONF)).unwrap()
|
||||||
"always_on_top": false,
|
|
||||||
"theme": "Light",
|
|
||||||
"titlebar": true
|
|
||||||
}))
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
use tauri::utils::config::Config;
|
// use tauri::utils::config::Config;
|
||||||
|
|
||||||
pub fn chat_root() -> PathBuf {
|
pub fn chat_root() -> PathBuf {
|
||||||
tauri::api::path::home_dir().unwrap().join(".chatgpt")
|
tauri::api::path::home_dir().unwrap().join(".chatgpt")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_tauri_conf() -> Option<Config> {
|
// pub fn get_tauri_conf() -> Option<Config> {
|
||||||
let config_file = include_str!("../tauri.conf.json");
|
// let config_file = include_str!("../tauri.conf.json");
|
||||||
let config: Config =
|
// let config: Config =
|
||||||
serde_json::from_str(config_file).expect("failed to parse tauri.conf.json");
|
// serde_json::from_str(config_file).expect("failed to parse tauri.conf.json");
|
||||||
Some(config)
|
// Some(config)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn exists(path: &Path) -> bool {
|
pub fn exists(path: &Path) -> bool {
|
||||||
Path::new(path).exists()
|
Path::new(path).exists()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "",
|
"beforeDevCommand": "",
|
||||||
"beforeBuildCommand": "",
|
"beforeBuildCommand": "",
|
||||||
"devPath": "https://chat.openai.com/",
|
"devPath": "../dist",
|
||||||
"distDir": "../dist"
|
"distDir": "../dist"
|
||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
|
|||||||
Reference in New Issue
Block a user