diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 7fc5d264..0133a76a 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -12,6 +12,9 @@ dependencies = [
"tauri-build",
"tauri-plugin-deep-link",
"tauri-plugin-sql",
+ "url",
+ "webview2-com 0.27.0",
+ "windows 0.51.1",
]
[[package]]
@@ -4010,7 +4013,7 @@ dependencies = [
"unicode-segmentation",
"uuid",
"windows 0.39.0",
- "windows-implement",
+ "windows-implement 0.39.0",
"x11-dl",
]
@@ -4093,7 +4096,7 @@ dependencies = [
"url",
"uuid",
"webkit2gtk",
- "webview2-com",
+ "webview2-com 0.19.1",
"windows 0.39.0",
]
@@ -4203,7 +4206,7 @@ dependencies = [
"thiserror",
"url",
"uuid",
- "webview2-com",
+ "webview2-com 0.19.1",
"windows 0.39.0",
]
@@ -4222,7 +4225,7 @@ dependencies = [
"tauri-utils",
"uuid",
"webkit2gtk",
- "webview2-com",
+ "webview2-com 0.19.1",
"windows 0.39.0",
"wry",
]
@@ -4883,10 +4886,24 @@ version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4a769c9f1a64a8734bde70caafac2b96cada12cd4aefa49196b3a386b8b4178"
dependencies = [
- "webview2-com-macros",
- "webview2-com-sys",
+ "webview2-com-macros 0.6.0",
+ "webview2-com-sys 0.19.0",
"windows 0.39.0",
- "windows-implement",
+ "windows-implement 0.39.0",
+]
+
+[[package]]
+name = "webview2-com"
+version = "0.27.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd15556ff1d1d6bc850dbb362762bae86069773dd30177c90d3bfa917080dc73"
+dependencies = [
+ "webview2-com-macros 0.7.0",
+ "webview2-com-sys 0.27.0",
+ "windows 0.51.1",
+ "windows-core",
+ "windows-implement 0.51.1",
+ "windows-interface",
]
[[package]]
@@ -4900,6 +4917,17 @@ dependencies = [
"syn 1.0.109",
]
+[[package]]
+name = "webview2-com-macros"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac1345798ecd8122468840bcdf1b95e5dc6d2206c5e4b0eafa078d061f59c9bc"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.37",
+]
+
[[package]]
name = "webview2-com-sys"
version = "0.19.0"
@@ -4915,6 +4943,17 @@ dependencies = [
"windows-metadata",
]
+[[package]]
+name = "webview2-com-sys"
+version = "0.27.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3775bb005c3170497ec411b36005708b57ad486bfa3d23864c92f5973858ce8d"
+dependencies = [
+ "thiserror",
+ "windows 0.51.1",
+ "windows-core",
+]
+
[[package]]
name = "whoami"
version = "1.4.1"
@@ -4971,7 +5010,7 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a"
dependencies = [
- "windows-implement",
+ "windows-implement 0.39.0",
"windows_aarch64_msvc 0.39.0",
"windows_i686_gnu 0.39.0",
"windows_i686_msvc 0.39.0",
@@ -4988,6 +5027,18 @@ dependencies = [
"windows-targets 0.48.5",
]
+[[package]]
+name = "windows"
+version = "0.51.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9"
+dependencies = [
+ "windows-core",
+ "windows-implement 0.51.1",
+ "windows-interface",
+ "windows-targets 0.48.5",
+]
+
[[package]]
name = "windows-bindgen"
version = "0.39.0"
@@ -4998,6 +5049,15 @@ dependencies = [
"windows-tokens",
]
+[[package]]
+name = "windows-core"
+version = "0.51.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
+dependencies = [
+ "windows-targets 0.48.5",
+]
+
[[package]]
name = "windows-implement"
version = "0.39.0"
@@ -5008,6 +5068,28 @@ dependencies = [
"windows-tokens",
]
+[[package]]
+name = "windows-implement"
+version = "0.51.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fb2b158efec5af20d8846836622f50a87e6556b9153a42772fa047f773c0e555"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.37",
+]
+
+[[package]]
+name = "windows-interface"
+version = "0.51.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0546e63e1ce64c04403d2311fa0e3ab5ae3a367bd524b4a38d8d8d18c70cfa76"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.37",
+]
+
[[package]]
name = "windows-metadata"
version = "0.39.0"
@@ -5289,9 +5371,9 @@ dependencies = [
"url",
"webkit2gtk",
"webkit2gtk-sys",
- "webview2-com",
+ "webview2-com 0.19.1",
"windows 0.39.0",
- "windows-implement",
+ "windows-implement 0.39.0",
]
[[package]]
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 0896f7c0..e946c26f 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -16,6 +16,9 @@ tauri-build = { version = "1.4", features = [] }
tauri = { version = "1.4", features = ["api-all"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
+webview2-com = "0.27.0"
+windows = "0.51.1"
+url = "2.4.1"
# sqlite 插件
[dependencies.tauri-plugin-sql]
diff --git a/src-tauri/src/client.rs b/src-tauri/src/client.rs
index 3b0fd0df..608d3a31 100644
--- a/src-tauri/src/client.rs
+++ b/src-tauri/src/client.rs
@@ -2,34 +2,45 @@
//! @desc 客户端模块,负责操作米游社客户端
//! @since Beta v0.3.3
-use tauri::{AppHandle, Manager,WindowBuilder};
+use tauri::{AppHandle, Manager,WindowBuilder, WindowUrl};
+use url::Url;
+
+// 获取米游社客户端入口地址
+fn get_mhy_client_url(func: String) -> WindowUrl {
+ let mut url_res: Url = "https://bbs.mihoyo.com/ys/".parse().unwrap();
+ if func == "sign_in" {
+ url_res = "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501".parse().unwrap();
+ } else if func == "game_record" {
+ url_res = "https://webstatic.mihoyo.com/app/community-game-records/index.html".parse().unwrap();
+ }
+ return WindowUrl::External(url_res);
+}
// 操作米游社客户端
#[tauri::command]
-pub async fn operate_mhy(handle: AppHandle, arg: String) {
+pub async fn create_mhy_client(handle: AppHandle, func: String, arg: String) {
+ dbg!(&arg);
let has_mhy_client = handle.get_window("mhy_client").is_some();
+ let mut mhy_client_config = handle.config().tauri.windows.get(1).unwrap().clone();
+ mhy_client_config.url = get_mhy_client_url(func.clone());
let mhy_client;
if has_mhy_client {
mhy_client = handle.get_window("mhy_client").unwrap();
+ mhy_client.close().unwrap();
} else {
mhy_client = WindowBuilder::from_config(
- &handle,
- handle.config().tauri.windows.get(1).unwrap().clone()
- )
- .build()
- .unwrap();
- }
- if mhy_client.is_visible().unwrap() == false {
+ &handle,
+ mhy_client_config,
+ )
+ .build()
+ .unwrap();
mhy_client.show().unwrap();
+ mhy_client.set_focus().unwrap();
+ let js_code = r#"
+ window.MiHoYoJSInterface = {
+ postMessage: function(arg) { window.__TAURI__.event.emit('post_mhy_client', arg) },
+ closePage: function() { this.postMessage('{"method":"closePage"}') },
+ };"#;
+ mhy_client.eval(&js_code).ok().unwrap();
}
- mhy_client.set_focus().unwrap();
- let js_code = r#"
- window.MiHoYoJSInterface = {
- postMessage: function(arg) { chrome.webview.postMessage(arg);console.log(arg) },
- closePage: function() { this.postMessage('{"method":"closePage"}') },
- };"#;
- mhy_client.eval(&js_code).ok().unwrap();
- let js_eval = format!("window.MiHoYoJSInterface.postMessage('{}')", arg);
- handle.emit_all("post_mhy_client", arg).unwrap();
- mhy_client.eval(&js_eval).ok().unwrap();
}
\ No newline at end of file
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 8e9f03a4..e592211e 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -65,7 +65,7 @@ fn main() {
}
})
.plugin(tauri_plugin_sql::Builder::default().build())
- .invoke_handler(tauri::generate_handler![register_deep_link, init_app, client::operate_mhy])
+ .invoke_handler(tauri::generate_handler![register_deep_link, init_app, client::create_mhy_client])
.setup(|_app| {
let _window = _app.get_window("TeyvatGuide").unwrap();
#[cfg(debug_assertions)] // only include this code on debug builds
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 8c2b35d3..820f8d9e 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -20,25 +20,7 @@
"http": {
"all": true,
"request": true,
- "scope": [
- "https://act-webstatic.mihoyo.com/*",
- "https://api-static.mihoyo.com/*",
- "https://api-takumi-record.mihoyo.com/*",
- "https://api-takumi.mihoyo.com/*",
- "https://api.geetest.com/*",
- "https://bbs-api-static.miyoushe.com/*",
- "https://bbs-api.mihoyo.com/*",
- "https://bbs-api.miyoushe.com/*",
- "https://bbs.mihoyo.com/*",
- "https://enka-api.hut.ao/*",
- "https://hk4e-api.mihoyo.com/*",
- "https://hk4e-sdk.mihoyo.com/*",
- "https://homa.snapgenshin.com/*",
- "https://passport-api-v4.mihoyo.com/*",
- "https://passport-api.mihoyo.com/*",
- "https://passport-api.miyoushe.com/*",
- "https://sdk-webstatic.mihoyo.com/*"
- ]
+ "scope": ["https://**"]
},
"shell": {
"all": false,
@@ -73,7 +55,19 @@
}
},
"security": {
- "csp": null
+ "dangerousRemoteDomainIpcAccess": [
+ {
+ "domain": "api-static.mihoyo.com",
+ "windows": ["mhy_client"],
+ "enableTauriAPI": true
+ },
+ {
+ "domain": "webstatic.mihoyo.com",
+ "windows": ["mhy_client"],
+ "enableTauriAPI": true
+ }
+ ],
+ "csp": "default-src 'self' *; img-src *; script-src *"
},
"updater": {
"active": false,
@@ -100,7 +94,8 @@
"resizable": false,
"title": "米游社",
"label": "mhy_client",
- "url": "https://bbs.mihoyo.com/",
+ "url": "https://api-static.mihoyo.com/",
+ "userAgent": "Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/2.60.1",
"visible": false,
"width": 360,
"height": 780,
diff --git a/src/pages/common/Test.vue b/src/pages/common/Test.vue
index 1a02f225..13db1194 100644
--- a/src/pages/common/Test.vue
+++ b/src/pages/common/Test.vue
@@ -24,19 +24,16 @@