Skip to content

Commit

Permalink
fix(bundler) webview dll not being bundled, fixes #875 (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 24, 2020
1 parent bbccad4 commit a00ac02
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/webview-dll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Bundling every DLL file on the binary directory.
58 changes: 48 additions & 10 deletions cli/tauri-bundler/src/bundle/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ impl ResourceDirectory {
}
directories.push_str(wix_string.as_str());
}
let wix_string = format!(
r#"<Directory Id="{name}" Name="{name}">{contents}</Directory>"#,
name = self.name,
contents = format!("{}{}", files, directories)
);
let wix_string = if self.name == "" {
format!("{}{}", files, directories)
} else {
format!(
r#"<Directory Id="{name}" Name="{name}">{contents}</Directory>"#,
name = self.name,
contents = format!("{}{}", files, directories)
)
};

Ok((wix_string, file_ids))
}
Expand Down Expand Up @@ -215,7 +219,7 @@ fn app_installer_dir(settings: &Settings) -> crate::Result<PathBuf> {
}

/// Extracts the zips from Wix and VC_REDIST into a useable path.
fn extract_zip(data: &Vec<u8>, path: &Path) -> crate::Result<()> {
fn extract_zip(data: &[u8], path: &Path) -> crate::Result<()> {
let cursor = Cursor::new(data);

let mut zipa = ZipArchive::new(cursor)?;
Expand Down Expand Up @@ -377,7 +381,7 @@ fn run_light(
];

for p in wixobjs {
args.push(p.to_string());
args.push((*p).to_string());
}

let mut cmd = Command::new(&light_exe);
Expand Down Expand Up @@ -488,13 +492,13 @@ pub fn build_wix_app_installer(
let temp = HANDLEBARS.render("main.wxs", &data)?;

if output_path.exists() {
remove_dir_all(&output_path).or_else(|e| Err(e))?;
remove_dir_all(&output_path)?;
}

create_dir_all(&output_path).or_else(|e| Err(e))?;
create_dir_all(&output_path)?;

let main_wxs_path = output_path.join("main.wxs");
write(&main_wxs_path, temp).or_else(|e| Err(e))?;
write(&main_wxs_path, temp)?;

let input_basenames = vec!["main"];

Expand Down Expand Up @@ -565,6 +569,40 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
let mut resources = ResourceMap::new();
let regex = Regex::new(r"[^\w\d\.]")?;
let cwd = std::env::current_dir()?;

let mut dlls = vec![];
for dll in glob::glob(
settings
.project_out_directory()
.join("*.dll")
.to_string_lossy()
.to_string()
.as_str(),
)? {
let path = dll?;
let filename = path
.file_name()
.expect("failed to extract resource filename")
.to_os_string()
.into_string()
.expect("failed to convert resource filename to string");
dlls.push(ResourceFile {
guid: generate_guid(filename.as_bytes()).to_string(),
path: path.to_string_lossy().to_string(),
id: regex.replace_all(&filename, "").to_string(),
});
}
if !dlls.is_empty() {
resources.insert(
"".to_string(),
ResourceDirectory {
name: "".to_string(),
directories: vec![],
files: dlls,
},
);
}

for src in settings.resource_files() {
let src = src?;

Expand Down
2 changes: 1 addition & 1 deletion cli/tauri-bundler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn run() -> crate::Result<()> {
if !output_str.contains("win32webviewhost_cw5n1h2txyewy") {
println!("Running Loopback command");
Command::new("powershell")
.args(&vec![
.args(&[
"CheckNetIsolation LoopbackExempt -a -n=\"Microsoft.Win32WebViewHost_cw5n1h2txyewy\"",
])
.force_prompt(true)
Expand Down

0 comments on commit a00ac02

Please sign in to comment.