mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: control center
This commit is contained in:
@@ -35,9 +35,8 @@ pub fn get_chat_conf() -> ChatConfJson {
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub fn form_confirm(app: AppHandle, data: serde_json::Value) {
|
||||
pub fn form_confirm(_app: AppHandle, data: serde_json::Value) {
|
||||
ChatConfJson::amend(&serde_json::json!(data)).unwrap();
|
||||
tauri::api::process::restart(&app.env());
|
||||
}
|
||||
|
||||
#[command]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::{
|
||||
app::window,
|
||||
conf::{self, ChatConfJson},
|
||||
utils,
|
||||
};
|
||||
@@ -71,14 +70,6 @@ pub fn init(context: &Context<EmbeddedAssets>) -> Menu {
|
||||
#[cfg(target_os = "macos")]
|
||||
titlebar_menu.into(),
|
||||
MenuItem::Separator.into(),
|
||||
// fix: Checking if the site connection is secure
|
||||
// @link: https://github.com/lencx/ChatGPT/issues/17
|
||||
CustomMenuItem::new("user_agent".to_string(), "User Agent")
|
||||
.accelerator("CmdOrCtrl+U")
|
||||
.into(),
|
||||
CustomMenuItem::new("switch_origin".to_string(), "Switch Origin")
|
||||
.accelerator("CmdOrCtrl+O")
|
||||
.into(),
|
||||
CustomMenuItem::new("inject_script".to_string(), "Inject Script")
|
||||
.accelerator("CmdOrCtrl+J")
|
||||
.into(),
|
||||
@@ -174,8 +165,6 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
"inject_script" => open(&app, script_path),
|
||||
"go_conf" => utils::open_file(utils::chat_root()),
|
||||
"clear_conf" => utils::clear_conf(&app),
|
||||
"switch_origin" => window::origin_window(&app),
|
||||
"user_agent" => window::ua_window(&app),
|
||||
"awesome" => open(&app, conf::AWESOME_URL.to_string()),
|
||||
"titlebar" => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
|
||||
@@ -23,31 +23,3 @@ pub fn mini_window(handle: &tauri::AppHandle) {
|
||||
.hide()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn origin_window(handle: &tauri::AppHandle) {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
WindowBuilder::new(handle, "origin", WindowUrl::App(chat_conf.origin.into()))
|
||||
.resizable(false)
|
||||
.fullscreen(false)
|
||||
.inner_size(400.0, 300.0)
|
||||
.always_on_top(true)
|
||||
.decorations(false)
|
||||
.initialization_script(include_str!("../assets/core.js"))
|
||||
.initialization_script(include_str!("../assets/origin.js"))
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn ua_window(handle: &tauri::AppHandle) {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
WindowBuilder::new(handle, "ua", WindowUrl::App(chat_conf.origin.into()))
|
||||
.resizable(false)
|
||||
.fullscreen(false)
|
||||
.inner_size(540.0, 480.0)
|
||||
.always_on_top(true)
|
||||
.decorations(false)
|
||||
.initialization_script(include_str!("../assets/core.js"))
|
||||
.initialization_script(include_str!("../assets/ua.js"))
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
79
src-tauri/src/assets/origin.js
vendored
79
src-tauri/src/assets/origin.js
vendored
@@ -1,79 +0,0 @@
|
||||
// *** Core Script - Origin ***
|
||||
|
||||
function init() {
|
||||
document.body.innerHTML = `<style>
|
||||
body {
|
||||
height: 100vh;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-family: Söhne,ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif,Helvetica Neue,Arial,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;
|
||||
}
|
||||
h3 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
input {
|
||||
all: unset;
|
||||
width: 280px;
|
||||
height: 30px;
|
||||
margin-bottom: 10px;
|
||||
padding: 0 5px;
|
||||
border: solid 2px #d8d8d8;
|
||||
background-color: #fff;
|
||||
border-radius: 5px !important;
|
||||
color: #4a4a4a;
|
||||
}
|
||||
button {
|
||||
all: unset;
|
||||
height: 30px;
|
||||
font-size: 16px;
|
||||
padding: 0 10px;
|
||||
line-height: 30px;
|
||||
margin: 0 5px;
|
||||
color: #fff;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#cancel {
|
||||
background-color: #999;
|
||||
}
|
||||
#confirm {
|
||||
background-color: #10a37f;
|
||||
}
|
||||
</style>
|
||||
<h3>Switch Origin</h3>
|
||||
<input id="input" type="text" autocapitalize="off" autocomplete="off" spellcheck="false" autofocus placeholder="https://chat.openai.com" />
|
||||
<div class="btns">
|
||||
<button id="cancel">Cancel</button>
|
||||
<button id="confirm">Confirm</button>
|
||||
</div>`;
|
||||
|
||||
const srcipt = document.createElement('script');
|
||||
srcipt.innerHTML = `const input = document.getElementById('input');
|
||||
const cancelBtn = document.getElementById('cancel');
|
||||
const confirmBtn = document.getElementById('confirm');
|
||||
cancelBtn.addEventListener('click', () => {
|
||||
window.invoke('form_cancel', { label: 'origin', title: 'Switch Origin', msg: 'Are you sure you want to cancel editing?' });
|
||||
})
|
||||
confirmBtn.addEventListener('click', () => {
|
||||
if (/^https?:\\/\\//.test(input.value)) {
|
||||
window.invoke('form_confirm', { data: { origin: input.value } });
|
||||
} else {
|
||||
window.invoke('form_msg', { label: 'origin', title: 'Switch Origin', msg: 'Invalid URL!' });
|
||||
}
|
||||
})`;
|
||||
document.head.appendChild(srcipt);
|
||||
}
|
||||
|
||||
// run init
|
||||
if (
|
||||
document.readyState === "complete" ||
|
||||
document.readyState === "interactive"
|
||||
) {
|
||||
init();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
}
|
||||
91
src-tauri/src/assets/ua.js
vendored
91
src-tauri/src/assets/ua.js
vendored
@@ -1,91 +0,0 @@
|
||||
// *** Core Script - User Agent ***
|
||||
|
||||
function init() {
|
||||
document.body.innerHTML = `<style>
|
||||
body {
|
||||
height: 100vh;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-family: Söhne,ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif,Helvetica Neue,Arial,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;
|
||||
}
|
||||
h3 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
textarea {
|
||||
all: unset;
|
||||
width: 300px;
|
||||
height: 60px;
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
border: solid 2px #d8d8d8;
|
||||
background-color: #fff;
|
||||
border-radius: 5px !important;
|
||||
color: #4a4a4a;
|
||||
}
|
||||
button {
|
||||
all: unset;
|
||||
height: 30px;
|
||||
font-size: 16px;
|
||||
padding: 0 10px;
|
||||
line-height: 30px;
|
||||
margin: 0 5px;
|
||||
color: #fff;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#cancel {
|
||||
background-color: #999;
|
||||
}
|
||||
#confirm {
|
||||
background-color: #10a37f;
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
label {
|
||||
width: 120px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
</style>
|
||||
<h3>User Agent</h3>
|
||||
<div class="item">
|
||||
<label>Main Window (PC)</label>
|
||||
<textarea id="ua_pc" type="text" autocapitalize="off" autocomplete="off" spellcheck="false" autofocus placeholder="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ..."></textarea>
|
||||
</div>
|
||||
<div class="item">
|
||||
<label>Tray Window (Phone)</label>
|
||||
<textarea id="ua_phone" type="text" autocapitalize="off" autocomplete="off" spellcheck="false" autofocus placeholder="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS ..."></textarea>
|
||||
</div>
|
||||
<div class="btns">
|
||||
<button id="cancel">Cancel</button>
|
||||
<button id="confirm">Confirm</button>
|
||||
</div>`;
|
||||
|
||||
const srcipt = document.createElement('script');
|
||||
srcipt.innerHTML = `const ua_pc = document.getElementById('ua_pc');
|
||||
const ua_phone = document.getElementById('ua_phone');
|
||||
const cancelBtn = document.getElementById('cancel');
|
||||
const confirmBtn = document.getElementById('confirm');
|
||||
cancelBtn.addEventListener('click', () => {
|
||||
window.invoke('form_cancel', { label: 'ua', title: 'User Agent', msg: 'Are you sure you want to cancel editing?' });
|
||||
})
|
||||
confirmBtn.addEventListener('click', () => {
|
||||
window.invoke('form_confirm', { data: { ua_pc: ua_pc.value, ua_phone: ua_phone.value } });
|
||||
})`;
|
||||
document.head.appendChild(srcipt);
|
||||
}
|
||||
|
||||
// run init
|
||||
if (
|
||||
document.readyState === "complete" ||
|
||||
document.readyState === "interactive"
|
||||
) {
|
||||
init();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
}
|
||||
Reference in New Issue
Block a user