Skip to content

Commit

Permalink
feat: Unable to add files to dmg interface
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Dec 19, 2024
1 parent ca7f025 commit 8f24914
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 1 deletion.
16 changes: 16 additions & 0 deletions crates/tauri-bundler/src/bundle/macos/dmg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions crates/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<DmgFile>
}

/// The macOS bundle settings.
Expand Down
38 changes: 38 additions & 0 deletions crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"x": 480,
"y": 170
},
"files": [],
"windowSize": {
"height": 400,
"width": 660
Expand Down Expand Up @@ -1994,6 +1995,7 @@
"x": 480,
"y": 170
},
"files": [],
"windowSize": {
"height": 400,
"width": 660
Expand Down Expand Up @@ -3263,6 +3265,7 @@
"x": 480,
"y": 170
},
"files": [],
"windowSize": {
"height": 400,
"width": 660
Expand Down Expand Up @@ -3334,6 +3337,13 @@
"$ref": "#/definitions/Position"
}
]
},
"files": {
"default": [],
"type": "array",
"items": {
"$ref": "#/definitions/DmgFile"
}
}
},
"additionalProperties": false
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"x": 480,
"y": 170
},
"files": [],
"windowSize": {
"height": 400,
"width": 660
Expand Down Expand Up @@ -1994,6 +1995,7 @@
"x": 480,
"y": 170
},
"files": [],
"windowSize": {
"height": 400,
"width": 660
Expand Down Expand Up @@ -3263,6 +3265,7 @@
"x": 480,
"y": 170
},
"files": [],
"windowSize": {
"height": 400,
"width": 660
Expand Down Expand Up @@ -3334,6 +3337,13 @@
"$ref": "#/definitions/Position"
}
]
},
"files": {
"default": [],
"type": "array",
"items": {
"$ref": "#/definitions/DmgFile"
}
}
},
"additionalProperties": false
Expand Down Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions crates/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DmgFile>,

}


#[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 {
Expand All @@ -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(),
}
}
}
Expand All @@ -575,6 +611,10 @@ fn dmg_application_folder_position() -> Position {
Position { x: 480, y: 170 }
}

fn files_default() -> Vec<DmgFile> {
Vec::new()
}

fn de_macos_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
Expand Down
13 changes: 13 additions & 0 deletions examples/api/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@
}
},
"bundle": {
"macOS": {
"dmg": {
"files": [
{
"x": 200,
"y": 200,
"name": "111",
"path": "./info.plist"
}
]

}
},
"active": true,
"icon": [
"../../.icons/32x32.png",
Expand Down
14 changes: 13 additions & 1 deletion examples/helloworld/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
}
}
}

0 comments on commit 8f24914

Please sign in to comment.