🎨 fix(ck): 删除 rocket,采用手动 cv

This commit is contained in:
BTMuli
2023-05-04 21:05:01 +08:00
parent 50f2305d5e
commit baff5a17c6
5 changed files with 133 additions and 704 deletions

View File

@@ -3,46 +3,6 @@
// Tauri
use tauri::{AppHandle, Manager, WindowBuilder, WindowUrl};
// Rocket
use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::Header;
use rocket::{Request, Response};
#[macro_use]
extern crate rocket;
static mut COOKIE: String = String::new();
// Rocket 接受 get 请求,发来的 cookie 会被打印在控制台
#[rocket::get("/login?<cookie>")]
fn emit_cookie(cookie: String) -> String {
unsafe {
COOKIE = cookie.parse().unwrap();
}
cookie
}
pub struct Cors;
#[rocket::async_trait]
impl Fairing for Cors {
fn info(&self) -> Info {
Info {
name: "Cross-Origin-Resource-Sharing Fairing",
kind: Kind::Response,
}
}
async fn on_response<'r>(&self, _request: &'r Request<'_>, response: &mut Response<'r>) {
response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
response.set_header(Header::new(
"Access-Control-Allow-Methods",
"POST, PATCH, PUT, DELETE, HEAD, OPTIONS, GET",
));
response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
}
}
#[tauri::command]
async fn mys_login(handle: AppHandle) {
@@ -60,29 +20,17 @@ async fn mys_login(handle: AppHandle) {
if(cookie === null || cookie.includes('login_ticket') === false) {
alert('请在该网页登录后关闭窗口再试');
} else {
fetch('http://localhost:8000/login?cookie=' + cookie);
alert('成功获取 cookie!请关闭窗口');
prompt('请复制以下内容后手动输入', cookie);
}
";
mys_window.eval(js_code).ok().unwrap();
}
#[tauri::command]
fn read_cookie() -> String {
unsafe { COOKIE.clone() }
}
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_sql::Builder::default().build())
.invoke_handler(tauri::generate_handler![mys_login, read_cookie])
.invoke_handler(tauri::generate_handler![mys_login])
.setup(|_app| {
tauri::async_runtime::spawn(
rocket::build()
.attach(Cors)
.mount("/", routes![emit_cookie])
.launch(),
);
#[cfg(debug_assertions)] // only include this code on debug builds
{
let window = _app.get_window("tauri-genshin").unwrap();