fix(bundler): migrate WebView2 offline installer to shorturl (#8292)

This commit is contained in:
i-c-b 2023-11-28 20:51:42 -05:00 committed by GitHub
parent c34710de67
commit 977a39f4f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 65 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-bundler": 'patch:bug'
---
Migrate the WebView2 offline installer to use shorturl provided by Microsoft.

View File

@ -10,9 +10,8 @@ use crate::bundle::{
windows::{
sign::try_sign,
util::{
download, download_and_verify, extract_zip, HashAlgorithm, WEBVIEW2_BOOTSTRAPPER_URL,
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID, WEBVIEW2_X86_OFFLINE_INSTALLER_GUID,
WIX_OUTPUT_FOLDER_NAME, WIX_UPDATER_OUTPUT_FOLDER_NAME,
download_and_verify, download_webview2_bootstrapper, download_webview2_offline_installer,
extract_zip, HashAlgorithm, WIX_OUTPUT_FOLDER_NAME, WIX_UPDATER_OUTPUT_FOLDER_NAME,
},
},
};
@ -473,42 +472,15 @@ pub fn build_wix_app_installer(
);
}
WebviewInstallMode::EmbedBootstrapper { silent: _ } => {
let webview2_bootstrapper_path = output_path.join("MicrosoftEdgeWebview2Setup.exe");
std::fs::write(
&webview2_bootstrapper_path,
download(WEBVIEW2_BOOTSTRAPPER_URL)?,
)?;
let webview2_bootstrapper_path = download_webview2_bootstrapper(&output_path)?;
data.insert(
"webview2_bootstrapper_path",
to_json(webview2_bootstrapper_path),
);
}
WebviewInstallMode::OfflineInstaller { silent: _ } => {
let guid = if arch == "x64" {
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID
} else {
WEBVIEW2_X86_OFFLINE_INSTALLER_GUID
};
let offline_installer_path = dirs_next::cache_dir()
.unwrap()
.join("tauri")
.join("Webview2OfflineInstaller")
.join(guid)
.join(arch);
create_dir_all(&offline_installer_path)?;
let webview2_installer_path =
offline_installer_path.join("MicrosoftEdgeWebView2RuntimeInstaller.exe");
if !webview2_installer_path.exists() {
std::fs::write(
&webview2_installer_path,
download(
&format!("https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/{}/MicrosoftEdgeWebView2RuntimeInstaller{}.exe",
guid,
arch.to_uppercase(),
),
)?,
)?;
}
download_webview2_offline_installer(&output_path.join(arch), arch)?;
data.insert("webview2_installer_path", to_json(webview2_installer_path));
}
}

View File

