Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2.6.0", features = [] }
embed-resource = "3"

[dependencies]
serde_json = "1.0"
Expand Down
33 changes: 32 additions & 1 deletion src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
fn main() {
tauri_build::build()
let mut attributes = tauri_build::Attributes::new();
// tauri-build links its Windows app manifest into binaries only, but the unit test executable
// links the same Tauri and dialog code. Without the manifest's Common Controls v6 dependency it
// fails to start with STATUS_ENTRYPOINT_NOT_FOUND. So embed the manifest ourselves, in every
// target.
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
if target_os == "windows" && target_env == "msvc" {
attributes = attributes
.windows_attributes(tauri_build::WindowsAttributes::new_without_app_manifest());
embed_manifest_in_every_target();
}
tauri_build::try_build(attributes).expect("failed to run tauri-build");
}

/// Writes tauri-build's default manifest into a resource script in tauri-winres' format, so the
/// app's embedded manifest bytes do not change, then links it into tests and libraries as well as
/// binaries. `windows/app-manifest.xml` is a verbatim copy of tauri-build 2.6.3's
/// `windows-app-manifest.xml`; re-diff it when upgrading tauri-build. Only `"` is escaped, the
/// one character tauri-winres escapes that the manifest contains.
fn embed_manifest_in_every_target() {
let manifest = include_str!("windows/app-manifest.xml");
let mut script = String::from("#pragma code_page(65001)\n1 24\n{\n");
for line in manifest.lines() {
script.push_str(&format!("\" {} \"\n", line.trim().replace('"', "\"\"")));
}
script.push_str("}\n");
let path = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("app-manifest.rc");
std::fs::write(&path, script).expect("failed to write the manifest resource script");
embed_resource::compile_for_everything(&path, embed_resource::NONE)
.manifest_required()
.expect("failed to compile the manifest resource");
}
12 changes: 10 additions & 2 deletions src-tauri/src/safe_save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ fn commit_temp(temp: &Path, destination: &Path) -> Result<(), String> {
/// Whether the path is in the app's local data folder, which holds the webview data that the fs
/// plugin denies the webview by default.
fn is_in_app_local_data<R: Runtime>(app: &AppHandle<R>, path: &Path) -> bool {
let canonical =
|path: &Path| std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
// Canonicalize the deepest folder that exists, so both sides compare in the same form even
// when one is missing (on Windows, canonical paths gain a `\\?\` prefix).
let canonical = |path: &Path| {
path.ancestors()
.find_map(|ancestor| {
let rest = path.strip_prefix(ancestor).ok()?;
Some(std::fs::canonicalize(ancestor).ok()?.join(rest))
})
.unwrap_or_else(|| path.to_path_buf())
};
match (app.path().app_local_data_dir(), path.parent()) {
(Ok(data), Some(directory)) => canonical(directory).starts_with(canonical(&data)),
_ => false,
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/windows/app-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
Loading