mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-25 03:33:36 +03:00
fix(bundler): migrate WebView2 offline installer to shorturl (#8292)
This commit is contained in:
parent
c34710de67
commit
977a39f4f7
5
.changes/migrate-webview2-offline-shorturl.md
Normal file
5
.changes/migrate-webview2-offline-shorturl.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-bundler": 'patch:bug'
|
||||
---
|
||||
|
||||
Migrate the WebView2 offline installer to use shorturl provided by Microsoft.
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
_ => {}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user