mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 04:37:29 -06:00
Fix #295: open files from the macOS Finder and Dock
Finder, Open With, a drop on the Dock icon and `open -a` failed with "VectorCraft cannot open files in the PDF document format": - The release Info.plist declared no document types, so Launch Services refused the files before the app saw them. Info.plist.in now declares every format File › Open reads (the engine's OPEN_EXTS; a test keeps them in step): VectorCraft owns its own documents and templates and is an alternate for the others, so it takes over no other app's files. `cargo xtask bundle` now fills in the same template instead of its own, shorter plist. - macOS delivers such files as open-document events, not arguments. winit 0.30's application delegate has no `application:openURLs:`, so AppKit fell back to NSDocumentController, which refuses every file of a non-NSDocument app (the error in both issues). The new `open_documents` module adds that method to the delegate's class when the app is about to finish launching (before AppKit delivers launch files), queues the paths and wakes the UI, which opens them with `io::open_path` like command-line files; errors go to the status bar too. New direct macOS dependencies `objc2-foundation` 0.3 and `block2` 0.6 were already in Cargo.lock (through winit, muda and rfd). The module allows `unsafe_code` for the Objective-C runtime call. Fixes #354 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
accfec7146
commit
b2c6764472
+16
-29
@@ -21,35 +21,20 @@ pub fn run(root: &Path) -> Result<(), String> {
|
||||
std::fs::copy(target.join("release/vectorcraft"), app.join("MacOS/VectorCraft")).map_err(|e| format!("copy app: {e}"))?;
|
||||
std::fs::copy(target.join("release/vectorcraft-cli"), app.join("MacOS/vectorcraft-cli")).map_err(|e| format!("copy cli: {e}"))?;
|
||||
std::fs::copy(root.join("assets/app-icon/vectorcraft.icns"), app.join("Resources/VectorCraft.icns")).map_err(|e| format!("copy icon: {e}"))?;
|
||||
std::fs::write(app.join("Info.plist"), info_plist(env!("CARGO_PKG_VERSION"))).map_err(|e| e.to_string())?;
|
||||
let sha = std::env::var("VECTORCRAFT_BUILD_SHA").unwrap_or_else(|_| "unknown".into());
|
||||
std::fs::write(app.join("Info.plist"), info_plist(env!("CARGO_PKG_VERSION"), &sha)).map_err(|e| e.to_string())?;
|
||||
println!("built {}", root.join("dist/VectorCraft.app").display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The development bundle's `Info.plist`.
|
||||
fn info_plist(version: &str) -> String {
|
||||
format!(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict>
|
||||
<key>CFBundleName</key><string>VectorCraft</string>
|
||||
<key>CFBundleDisplayName</key><string>VectorCraft</string>
|
||||
<key>CFBundleIdentifier</key><string>ai.storyteller.vectorcraft</string>
|
||||
<key>CFBundleExecutable</key><string>VectorCraft</string>
|
||||
<key>CFBundleIconFile</key><string>VectorCraft</string>
|
||||
<key>CFBundlePackageType</key><string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key><string>{version}</string>
|
||||
<key>CFBundleVersion</key><string>{version}</string>
|
||||
<key>NSHighResolutionCapable</key><true/>
|
||||
<key>LSMinimumSystemVersion</key><string>11.0</string>
|
||||
<key>CFBundleDocumentTypes</key><array>
|
||||
<dict><key>CFBundleTypeName</key><string>VectorCraft Document</string><key>CFBundleTypeExtensions</key><array><string>vectorcraft</string></array><key>CFBundleTypeRole</key><string>Editor</string></dict>
|
||||
<dict><key>CFBundleTypeName</key><string>SVG</string><key>CFBundleTypeExtensions</key><array><string>svg</string></array><key>CFBundleTypeRole</key><string>Editor</string></dict>
|
||||
<dict><key>CFBundleTypeName</key><string>PDF Document</string><key>CFBundleTypeExtensions</key><array><string>pdf</string><string>ai</string></array><key>CFBundleTypeRole</key><string>Viewer</string></dict>
|
||||
</array>
|
||||
</dict></plist>
|
||||
"#
|
||||
)
|
||||
/// The release `Info.plist` template, which `packaging/macos/package.sh` fills in the same way: the
|
||||
/// development bundle declares the same document types (Finder opens them with the app).
|
||||
const INFO_PLIST: &str = include_str!("../../packaging/macos/Info.plist.in");
|
||||
|
||||
/// The bundle's `Info.plist`: [`INFO_PLIST`] for `version` and the build commit `sha`.
|
||||
fn info_plist(version: &str, sha: &str) -> String {
|
||||
let short = version.split('-').next().unwrap_or(version);
|
||||
INFO_PLIST.replace("@VERSION@", version).replace("@SHORT_VERSION@", short).replace("@BUILD_SHA@", sha)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -88,9 +73,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dev_bundle_plist_names_types_neutrally() {
|
||||
let p = info_plist("1.2.3");
|
||||
assert!(p.contains("<key>CFBundleShortVersionString</key><string>1.2.3</string>"));
|
||||
assert!(p.contains("<string>VectorCraft Document</string>") && p.contains("<string>PDF Document</string>"));
|
||||
fn dev_bundle_plist_is_the_release_one() {
|
||||
let p = info_plist("1.2.3-rc.1", "abc123");
|
||||
assert!(p.contains("<string>1.2.3</string>") && p.contains("<string>1.2.3-rc.1</string>"), "{p}");
|
||||
assert!(p.contains("<string>abc123</string>"));
|
||||
assert!(!p.contains('@'), "every placeholder filled");
|
||||
assert!(p.contains("<key>CFBundleDocumentTypes</key>") && p.contains("<string>pdf</string>"), "Finder opens files with it");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user