diff --git a/crates/tauri-bundler/src/bundle/macos/dmg/mod.rs b/crates/tauri-bundler/src/bundle/macos/dmg/mod.rs index 747b3963c09c..04c89cc4ca59 100644 --- a/crates/tauri-bundler/src/bundle/macos/dmg/mod.rs +++ b/crates/tauri-bundler/src/bundle/macos/dmg/mod.rs @@ -133,6 +133,22 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result< &bundle_file_name, ]); + for item in &dmg_settings.files { + let _arg = format!("{} {:?} {} {}", item.name, item.path, item.x, item.y); + bundle_dmg_cmd.arg("--add-file" ); + bundle_dmg_cmd.arg(&item.name); + + if item.path.is_absolute() { + bundle_dmg_cmd.arg(&item.path); + } + else { + bundle_dmg_cmd.arg(env::current_dir()?.join(&item.path)); + } + + bundle_dmg_cmd.arg(&item.x.to_string()); + bundle_dmg_cmd.arg(&item.y.to_string()); + } + let window_position = dmg_settings .window_position .as_ref() diff --git a/crates/tauri-bundler/src/bundle/settings.rs b/crates/tauri-bundler/src/bundle/settings.rs index de7e32a1e3b1..36e02ffaed65 100644 --- a/crates/tauri-bundler/src/bundle/settings.rs +++ b/crates/tauri-bundler/src/bundle/settings.rs @@ -19,6 +19,7 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, }; +use tauri_utils::config::DmgFile; /// The type of the package we're bundling. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -304,6 +305,8 @@ pub struct DmgSettings { pub app_position: Position, /// Position of application folder on window. pub application_folder_position: Position, + /// Need to add files to the dmg collection + pub files: Vec } /// The macOS bundle settings. diff --git a/crates/tauri-cli/config.schema.json b/crates/tauri-cli/config.schema.json index 1c25517eacc7..d2cadb9f3565 100644 --- a/crates/tauri-cli/config.schema.json +++ b/crates/tauri-cli/config.schema.json @@ -112,6 +112,7 @@ "x": 480, "y": 170 }, + "files": [], "windowSize": { "height": 400, "width": 660 @@ -1994,6 +1995,7 @@ "x": 480, "y": 170 }, + "files": [], "windowSize": { "height": 400, "width": 660 @@ -3263,6 +3265,7 @@ "x": 480, "y": 170 }, + "files": [], "windowSize": { "height": 400, "width": 660 @@ -3334,6 +3337,13 @@ "$ref": "#/definitions/Position" } ] + }, + "files": { + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/DmgFile" + } } }, "additionalProperties": false @@ -3384,6 +3394,34 @@ }, "additionalProperties": false }, + "DmgFile": { + "type": "object", + "required": [ + "name", + "path", + "x", + "y" + ], + "properties": { + "path": { + "type": "string" + }, + "name": { + "type": "string" + }, + "x": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "y": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, "IosConfig": { "description": "General configuration for the iOS target.", "type": "object", diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index b6542466da18..9d3a15fbf86f 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -1443,6 +1443,7 @@ fn tauri_config_to_bundle_settings( x: config.macos.dmg.application_folder_position.x, y: config.macos.dmg.application_folder_position.y, }, + files: config.macos.dmg.files, }, macos: MacOsSettings { frameworks: config.macos.frameworks, diff --git a/crates/tauri-schema-generator/schemas/config.schema.json b/crates/tauri-schema-generator/schemas/config.schema.json index 1c25517eacc7..d2cadb9f3565 100644 --- a/crates/tauri-schema-generator/schemas/config.schema.json +++ b/crates/tauri-schema-generator/schemas/config.schema.json @@ -112,6 +112,7 @@ "x": 480, "y": 170 }, + "files": [], "windowSize": { "height": 400, "width": 660 @@ -1994,6 +1995,7 @@ "x": 480, "y": 170 }, + "files": [], "windowSize": { "height": 400, "width": 660 @@ -3263,6 +3265,7 @@ "x": 480, "y": 170 }, + "files": [], "windowSize": { "height": 400, "width": 660 @@ -3334,6 +3337,13 @@ "$ref": "#/definitions/Position" } ] + }, + "files": { + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/DmgFile" + } } }, "additionalProperties": false @@ -3384,6 +3394,34 @@ }, "additionalProperties": false }, + "DmgFile": { + "type": "object", + "required": [ + "name", + "path", + "x", + "y" + ], + "properties": { + "path": { + "type": "string" + }, + "name": { + "type": "string" + }, + "x": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "y": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, "IosConfig": { "description": "General configuration for the iOS target.", "type": "object", diff --git a/crates/tauri-utils/src/config.rs b/crates/tauri-utils/src/config.rs index 824a835fea15..3d3d7e429c4b 100644 --- a/crates/tauri-utils/src/config.rs +++ b/crates/tauri-utils/src/config.rs @@ -546,6 +546,41 @@ pub struct DmgConfig { alias = "application-folder-position" )] pub application_folder_position: Position, + /// Need to add files to the dmg collection + #[serde( + default = "files_default", + alias = "files" + )] + pub files: Vec, + +} + + +#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "schema", derive(JsonSchema))] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct DmgFile { + #[serde( + alias = "path" + )] + /// The path to the file. + pub path: PathBuf, + #[serde( + alias = "name" + )] + /// The name of the file. + pub name: String, + #[serde( + alias = "x" + )] + /// The x-coordinate associated with the file. + pub x: u32, + #[serde( + alias = "y" + )] + /// The y-coordinate associated with the file. + pub y: u32, + } impl Default for DmgConfig { @@ -556,6 +591,7 @@ impl Default for DmgConfig { window_size: dmg_window_size(), app_position: dmg_app_position(), application_folder_position: dmg_application_folder_position(), + files: files_default(), } } } @@ -575,6 +611,10 @@ fn dmg_application_folder_position() -> Position { Position { x: 480, y: 170 } } +fn files_default() -> Vec { + Vec::new() +} + fn de_macos_minimum_system_version<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, diff --git a/examples/api/src-tauri/tauri.conf.json b/examples/api/src-tauri/tauri.conf.json index b09d914364a9..5dfe6975e714 100644 --- a/examples/api/src-tauri/tauri.conf.json +++ b/examples/api/src-tauri/tauri.conf.json @@ -74,6 +74,19 @@ } }, "bundle": { + "macOS": { + "dmg": { + "files": [ + { + "x": 200, + "y": 200, + "name": "111", + "path": "./info.plist" + } + ] + + } + }, "active": true, "icon": [ "../../.icons/32x32.png", diff --git a/examples/helloworld/tauri.conf.json b/examples/helloworld/tauri.conf.json index 5b6d19585f8d..db64a5d046db 100644 --- a/examples/helloworld/tauri.conf.json +++ b/examples/helloworld/tauri.conf.json @@ -30,6 +30,18 @@ "../.icons/128x128@2x.png", "../.icons/icon.icns", "../.icons/icon.ico" - ] + ], + "macOS": { + "dmg": { + "files": [ + { + "name": "aa.md", + "path": "./README.md", + "x": 200, + "y": 200 + } + ] + } + } } }