Skip to content

Commit

Permalink
feat: add dmg settings, cherry picked from #7964 (#8334)
Browse files Browse the repository at this point in the history
* feat(bundler): add dmg settings, closes #4669 (#7964)

* fix(bundler): lint and cleanup for #7964 (#8275)

* fmt

---------

Co-authored-by: Andrew <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: FabianLars <[email protected]>
  • Loading branch information
4 people authored Jun 17, 2024
1 parent d2786bf commit 9243870
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .changes/feat-add-dmg-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
tauri-bundler: minor:feat
tauri-cli: minor:feat
---

Added support for DMG settings to `bundler > dmg`. Includes window size, background image and icon positions.
157 changes: 157 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@
"deb": {
"files": {}
},
"dmg": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"icon": [],
"identifier": "",
"macOS": {
Expand Down Expand Up @@ -285,6 +299,20 @@
"deb": {
"files": {}
},
"dmg": {
"appPosition": {
"x": 180,
"y": 170
},
"applicationFolderPosition": {
"x": 480,
"y": 170
},
"windowSize": {
"height": 400,
"width": 660
}
},
"icon": [],
"identifier": "",
"macOS": {
Expand Down Expand Up @@ -1166,6 +1194,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 @@ -1495,6 +1545,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
81 changes: 81 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,81 @@ fn default_release() -> String {
"1".into()
}

/// 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 = "dmg_window_size", alias = "window-size")]
pub window_size: Size,
/// Position of app file on window.
#[serde(default = "dmg_app_position", alias = "app-position")]
pub app_position: Position,
/// Position of application folder on window.
#[serde(
default = "dmg_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: dmg_window_size(),
app_position: dmg_app_position(),
application_folder_position: dmg_application_folder_position(),
}
}
}

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

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

fn dmg_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 @@ -810,6 +885,9 @@ pub struct BundleConfig {
/// Configuration for the RPM bundle.
#[serde(default)]
pub rpm: RpmConfig,
/// DMG-specific settings.
#[serde(default)]
pub dmg: DmgConfig,
/// Configuration for the macOS bundles.
#[serde(rename = "macOS", default)]
pub macos: MacConfig,
Expand Down Expand Up @@ -3639,6 +3717,7 @@ mod build {
let appimage = quote!(Default::default());
let deb = quote!(Default::default());
let rpm = 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 @@ -3660,6 +3739,7 @@ mod build {
appimage,
deb,
rpm,
dmg,
macos,
external_bin,
windows
Expand Down Expand Up @@ -4104,6 +4184,7 @@ mod test {
appimage: Default::default(),
deb: Default::default(),
rpm: 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,
RpmSettings, Settings, SettingsBuilder, UpdaterSettings,
BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings,
PackageType, Position, RpmSettings, Settings, SettingsBuilder, Size, UpdaterSettings,
},
};
#[cfg(target_os = "macos")]
Expand Down
Loading

0 comments on commit 9243870

Please sign in to comment.