Skip to content

Commit 977a39f

Browse files
authored
fix(bundler): migrate WebView2 offline installer to shorturl (#8292)
1 parent c34710d commit 977a39f

File tree

4 files changed

+65
-65
lines changed

4 files changed

+65
-65
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": 'patch:bug'
3+
---
4+
5+
Migrate the WebView2 offline installer to use shorturl provided by Microsoft.

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use crate::bundle::{
1010
windows::{
1111
sign::try_sign,
1212
util::{
13-
download, download_and_verify, extract_zip, HashAlgorithm, WEBVIEW2_BOOTSTRAPPER_URL,
14-
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID, WEBVIEW2_X86_OFFLINE_INSTALLER_GUID,
15-
WIX_OUTPUT_FOLDER_NAME, WIX_UPDATER_OUTPUT_FOLDER_NAME,
13+
download_and_verify, download_webview2_bootstrapper, download_webview2_offline_installer,
14+
extract_zip, HashAlgorithm, WIX_OUTPUT_FOLDER_NAME, WIX_UPDATER_OUTPUT_FOLDER_NAME,
1615
},
1716
},
1817
};
@@ -473,42 +472,15 @@ pub fn build_wix_app_installer(
473472
);
474473
}
475474
WebviewInstallMode::EmbedBootstrapper { silent: _ } => {
476-
let webview2_bootstrapper_path = output_path.join("MicrosoftEdgeWebview2Setup.exe");
477-
std::fs::write(
478-
&webview2_bootstrapper_path,
479-
download(WEBVIEW2_BOOTSTRAPPER_URL)?,
480-
)?;
475+
let webview2_bootstrapper_path = download_webview2_bootstrapper(&output_path)?;
481476
data.insert(
482477
"webview2_bootstrapper_path",
483478
to_json(webview2_bootstrapper_path),
484479
);
485480
}
486481
WebviewInstallMode::OfflineInstaller { silent: _ } => {
487-
let guid = if arch == "x64" {
488-
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID
489-
} else {
490-
WEBVIEW2_X86_OFFLINE_INSTALLER_GUID
491-
};
492-
let offline_installer_path = dirs_next::cache_dir()
493-
.unwrap()
494-
.join("tauri")
495-
.join("Webview2OfflineInstaller")
496-
.join(guid)
497-
.join(arch);
498-
create_dir_all(&offline_installer_path)?;
499482
let webview2_installer_path =
500-
offline_installer_path.join("MicrosoftEdgeWebView2RuntimeInstaller.exe");
501-
if !webview2_installer_path.exists() {
502-
std::fs::write(
503-
&webview2_installer_path,
504-
download(
505-
&format!("https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/{}/MicrosoftEdgeWebView2RuntimeInstaller{}.exe",
506-
guid,
507-
arch.to_uppercase(),
508-
),
509-
)?,
510-
)?;
511-
}
483+
download_webview2_offline_installer(&output_path.join(arch), arch)?;
512484
data.insert("webview2_installer_path", to_json(webview2_installer_path));
513485
}
514486
}

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::{
88
bundle::{
99
common::CommandExt,
1010
windows::util::{
11-
download, download_and_verify, extract_zip, HashAlgorithm, NSIS_OUTPUT_FOLDER_NAME,
12-
NSIS_UPDATER_OUTPUT_FOLDER_NAME, WEBVIEW2_BOOTSTRAPPER_URL,
13-
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID, WEBVIEW2_X86_OFFLINE_INSTALLER_GUID,
11+
download, download_and_verify, download_webview2_bootstrapper,
12+
download_webview2_offline_installer, extract_zip, HashAlgorithm, NSIS_OUTPUT_FOLDER_NAME,
13+
NSIS_UPDATER_OUTPUT_FOLDER_NAME,
1414
},
1515
},
1616
Settings,
@@ -370,40 +370,15 @@ fn build_nsis_app_installer(
370370

371371
match webview2_install_mode {
372372
WebviewInstallMode::EmbedBootstrapper { silent: _ } => {
373-
let webview2_bootstrapper_path = tauri_tools_path.join("MicrosoftEdgeWebview2Setup.exe");
374-
std::fs::write(
375-
&webview2_bootstrapper_path,
376-
download(WEBVIEW2_BOOTSTRAPPER_URL)?,
377-
)?;
373+
let webview2_bootstrapper_path = download_webview2_bootstrapper(tauri_tools_path)?;
378374
data.insert(
379375
"webview2_bootstrapper_path",
380376
to_json(webview2_bootstrapper_path),
381377
);
382378
}
383379
WebviewInstallMode::OfflineInstaller { silent: _ } => {
384-
let guid = if arch == "x64" {
385-
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID
386-
} else {
387-
WEBVIEW2_X86_OFFLINE_INSTALLER_GUID
388-
};
389-
let offline_installer_path = tauri_tools_path
390-
.join("Webview2OfflineInstaller")
391-
.join(guid)
392-
.join(arch);
393-
create_dir_all(&offline_installer_path)?;
394380
let webview2_installer_path =
395-
offline_installer_path.join("MicrosoftEdgeWebView2RuntimeInstaller.exe");
396-
if !webview2_installer_path.exists() {
397-
std::fs::write(
398-
&webview2_installer_path,
399-
download(
400-
&format!("https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/{}/MicrosoftEdgeWebView2RuntimeInstaller{}.exe",
401-
guid,
402-
arch.to_uppercase(),
403-
),
404-
)?,
405-
)?;
406-
}
381+
download_webview2_offline_installer(&tauri_tools_path.join(arch), arch)?;
407382
data.insert("webview2_installer_path", to_json(webview2_installer_path));
408383
}
409384
_ => {}

tooling/bundler/src/bundle/windows/util.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,69 @@
55
use std::{
66
fs::{create_dir_all, File},
77
io::{Cursor, Read, Write},
8-
path::Path,
8+
path::{Path, PathBuf},
99
};
1010

1111
use log::info;
1212
use sha2::Digest;
1313
use zip::ZipArchive;
1414

1515
pub const WEBVIEW2_BOOTSTRAPPER_URL: &str = "https://go.microsoft.com/fwlink/p/?LinkId=2124703";
16-
pub const WEBVIEW2_X86_OFFLINE_INSTALLER_GUID: &str = "2c122012-898d-4a69-9ab6-aa50bbe81031";
17-
pub const WEBVIEW2_X64_OFFLINE_INSTALLER_GUID: &str = "0af26c79-02f0-4f06-a12d-116bc05ca860";
16+
pub const WEBVIEW2_OFFLINE_INSTALLER_X86_URL: &str =
17+
"https://go.microsoft.com/fwlink/?linkid=2099617";
18+
pub const WEBVIEW2_OFFLINE_INSTALLER_X64_URL: &str =
19+
"https://go.microsoft.com/fwlink/?linkid=2124701";
20+
pub const WEBVIEW2_URL_PREFIX: &str =
21+
"https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/";
1822
pub const NSIS_OUTPUT_FOLDER_NAME: &str = "nsis";
1923
pub const NSIS_UPDATER_OUTPUT_FOLDER_NAME: &str = "nsis-updater";
2024
pub const WIX_OUTPUT_FOLDER_NAME: &str = "msi";
2125
pub const WIX_UPDATER_OUTPUT_FOLDER_NAME: &str = "msi-updater";
2226

27+
pub fn webview2_guid_path(url: &str) -> crate::Result<(String, String)> {
28+
let agent = ureq::AgentBuilder::new().try_proxy_from_env(true).build();
29+
let response = agent.head(url).call().map_err(Box::new)?;
30+
let final_url = response.get_url();
31+
let remaining_url = final_url.strip_prefix(WEBVIEW2_URL_PREFIX).ok_or_else(|| {
32+
anyhow::anyhow!(
33+
"WebView2 URL prefix mismatch. Expected `{}`, found `{}`.",
34+
WEBVIEW2_URL_PREFIX,
35+
final_url
36+
)
37+
})?;
38+
let (guid, filename) = remaining_url.split_once('/').ok_or_else(|| {
39+
anyhow::anyhow!(
40+
"WebView2 URL format mismatch. Expected `<GUID>/<FILENAME>`, found `{}`.",
41+
remaining_url
42+
)
43+
})?;
44+
Ok((guid.into(), filename.into()))
45+
}
46+
47+
pub fn download_webview2_bootstrapper(base_path: &Path) -> crate::Result<PathBuf> {
48+
let file_path = base_path.join("MicrosoftEdgeWebview2Setup.exe");
49+
if !file_path.exists() {
50+
std::fs::write(&file_path, download(WEBVIEW2_BOOTSTRAPPER_URL)?)?;
51+
}
52+
Ok(file_path)
53+
}
54+
55+
pub fn download_webview2_offline_installer(base_path: &Path, arch: &str) -> crate::Result<PathBuf> {
56+
let url = if arch == "x64" {
57+
WEBVIEW2_OFFLINE_INSTALLER_X64_URL
58+
} else {
59+
WEBVIEW2_OFFLINE_INSTALLER_X86_URL
60+
};
61+
let (guid, filename) = webview2_guid_path(url)?;
62+
let dir_path = base_path.join(guid);
63+
let file_path = dir_path.join(filename);
64+
if !file_path.exists() {
65+
create_dir_all(dir_path)?;
66+
std::fs::write(&file_path, download(url)?)?;
67+
}
68+
Ok(file_path)
69+
}
70+
2371
pub fn download(url: &str) -> crate::Result<Vec<u8>> {
2472
info!(action = "Downloading"; "{}", url);
2573

0 commit comments

Comments
 (0)