Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changes/feat-add-utis-support-for-fileassociation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"tauri-bundler": "minor:feat"
"tauri-utils": "minor:feat"
"tauri-cli": "minor:feat"
"@tauri-apps/cli": "minor:feat"
---

Feat: add `LSItemContentTypes` and `CFBundleTypeIconFile` support for `fileAssociations` on macOS.
14 changes: 14 additions & 0 deletions crates/tauri-bundler/src/bundle/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ fn create_info_plist(
association.role.to_string().into(),
);
dict.insert("LSHandlerRank".into(), association.rank.to_string().into());
if let Some(item_content_types) = &association.item_content_types {
dict.insert(
"LSItemContentTypes".into(),
plist::Value::Array(
item_content_types
.iter()
.map(|uti| uti.to_string().into())
.collect(),
),
);
}
if let Some(icns) = &association.icon_file {
dict.insert("CFBundleTypeIconFile".into(), icns.to_string().into());
}
plist::Value::Dictionary(dict)
})
.collect(),
Expand Down
21 changes: 21 additions & 0 deletions crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,23 @@
"$ref": "#/definitions/HandlerRank"
}
]
},
"itemContentTypes": {
"description": "The document file types the app supports. Maps to `LSItemContentTypes` on macOS.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/UniformTypeIdentifiers"
}
},
"iconFile": {
"description": "This key contains a string with the name of the icon file (.icns) to associate with this macOS document type. Maps to `CFBundleTypeIconFile` on macOS.\n For more information about specifying document icons, see [Document Icons](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9).",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2435,6 +2452,10 @@
}
]
},
"UniformTypeIdentifiers": {
"description": "Provide uniform type identifiers that describe file types for storage or transfer.",
"type": "string"
},
"WindowsConfig": {
"description": "Windows bundler configuration.\n\n See more: <https://v2.tauri.app/reference/config/#windowsconfig>",
"type": "object",
Expand Down
21 changes: 21 additions & 0 deletions crates/tauri-cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,23 @@
"$ref": "#/definitions/HandlerRank"
}
]
},
"itemContentTypes": {
"description": "The document file types the app supports. Maps to `LSItemContentTypes` on macOS.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/UniformTypeIdentifiers"
}
},
"iconFile": {
"description": "This key contains a string with the name of the icon file (.icns) to associate with this macOS document type. Maps to `CFBundleTypeIconFile` on macOS.\n For more information about specifying document icons, see [Document Icons](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9).",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2056,6 +2073,10 @@
}
]
},
"UniformTypeIdentifiers": {
"description": "Provide uniform type identifiers that describe file types for storage or transfer.",
"type": "string"
},
"WindowsConfig": {
"description": "Windows bundler configuration.\n\n See more: <https://tauri.app/v1/api/config#windowsconfig>",
"type": "object",
Expand Down
21 changes: 21 additions & 0 deletions crates/tauri-cli/tauri.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,23 @@
"$ref": "#/definitions/HandlerRank"
}
]
},
"itemContentTypes": {
"description": "The document file types the app supports. Maps to `LSItemContentTypes` on macOS.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/UniformTypeIdentifiers"
}
},
"iconFile": {
"description": "This key contains a string with the name of the icon file (.icns) to associate with this macOS document type. Maps to `CFBundleTypeIconFile` on macOS.\n For more information about specifying document icons, see [Document Icons](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9).",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2056,6 +2073,10 @@
}
]
},
"UniformTypeIdentifiers": {
"description": "Provide uniform type identifiers that describe file types for storage or transfer.",
"type": "string"
},
"WindowsConfig": {
"description": "Windows bundler configuration.\n\n See more: <https://tauri.app/v1/api/config#windowsconfig>",
"type": "object",
Expand Down
21 changes: 21 additions & 0 deletions crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,23 @@
"$ref": "#/definitions/HandlerRank"
}
]
},
"itemContentTypes": {
"description": "The document file types the app supports. Maps to `LSItemContentTypes` on macOS.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/UniformTypeIdentifiers"
}
},
"iconFile": {
"description": "This key contains a string with the name of the icon file (.icns) to associate with this macOS document type. Maps to `CFBundleTypeIconFile` on macOS.\n For more information about specifying document icons, see [Document Icons](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9).",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2435,6 +2452,10 @@
}
]
},
"UniformTypeIdentifiers": {
"description": "Provide uniform type identifiers that describe file types for storage or transfer.",
"type": "string"
},
"WindowsConfig": {
"description": "Windows bundler configuration.\n\n See more: <https://v2.tauri.app/reference/config/#windowsconfig>",
"type": "object",
Expand Down
23 changes: 23 additions & 0 deletions crates/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,24 @@ impl Display for HandlerRank {
}
}

/// Provide uniform type identifiers that describe file types for storage or transfer.
#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub struct UniformTypeIdentifiers(pub String);

impl fmt::Display for UniformTypeIdentifiers {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

impl<'d> serde::Deserialize<'d> for UniformTypeIdentifiers {
fn deserialize<D: Deserializer<'d>>(deserializer: D) -> Result<Self, D::Error> {
let uti = String::deserialize(deserializer)?;
Ok(UniformTypeIdentifiers(uti))
}
}

/// An extension for a [`FileAssociation`].
///
/// A leading `.` is automatically stripped.
Expand Down Expand Up @@ -1162,6 +1180,11 @@ pub struct FileAssociation {
/// The ranking of this app among apps that declare themselves as editors or viewers of the given file type. Maps to `LSHandlerRank` on macOS.
#[serde(default)]
pub rank: HandlerRank,
/// The document file types the app supports. Maps to `LSItemContentTypes` on macOS.
pub item_content_types: Option<Vec<UniformTypeIdentifiers>>,
/// This key contains a string with the name of the icon file (.icns) to associate with this macOS document type. Maps to `CFBundleTypeIconFile` on macOS.
/// For more information about specifying document icons, see [Document Icons](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9).
pub icon_file: Option<String>,
}

/// Deep link protocol configuration.
Expand Down
4 changes: 3 additions & 1 deletion examples/file-associations/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
{
"ext": ["png"],
"mimeType": "image/png",
"rank": "Default"
"rank": "Default",
"itemContentTypes": ["public.png"],
"iconFile": ""
},
{
"ext": ["jpg", "jpeg"],
Expand Down
Loading