|
|
@@ -143,8 +143,9 @@ pub async fn data_url_from_url(url: String) -> Result<String, String> {
|
|
|
Ok(format!("data:{};base64,{}", mime, b64))
|
|
|
}
|
|
|
|
|
|
-/// 微信扫码登录:取二维码链接 → 用系统浏览器打开 → 后台轮询换取 JWT → 写入 keyring。
|
|
|
-/// 结果通过 `pet://wechat-login` 事件回传
|
|
|
+/// 微信小程序码扫码登录:取小程序码图片 → 前端展示 → 后台轮询换取 JWT → 写入 keyring。
|
|
|
+/// 二维码图片通过 `pet://wechat-qr` 事件回传({state, qrImage});
|
|
|
+/// 登录结果通过 `pet://wechat-login` 事件回传
|
|
|
/// (status: pending / success / notfound / expired / error / timeout)。
|
|
|
#[tauri::command]
|
|
|
pub async fn start_wechat_login(app: AppHandle) -> Result<serde_json::Value, String> {
|
|
|
@@ -156,7 +157,12 @@ pub async fn start_wechat_login(app: AppHandle) -> Result<serde_json::Value, Str
|
|
|
.await
|
|
|
.map_err(|e| format!("获取二维码失败: {e}"))?
|
|
|
};
|
|
|
- open_url(&qr.url)?;
|
|
|
+
|
|
|
+ // 将小程序码图片推给设置窗口展示(用户用微信扫码后在小程序内确认登录)
|
|
|
+ let _ = app.emit(
|
|
|
+ "pet://wechat-qr",
|
|
|
+ serde_json::json!({ "state": qr.state.clone(), "qrImage": qr.qr_image.clone() }),
|
|
|
+ );
|
|
|
|
|
|
let api = app.state::<AppState>().api.clone();
|
|
|
let state_token = qr.state.clone();
|
|
|
@@ -212,33 +218,7 @@ pub async fn start_wechat_login(app: AppHandle) -> Result<serde_json::Value, Str
|
|
|
let _ = handle.emit("pet://wechat-login", serde_json::json!({"status": "timeout"}));
|
|
|
});
|
|
|
|
|
|
- Ok(serde_json::json!({ "status": "pending", "url": qr.url }))
|
|
|
-}
|
|
|
-
|
|
|
-/// 用系统默认浏览器打开 URL(Windows: cmd start / macOS: open / 其它: xdg-open)。
|
|
|
-fn open_url(url: &str) -> Result<(), String> {
|
|
|
- #[cfg(target_os = "windows")]
|
|
|
- {
|
|
|
- std::process::Command::new("cmd")
|
|
|
- .args(["/C", "start", "", url])
|
|
|
- .spawn()
|
|
|
- .map_err(|e| e.to_string())?;
|
|
|
- }
|
|
|
- #[cfg(target_os = "macos")]
|
|
|
- {
|
|
|
- std::process::Command::new("open")
|
|
|
- .arg(url)
|
|
|
- .spawn()
|
|
|
- .map_err(|e| e.to_string())?;
|
|
|
- }
|
|
|
- #[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
|
|
- {
|
|
|
- std::process::Command::new("xdg-open")
|
|
|
- .arg(url)
|
|
|
- .spawn()
|
|
|
- .map_err(|e| e.to_string())?;
|
|
|
- }
|
|
|
- Ok(())
|
|
|
+ Ok(serde_json::json!({ "status": "pending", "qrImage": qr.qr_image }))
|
|
|
}
|
|
|
|
|
|
#[tauri::command]
|