♻️ 感觉差不多了,剩下的就靠测试了 #92

This commit is contained in:
目棃
2024-07-03 22:33:00 +08:00
parent 8a2c7d13c6
commit f4de7552e1
28 changed files with 249 additions and 399 deletions

View File

@@ -0,0 +1,37 @@
{
"$schema": "./schemas/desktop-schema.json",
"identifier": "DevJson",
"description": "Capability for the dev json window",
"windows": ["Dev_JSON"],
"permissions": [
"app:allow-version",
"app:default",
"event:allow-listen",
"event:default",
"http:allow-fetch",
"log:allow-log",
"log:default",
"path:allow-resolve-directory",
"path:default",
"sql:allow-load",
"sql:allow-execute",
"sql:default",
"window:allow-close",
"window:allow-destroy",
"window:allow-set-title",
"window:allow-set-fullscreen",
"window:allow-show",
{
"identifier": "http:default",
"allow": [
{
"url": "https://*.miyoushe.com/*"
},
{
"url": "https://*.mihoyo.com/*"
}
]
}
],
"platforms": ["windows", "macOS"]
}

View File

@@ -3,7 +3,41 @@
"identifier": "Mys",
"description": "Capability for the mys client window",
"windows": ["mhy_client"],
"permissions": ["event:allow-emit"],
"permissions": [
"dialog:allow-message",
"dialog:default",
"event:allow-emit",
"path:allow-resolve-directory",
"path:default",
{
"identifier": "fs:allow-exists",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-mkdir",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-read-dir",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-read-text-file",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-remove",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-write-file",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-write-text-file",
"allow": [{ "path": "**" }]
}
],
"remote": {
"urls": ["https://*.mihoyo.com/*", "https://*.miyoushe.com/*"]
},

View File

