浏览代码

fix(bundler): detect per-user webview2 installations (#3076)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
FabianLars 3 年之前
父节点
当前提交
3206a7088c
共有 2 个文件被更改,包括 27 次插入13 次删除
  1. 2 1
      tooling/bundler/src/bundle/windows/templates/main.wxs
  2. 25 12
      tooling/cli.rs/src/info.rs

+ 2 - 1
tooling/bundler/src/bundle/windows/templates/main.wxs

@@ -219,7 +219,8 @@
         {{#if install_webview}}
         <!-- WebView2 -->
         <Property Id="WVRTINSTALLED">
-            <RegistrySearch Id="WVRTInstalled" Root="HKLM" Key="SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" Name="pv" Type="raw" Win64="no"/>
+            <RegistrySearch Id="WVRTInstalledSystem" Root="HKLM" Key="SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" Name="pv" Type="raw" Win64="no" />
+            <RegistrySearch Id="WVRTInstalledUser" Root="HKCU" Key="SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" Name="pv" Type="raw"/>
         </Property>
         <CustomAction Id='DownloadAndInvokeBootstrapper' Directory="INSTALLDIR" Execute="deferred" ExeCommand='powershell.exe -NoProfile -windowstyle hidden Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; &amp; $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install' Return='check'/>
         <InstallExecuteSequence>

+ 25 - 12
tooling/cli.rs/src/info.rs

@@ -271,25 +271,38 @@ fn get_version(command: &str, args: &[&str]) -> crate::Result<Option<String>> {
 
 #[cfg(windows)]
 fn webview2_version() -> crate::Result<Option<String>> {
+  // check 64bit machine-wide installation
   let output = Command::new("powershell")
       .args(&["-NoProfile", "-Command"])
       .arg("Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
       .output()?;
-  let version = if output.status.success() {
-    Some(String::from_utf8_lossy(&output.stdout).replace('\n', ""))
-  } else {
-    // check 32bit installation
-    let output = Command::new("powershell")
+  if output.status.success() {
+    return Ok(Some(
+      String::from_utf8_lossy(&output.stdout).replace('\n', ""),
+    ));
+  }
+  // check 32bit machine-wide installation
+  let output = Command::new("powershell")
         .args(&["-NoProfile", "-Command"])
         .arg("Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
         .output()?;
-    if output.status.success() {
-      Some(String::from_utf8_lossy(&output.stdout).replace('\n', ""))
-    } else {
-      None
-    }
-  };
-  Ok(version)
+  if output.status.success() {
+    return Ok(Some(
+      String::from_utf8_lossy(&output.stdout).replace('\n', ""),
+    ));
+  }
+  // check user-wide installation
+  let output = Command::new("powershell")
+      .args(&["-NoProfile", "-Command"])
+      .arg("Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
+      .output()?;
+  if output.status.success() {
+    return Ok(Some(
+      String::from_utf8_lossy(&output.stdout).replace('\n', ""),
+    ));
+  }
+
+  Ok(None)
 }
 
 #[cfg(windows)]