Skip to content

Commit

Permalink
feat(bundler): add dmg settings, closes #4669 (#7964)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreybest authored Nov 20, 2023
1 parent 3b91e23 commit b0c5b06
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 18 deletions.
157 changes: 157 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
"deb": {
"files": {}
},
"dmg": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"iOS": {},
"icon": [],
"identifier": "",
Expand Down Expand Up @@ -171,6 +185,20 @@
"deb": {
"files": {}
},
"dmg": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"iOS": {},
"icon": [],
"identifier": "",
Expand Down Expand Up @@ -1003,6 +1031,28 @@
}
]
},
"dmg": {
"description": "DMG-specific settings.",
"default": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"allOf": [
{
"$ref": "#/definitions/DmgConfig"
}
]
},
"macOS": {
"description": "Configuration for the macOS bundles.",
"default": {
Expand Down Expand Up @@ -1318,6 +1368,113 @@
},
"additionalProperties": false
},
"DmgConfig": {
"description": "Configuration for Apple Disk Image (.dmg) bundles.\n\nSee more: https://tauri.app/v1/api/config#dmgconfig",
"type": "object",
"properties": {
"background": {
"description": "Image to use as the background in dmg file. Accepted formats: `png`/`jpg`/`gif`.",
"type": [
"string",
"null"
]
},
"windowPosition": {
"description": "Position of volume window on screen.",
"anyOf": [
{
"$ref": "#/definitions/Position"
},
{
"type": "null"
}
]
},
"windowSize": {
"description": "Size of volume window.",
"default": {
"height": 400,
"width": 660
},
"allOf": [
{
"$ref": "#/definitions/Size"
}
]
},
"appPosition": {
"description": "Position of app file on window.",
"default": {
"x": 180,
"y": 170
},
"allOf": [
{
"$ref": "#/definitions/Position"
}
]
},
"applicationFolderPosition": {
"description": "Position of application folder on window.",
"default": {
"x": 480,
"y": 170
},
"allOf": [
{
"$ref": "#/definitions/Position"
}
]
}
},
"additionalProperties": false
},
"Position": {
"description": "Position coordinates struct.",
"type": "object",
"required": [
"x",
"y"
],
"properties": {
"x": {
"description": "X coordinate.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"y": {
"description": "Y coordinate.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
"Size": {
"description": "Size of the window.",
"type": "object",
"required": [
"height",
"width"
],
"properties": {
"width": {
"description": "Width of the window.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"height": {
"description": "Height of the window.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
"MacConfig": {
"description": "Configuration for the macOS bundles.\n\nSee more: <https://tauri.app/v1/api/config#macconfig>",
"type": "object",
Expand Down
95 changes: 95 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,95 @@ pub struct DebConfig {
pub desktop_template: Option<PathBuf>,
}

/// Position coordinates struct.
#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Position {
/// X coordinate.
pub x: u32,
/// Y coordinate.
pub y: u32,
}

/// Size of the window.
#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Size {
/// Width of the window.
pub width: u32,
/// Height of the window.
pub height: u32,
}



/// Configuration for Apple Disk Image (.dmg) bundles.
///
/// See more: https://tauri.app/v1/api/config#dmgconfig
#[skip_serializing_none]
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DmgConfig {
/// Image to use as the background in dmg file. Accepted formats: `png`/`jpg`/`gif`.
pub background: Option<PathBuf>,
/// Position of volume window on screen.
pub window_position: Option<Position>,
/// Size of volume window.
#[serde(
default = "window_size",
alias = "window-size"
)]
pub window_size: Size,
/// Position of app file on window.
#[serde(
default = "app_position",
alias = "app-position"
)]
pub app_position: Position,
/// Position of application folder on window.
#[serde(
default = "application_folder_position",
alias = "application-folder-position"
)]
pub application_folder_position: Position,
}

impl Default for DmgConfig {
fn default() -> Self {
Self {
background: None,
window_position: None,
window_size: window_size(),
app_position: app_position(),
application_folder_position: application_folder_position(),
}
}
}

fn window_size() -> Size {
Size {
width: 660,
height: 400,
}
}

fn app_position() -> Position {
Position {
x: 180,
y: 170,
}
}

fn application_folder_position() -> Position {
Position {
x: 480,
y: 170,
}
}

fn de_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
Expand Down Expand Up @@ -850,6 +939,9 @@ pub struct BundleConfig {
/// Configuration for the Debian bundle.
#[serde(default)]
pub deb: DebConfig,
/// DMG-specific settings.
#[serde(default)]
pub dmg: DmgConfig,
/// Configuration for the macOS bundles.
#[serde(rename = "macOS", default)]
pub macos: MacConfig,
Expand Down Expand Up @@ -2440,6 +2532,7 @@ mod build {
let long_description = quote!(None);
let appimage = quote!(Default::default());
let deb = quote!(Default::default());
let dmg = quote!(Default::default());
let macos = quote!(Default::default());
let external_bin = opt_vec_str_lit(self.external_bin.as_ref());
let windows = &self.windows;
Expand All @@ -2463,6 +2556,7 @@ mod build {
long_description,
appimage,
deb,
dmg,
macos,
external_bin,
windows,
Expand Down Expand Up @@ -2771,6 +2865,7 @@ mod test {
long_description: None,
appimage: Default::default(),
deb: Default::default(),
dmg: Default::default(),
macos: Default::default(),
external_bin: None,
windows: Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use tauri_utils::display_path;
pub use self::{
category::AppCategory,
settings::{
BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings, PackageType,
Settings, SettingsBuilder, UpdaterSettings,
BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings, PackageType,
Settings, SettingsBuilder, UpdaterSettings, Position, Size
},
};
#[cfg(target_os = "macos")]
Expand Down
Loading

0 comments on commit b0c5b06

Please sign in to comment.