Skip to content

Commit 3b98141

Browse files
meowtecamrbashirlucasfernogRaphiikoFabianLars
authored
feat: add file association support, closes #3736 (#4320)
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Raphii <iam@raphii.co> Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 84c4159 commit 3b98141

File tree

43 files changed

+5566
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5566
-163
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": minor:feat
3+
---
4+
5+
Add a configuration object for file associations under `BundleConfig`.

.changes/file-associations.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor:feat
3+
---
4+
5+
Added support to file associations.

.changes/runtime-opened-event.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-runtime": minor:feat
3+
"tauri-runtime-wry": minor:feat
4+
---
5+
6+
Added the `Opened` variant to `RunEvent`.

.github/workflows/covector-version-or-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
steps.covector.outputs.successfulPublish == 'true' &&
122122
contains(steps.covector.outputs.packagesPublished, '@tauri-apps/cli')
123123
run: |
124-
echo '${{ steps.covector.outputs }}' > output.json
124+
echo '${{ toJSON(steps.covector.outputs) }}' > output.json
125125
id=$(jq '.["-tauri-apps-cli-releaseId"]' < output.json)
126126
rm output.json
127127
echo "cliReleaseId=$id" >> "$GITHUB_OUTPUT"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exclude = [
2020
"examples/resources/src-tauri",
2121
"examples/sidecar/src-tauri",
2222
"examples/web/core",
23+
"examples/file-associations/src-tauri",
2324
"examples/workspace",
2425
]
2526

core/tauri-config-schema/schema.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,16 @@
925925
"null"
926926
]
927927
},
928+
"fileAssociations": {
929+
"description": "File associations to application.",
930+
"type": [
931+
"array",
932+
"null"
933+
],
934+
"items": {
935+
"$ref": "#/definitions/FileAssociation"
936+
}
937+
},
928938
"shortDescription": {
929939
"description": "A short description of your application.",
930940
"type": [
@@ -1122,6 +1132,97 @@
11221132
}
11231133
]
11241134
},
1135+
"FileAssociation": {
1136+
"description": "File association",
1137+
"type": "object",
1138+
"required": [
1139+
"ext"
1140+
],
1141+
"properties": {
1142+
"ext": {
1143+
"description": "File extensions to associate with this app. e.g. 'png'",
1144+
"type": "array",
1145+
"items": {
1146+
"$ref": "#/definitions/AssociationExt"
1147+
}
1148+
},
1149+
"name": {
1150+
"description": "The name. Maps to `CFBundleTypeName` on macOS. Default to ext[0]",
1151+
"type": [
1152+
"string",
1153+
"null"
1154+
]
1155+
},
1156+
"description": {
1157+
"description": "The association description. Windows-only. It is displayed on the `Type` column on Windows Explorer.",
1158+
"type": [
1159+
"string",
1160+
"null"
1161+
]
1162+
},
1163+
"role": {
1164+
"description": "The app’s role with respect to the type. Maps to `CFBundleTypeRole` on macOS.",
1165+
"default": "Editor",
1166+
"allOf": [
1167+
{
1168+
"$ref": "#/definitions/BundleTypeRole"
1169+
}
1170+
]
1171+
},
1172+
"mimeType": {
1173+
"description": "The mime-type e.g. 'image/png' or 'text/plain'. Linux-only.",
1174+
"type": [
1175+
"string",
1176+
"null"
1177+
]
1178+
}
1179+
},
1180+
"additionalProperties": false
1181+
},
1182+
"AssociationExt": {
1183+
"description": "An extension for a [`FileAssociation`].\n\nA leading `.` is automatically stripped.",
1184+
"type": "string"
1185+
},
1186+
"BundleTypeRole": {
1187+
"description": "macOS-only. Corresponds to CFBundleTypeRole",
1188+
"oneOf": [
1189+
{
1190+
"description": "CFBundleTypeRole.Editor. Files can be read and edited.",
1191+
"type": "string",
1192+
"enum": [
1193+
"Editor"
1194+
]
1195+
},
1196+
{
1197+
"description": "CFBundleTypeRole.Viewer. Files can be read.",
1198+
"type": "string",
1199+
"enum": [
1200+
"Viewer"
1201+
]
1202+
},
1203+
{
1204+
"description": "CFBundleTypeRole.Shell",
1205+
"type": "string",
1206+
"enum": [
1207+
"Shell"
1208+
]
1209+
},
1210+
{
1211+
"description": "CFBundleTypeRole.QLGenerator",
1212+
"type": "string",
1213+
"enum": [
1214+
"QLGenerator"
1215+
]
1216+
},
1217+
{
1218+
"description": "CFBundleTypeRole.None",
1219+
"type": "string",
1220+
"enum": [
1221+
"None"
1222+
]
1223+
}
1224+
]
1225+
},
11251226
"AppImageConfig": {
11261227
"description": "Configuration for AppImage bundles.\n\nSee more: https://tauri.app/v1/api/config#appimageconfig",
11271228
"type": "object",

core/tauri-runtime-wry/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ edition = { workspace = true }
1313
rust-version = { workspace = true }
1414

1515
[dependencies]
16-
wry = { version = "0.28.3", default-features = false, features = [ "file-drop", "protocol" ] }
16+
wry = { version = "0.30", default-features = false, features = [ "file-drop", "protocol" ] }
1717
tauri-runtime = { version = "0.13.0-alpha.6", path = "../tauri-runtime" }
1818
tauri-utils = { version = "2.0.0-alpha.6", path = "../tauri-utils" }
1919
uuid = { version = "1", features = [ "v4" ] }
2020
rand = "0.8"
2121
raw-window-handle = "0.5"
2222

2323
[target."cfg(windows)".dependencies]
24-
webview2-com = "0.22"
24+
webview2-com = "0.25"
2525

2626
[target."cfg(windows)".dependencies.windows]
27-
version = "0.44"
27+
version = "0.48"
2828
features = [ "Win32_Foundation" ]
2929

3030
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
3131
gtk = { version = "0.16", features = [ "v3_24" ] }
32-
webkit2gtk = { version = "0.19.1", features = [ "v2_38" ] }
32+
webkit2gtk = { version = "1.1", features = [ "v2_38" ] }
3333
percent-encoding = "2.1"
3434

3535
[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
@@ -48,4 +48,4 @@ macos-private-api = [
4848
"tauri-runtime/macos-private-api"
4949
]
5050
objc-exception = [ "wry/objc-exception" ]
51-
linux-headers = [ "wry/linux-headers", "webkit2gtk/v2_36" ]
51+
linux-headers = [ ]

core/tauri-runtime-wry/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,10 @@ fn handle_event_loop<T: UserEvent>(
29522952
);
29532953
}
29542954
},
2955+
#[cfg(target_os = "macos")]
2956+
Event::Opened { urls } => {
2957+
callback(RunEvent::Opened { urls });
2958+
}
29552959
_ => (),
29562960
}
29572961