@ -8,9 +8,9 @@ use crate::{
bundle::{
common::CommandExt,
windows::util::{
download, download_and_verify, extract_zip, HashAlgorithm, NSIS_OUTPUT_FOLDER_NAME,
NSIS_UPDATER_OUTPUT_FOLDER_NAME, WEBVIEW2_BOOTSTRAPPER_URL,
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID, WEBVIEW2_X86_OFFLINE_INSTALLER_GUID,
download, download_and_verify, download_webview2_bootstrapper,
download_webview2_offline_installer, extract_zip, HashAlgorithm, NSIS_OUTPUT_FOLDER_NAME,
NSIS_UPDATER_OUTPUT_FOLDER_NAME,
},
},
Settings,
@ -370,40 +370,15 @@ fn build_nsis_app_installer(
match webview2_install_mode {
WebviewInstallMode::EmbedBootstrapper { silent: _ } => {
let webview2_bootstrapper_path = tauri_tools_path.join("MicrosoftEdgeWebview2Setup.exe");
std::fs::write(
&webview2_bootstrapper_path,
download(WEBVIEW2_BOOTSTRAPPER_URL)?,
)?;
let webview2_bootstrapper_path = download_webview2_bootstrapper(tauri_tools_path)?;
data.insert(
"webview2_bootstrapper_path",
to_json(webview2_bootstrapper_path),
);
}
WebviewInstallMode::OfflineInstaller { silent: _ } => {
let guid = if arch == "x64" {
WEBVIEW2_X64_OFFLINE_INSTALLER_GUID
} else {
WEBVIEW2_X86_OFFLINE_INSTALLER_GUID
};
let offline_installer_path = tauri_tools_path
.join("Webview2OfflineInstaller")
.join(guid)
.join(arch);
create_dir_all(&offline_installer_path)?;
let webview2_installer_path =
offline_installer_path.join("MicrosoftEdgeWebView2RuntimeInstaller.exe");
if !webview2_installer_path.exists() {
std::fs::write(
&webview2_installer_path,
download(
&format!("https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/{}/MicrosoftEdgeWebView2RuntimeInstaller{}.exe",
guid,
arch.to_uppercase(),
),
)?,
)?;
}
download_webview2_offline_installer(&tauri_tools_path.join(arch), arch)?;
data.insert("webview2_installer_path", to_json(webview2_installer_path));
}
_ => {}

View File

@ -5,7 +5,7 @@
use std::{
fs::{create_dir_all, File},
io::{Cursor, Read, Write},
path::Path,
path::{Path, PathBuf},
};
use log::info;
@ -13,13 +13,61 @@ use sha2::Digest;
use zip::ZipArchive;
pub const WEBVIEW2_BOOTSTRAPPER_URL: &str = "https://go.microsoft.com/fwlink/p/?LinkId=2124703";
pub const WEBVIEW2_X86_OFFLINE_INSTALLER_GUID: &str = "2c122012-898d-4a69-9ab6-aa50bbe81031";
pub const WEBVIEW2_X64_OFFLINE_INSTALLER_GUID: &str = "0af26c79-02f0-4f06-a12d-116bc05ca860";
pub const WEBVIEW2_OFFLINE_INSTALLER_X86_URL: &str =
"https://go.microsoft.com/fwlink/?linkid=2099617";
pub const WEBVIEW2_OFFLINE_INSTALLER_X64_URL: &str =
"https://go.microsoft.com/fwlink/?linkid=2124701";
pub const WEBVIEW2_URL_PREFIX: &str =
"https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/";
pub const NSIS_OUTPUT_FOLDER_NAME: &str = "nsis";
pub const NSIS_UPDATER_OUTPUT_FOLDER_NAME: &str = "nsis-updater";
pub const WIX_OUTPUT_FOLDER_NAME: &str = "msi";
pub const WIX_UPDATER_OUTPUT_FOLDER_NAME: &str = "msi-updater";
pub fn webview2_guid_path(url: &str) -> crate::Result<(String, String)> {
let agent = ureq::AgentBuilder::new().try_proxy_from_env(true).build();
let response = agent.head(url).call().map_err(Box::new)?;
let final_url = response.get_url();
let remaining_url = final_url.strip_prefix(WEBVIEW2_URL_PREFIX).ok_or_else(|| {
anyhow::anyhow!(
"WebView2 URL prefix mismatch. Expected `{}`, found `{}`.",
WEBVIEW2_URL_PREFIX,
final_url
)
})?;
let (guid, filename) = remaining_url.split_once('/').ok_or_else(|| {
anyhow::anyhow!(
"WebView2 URL format mismatch. Expected `<GUID>/<FILENAME>`, found `{}`.",
remaining_url
)
})?;
Ok((guid.into(), filename.into()))
}
pub fn download_webview2_bootstrapper(base_path: &Path) -> crate::Result<PathBuf> {
let file_path = base_path.join("MicrosoftEdgeWebview2Setup.exe");
if !file_path.exists() {
std::fs::write(&file_path, download(WEBVIEW2_BOOTSTRAPPER_URL)?)?;
}
Ok(file_path)
}
pub fn download_webview2_offline_installer(base_path: &Path, arch: &str) -> crate::Result<PathBuf> {
let url = if arch == "x64" {
WEBVIEW2_OFFLINE_INSTALLER_X64_URL
} else {
WEBVIEW2_OFFLINE_INSTALLER_X86_URL
};
let (guid, filename) = webview2_guid_path(url)?;
let dir_path = base_path.join(guid);
let file_path = dir_path.join(filename);
if !file_path.exists() {
create_dir_all(dir_path)?;
std::fs::write(&file_path, download(url)?)?;
}
Ok(file_path)
}
pub fn download(url: &str) -> crate::Result<Vec<u8>> {
info!(action = "Downloading"; "{}", url);