From bca3378c7d4916d1fa4862a01f39014dfa260e05 Mon Sep 17 00:00:00 2001 From: Guyutongxue Date: Tue, 16 Aug 2022 16:32:58 +0800 Subject: [PATCH] update --- CHANGELOG.md | 4 +++ src-tauri/src/gui.rs | 38 +++++++++++++++++++++++++++- src-tauri/src/main.rs | 2 ++ src-tauri/src/steps/compiler/msvc.rs | 4 +-- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4880a74..2cfd425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - 修复了 MSVC 的错误的问题匹配设置(`vscext` 分支) - CLI 增加了日志路径选项 +## v4.0.0-beta.11 +*2022.8.16* +- Windows 下检测 WebView 2 安装 + ## v4.0.0-beta.10 *2022.8.14* - 修复了点击“新手模式”在非 Windows 系统上导致的错误 diff --git a/src-tauri/src/gui.rs b/src-tauri/src/gui.rs index bc530e7..2ee0f72 100644 --- a/src-tauri/src/gui.rs +++ b/src-tauri/src/gui.rs @@ -16,7 +16,7 @@ // along with vscch4. If not, see . use anyhow::{anyhow, Result}; -use log::{debug, info, trace}; +use log::{debug, info, trace, warn}; use serde::Serialize; use crate::steps::{ @@ -25,7 +25,43 @@ use crate::steps::{ use crate::tasks; use crate::tasks::TaskInitArgs; +#[cfg(windows)] +fn has_webview2_installed() -> bool { + use crate::utils::winreg; + if let Some(v) = winreg::get( + winreg::HKEY_LOCAL_MACHINE, + r#"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"#, + "pv", + ) { + if v != "" && v != "0.0.0.0" { return true; } + } + if let Some(v) = winreg::get( + winreg::HKEY_CURRENT_USER, + r#"Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"#, + "pv", + ) { + if v != "" && v != "0.0.0.0" { return true; } + } + return false; +} + pub fn gui() -> Result<()> { + #[cfg(windows)] + { + if !has_webview2_installed() { + debug!("WebView 2 未安装"); + let download = native_dialog::MessageDialog::new() + .set_title("WebView 2 未安装") + .set_type(native_dialog::MessageType::Warning) + .set_text("您的系统可能尚未安装 WebView 2。这表明您可能无法正常运行图形界面。\n 点击“确认”以前往 WebView 2 下载页面,并退出程序;\n 点击“取消”以继续尝试运行本程序。") + .show_confirm()?; + if download { + open::that("https://go.microsoft.com/fwlink/p/?LinkId=2124703")?; + std::process::exit(1); + } + warn!("用户执意执行 GUI。"); + } + } debug!("即将启动 tauri GUI。"); tauri::Builder::default() .invoke_handler(tauri::generate_handler![ diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4bdce08..632db91 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -32,6 +32,7 @@ fn handle_error(e: Error) -> ! { native_dialog::MessageDialog::new() .set_title("程序已报告错误") .set_text(&format!("{}\n您可以将代码 “{}” 发送至 guyutongxue@163.com,开发者会尽快帮您解决问题。\n(使用 --no-stats 选项以关闭此弹窗。)", e.to_string(), &id[0..6])) + .set_type(native_dialog::MessageType::Error) .show_alert() .unwrap(); } @@ -40,6 +41,7 @@ fn handle_error(e: Error) -> ! { native_dialog::MessageDialog::new() .set_title("日志未就绪前出现错误") .set_text(&format!("{:?}", e)) + .set_type(native_dialog::MessageType::Error) .show_alert() .unwrap(); } else { diff --git a/src-tauri/src/steps/compiler/msvc.rs b/src-tauri/src/steps/compiler/msvc.rs index a738ed1..2566164 100644 --- a/src-tauri/src/steps/compiler/msvc.rs +++ b/src-tauri/src/steps/compiler/msvc.rs @@ -84,7 +84,7 @@ fn scan() -> Vec { return vec![]; } let vswhere = vswhere.unwrap(); - debug!("vswhere.exe is {:?}", vswhere); + debug!("vswhere.exe 路径:{:?}", vswhere); #[derive(Deserialize)] #[serde(rename_all = "camelCase")] @@ -111,7 +111,7 @@ fn scan() -> Vec { // 受 https://github.com/microsoft/vswhere/issues/262 影响,某些 vswhere 可能存在编码错误 let s = String::from_utf8_lossy(&o.stdout) .into_owned(); - debug!("vswhere.exe output: {}", s); + debug!("vswhere.exe 输出:{}", s); serde_json::from_str(&s).ok() }); if list.is_none() {