core/tauri-runtime/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rand = "0.8"
3535
url = { version = "2" }
3636

3737
[target."cfg(windows)".dependencies.windows]
38-
version = "0.44"
38+
version = "0.48"
3939
features = [ "Win32_Foundation" ]
4040

4141
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
@@ -44,6 +44,9 @@ gtk = { version = "0.16", features = [ "v3_24" ] }
4444
[target."cfg(target_os = \"android\")".dependencies]
4545
jni = "0.20"
4646

47+
[target."cfg(target_os = \"macos\")".dependencies]
48+
url = "2"
49+
4750
[features]
4851
devtools = [ ]
4952
system-tray = [ ]

core/tauri-runtime/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub trait UserEvent: Debug + Clone + Send + 'static {}
290290
impl<T: Debug + Clone + Send + 'static> UserEvent for T {}
291291

292292
/// Event triggered on the event loop run.
293+
#[derive(Debug)]
293294
#[non_exhaustive]
294295
pub enum RunEvent<T: UserEvent> {
295296
/// Event loop is exiting.
@@ -313,6 +314,9 @@ pub enum RunEvent<T: UserEvent> {
313314
///
314315
/// This event is useful as a place to put your code that should be run after all state-changing events have been handled and you want to do stuff (updating state, performing calculations, etc) that happens as the “main body” of your event loop.
315316
MainEventsCleared,
317+
/// Emitted when the user wants to open the specified resource with the app.
318+
#[cfg(target_os = "macos")]
319+
Opened { urls: Vec<url::Url> },
316320
/// A custom event defined by the user.
317321
UserEvent(T),
318322
}

0 commit comments

Comments
 (0)