@@ -8,10 +8,7 @@
"app:default",
"event:allow-listen",
"event:default",
"fs:allow-remove",
"fs:default",
"fs:scope-cache-recursive",
"fs:scope-document-recursive",
"http:allow-fetch",
"log:allow-log",
"log:default",
@@ -26,10 +23,43 @@
"sql:allow-load",
"sql:allow-execute",
"sql:default",
"webview:allow-create-webview-window",
"webview:default",
"window:allow-close",
"window:allow-destroy",
"window:default",
"window:allow-is-minimized",
"window:allow-set-title",
"window:allow-set-focus",
"window:allow-show",
{
"identifier": "fs:allow-exists",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-mkdir",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-read-dir",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-read-text-file",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-remove",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-write-file",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-write-text-file",
"allow": [{ "path": "**" }]
},
{
"identifier": "http:default",
"allow": [

View File

@@ -1,11 +1,54 @@
{
"DevJson": {
"identifier": "DevJson",
"description": "Capability for the dev json window",
"local": true,
"windows": ["Dev_JSON"],
"permissions": [
"app:allow-version",
"app:default",
"event:allow-listen",
"event:default",
"http:allow-fetch",
"log:allow-log",
"log:default",
"path:allow-resolve-directory",
"path:default",
"sql:allow-load",
"sql:allow-execute",
"sql:default",
"window:allow-close",
"window:allow-destroy",
"window:allow-set-title",
"window:allow-set-fullscreen",
"window:allow-show",
{
"identifier": "http:default",
"allow": [{ "url": "https://*.miyoushe.com/*" }, { "url": "https://*.mihoyo.com/*" }]
}
],
"platforms": ["windows", "macOS"]
},
"Mys": {
"identifier": "Mys",
"description": "Capability for the mys client window",
"remote": { "urls": ["https://*.mihoyo.com/*", "https://*.miyoushe.com/*"] },
"local": true,
"windows": ["mhy_client"],
"permissions": ["event:allow-emit"],
"permissions": [
"dialog:allow-message",
"dialog:default",
"event:allow-emit",
"path:allow-resolve-directory",
"path:default",
{ "identifier": "fs:allow-exists", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-mkdir", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-read-dir", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-read-text-file", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-remove", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-write-file", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-write-text-file", "allow": [{ "path": "**" }] }
],
"platforms": ["windows", "macOS"]
},
"SubWindow": {
@@ -48,10 +91,7 @@
"app:default",
"event:allow-listen",
"event:default",
"fs:allow-remove",
"fs:default",
"fs:scope-cache-recursive",
"fs:scope-document-recursive",
"http:allow-fetch",
"log:allow-log",
"log:default",
@@ -66,10 +106,22 @@
"sql:allow-load",
"sql:allow-execute",
"sql:default",
"webview:allow-create-webview-window",
"webview:default",
"window:allow-close",
"window:allow-destroy",
"window:default",
"window:allow-is-minimized",
"window:allow-set-title",
"window:allow-set-focus",
"window:allow-show",
{ "identifier": "fs:allow-exists", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-mkdir", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-read-dir", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-read-text-file", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-remove", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-write-file", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-write-text-file", "allow": [{ "path": "**" }] },
{
"identifier": "http:default",
"allow": [

View File

@@ -43,16 +43,11 @@ fn create_utils_menu(app: AppHandle) -> Submenu<Wry> {
}
// 创建米游社客户端菜单
pub fn create_mhy_menu(func: String, app: AppHandle) -> Menu<Wry> {
pub fn create_mhy_menu(app: AppHandle) -> Menu<Wry> {
let top_menu = MenuItemBuilder::with_id("top", "置顶").build(&app).unwrap();
let cancel_top_menu = MenuItemBuilder::with_id("cancel_top", "取消置顶").build(&app).unwrap();
let sign_in_menu = MenuItemBuilder::with_id("sign_in", "用户登录").build(&app).unwrap();
let open_post_menu = MenuItemBuilder::with_id("open_post", "打开帖子").build(&app).unwrap();
let utils_menu = create_utils_menu(app.clone());
// 如果是登录
if func == "config_sign_in" {
return MenuBuilder::new(&app).item(&sign_in_menu).build().expect("failed to create mhy_menu");
}
return MenuBuilder::new(&app)
.item(&top_menu)
.item(&cancel_top_menu)
@@ -67,7 +62,6 @@ pub fn handle_menu_event(window: &Window, event: MenuEvent) {
match event.id.as_ref() {
"top" => handle_menu_top(window),
"cancel_top" => handle_menu_cancel_top(window),
"sign_in" => handle_menu_sign_in(window),
"open_post" => handle_menu_open_post(window),
"retry" => handle_menu_retry(window),
"mock_touch" => handle_menu_mock_touch(window),
@@ -93,29 +87,6 @@ fn handle_menu_cancel_top(app_handle: &Window) {
}
}
// 处理用户登录菜单
fn handle_menu_sign_in(app_handle: &Window) {
let window = app_handle.get_webview_window("mhy_client");
let execute_js = r#"
javascript:(async function(){
// 首先检测是不是 user.mihoyo.com
const url = new URL(window.location.href);
if(url.hostname !== "user.mihoyo.com"){
alert("当前页面不是米游社登录页面");
return;
}
const ck = document.cookie;
const arg = {
method: 'teyvat_sign_in',
payload: ck,
}
await window.__TAURI__.event.emit('post_mhy_client',JSON.stringify(arg));
})()"#;
if window.is_some() {
window.unwrap().eval(&execute_js).ok().unwrap();
}
}
// 处理打开帖子菜单
fn handle_menu_open_post(app_handle: &Window) {
let window = app_handle.get_webview_window("mhy_client");

View File

@@ -3,42 +3,37 @@
//! @since Beta v0.5.0
mod menu;
use tauri::async_runtime::block_on;
use tauri::{AppHandle, Manager, WebviewWindowBuilder, WindowEvent};
use tauri::{AppHandle, Manager, WebviewWindowBuilder};
use tauri_utils::config::WebviewUrl;
#[tauri::command]
pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) {
let mut mhy_window_config = handle.config().app.windows.get(1).unwrap().clone();
mhy_window_config.visible = true;
let mut option = handle.config().app.windows.get(1).unwrap().clone();
let url_parse;
if url != "" {
mhy_window_config.url = WebviewUrl::External(url.parse().unwrap());
url_parse = WebviewUrl::External(url.parse().unwrap());
} else {
mhy_window_config.url = menu::get_mhy_client_url(func.clone());
url_parse = menu::get_mhy_client_url(func.clone());
}
if func == "birthday"
|| func == "web_act"
|| url.starts_with("https://webstatic.mihoyo.com/ys/event/e20220303-birthday/index.html")
{
mhy_window_config.width = 1280.0;
mhy_window_config.height = 720.0;
option.width = 1280.0;
option.height = 720.0;
}
let window_get = handle.get_webview_window("mhy_client");
if window_get.is_some() {
let mhy_client = window_get.unwrap();
mhy_client.on_window_event(move |e| {
if let WindowEvent::Destroyed = e {
let future = create_mhy_client(handle.clone(), func.clone(), url.clone());
block_on(future);
}
});
mhy_client.close().unwrap();
let window_find = handle.get_webview_window("mhy_client");
if window_find.is_some() {
window_find.unwrap().destroy().unwrap();
return;
}
WebviewWindowBuilder::from_config(&handle, &mhy_window_config)
.expect("failed to create mhy_client")
.menu(menu::create_mhy_menu(func.clone(), handle.clone()))
WebviewWindowBuilder::new(&handle, "mhy_client", url_parse)
.inner_size(option.width, option.height)
.title(option.title)
.center()
.user_agent(option.user_agent.unwrap().as_str())
.menu(menu::create_mhy_menu(handle.clone()))
.on_menu_event(move |app, event| menu::handle_menu_event(app, event))
.build()
.expect("failed to add menu")
.on_menu_event(move |app, event| menu::handle_menu_event(app, event));
.unwrap();
}

View File

@@ -38,8 +38,7 @@ pub async fn create_window(
) {
let window_find = app_handle.get_webview_window(&label);
if window_find.is_some() {
let window = window_find.unwrap();
window.destroy().unwrap();
window_find.unwrap().destroy().unwrap();
return;
}
let url_parse = WebviewUrl::App(url.parse().unwrap());
@@ -55,10 +54,10 @@ pub async fn create_window(
// 执行 js
#[tauri::command]
pub async fn execute_js(app_handle: tauri::AppHandle, label: String, js: String) {
pub async fn execute_js(app_handle: AppHandle, label: String, js: String) {
let window = app_handle.get_webview_window(&label);
if window.is_some() {
window.unwrap().eval(&js).ok().unwrap();
window.unwrap().eval(&js).unwrap();
}
}

View File

@@ -1,5 +1,6 @@
{
"productName": "TeyvatGuide",
"identifier": "TeyvatGuide",
"version": "0.4.9",
"build": {
"beforeDevCommand": "pnpm vite:dev",
@@ -62,13 +63,13 @@
}
],
"security": {
"capabilities": ["TeyvatGuide", "Mys", "SubWindow"]
"capabilities": ["TeyvatGuide", "Mys", "SubWindow", "DevJson"]
}
},
"plugins": {
"deep-link": {
"desktop": {
"schemes": ["teyvatguide", "test"]
"schemes": ["teyvatguide"]
},
"mobile": []
}