release_hub/utils.rs
1// Copyright (c) 2025 BibCiTeX Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3//
4// This file contains code derived from tauri-plugin-updater
5// Original source: https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/updater
6// Copyright (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
7// Licensed under MIT OR MIT/Apache-2.0
8
9//! Filesystem path helpers used by the updater.
10
11use crate::{Error, Result};
12use std::path::{Path, PathBuf};
13
14/// Bundle types supported by the installer logic.
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum BundleType {
17 /// macOS `.app.zip` bundle.
18 MacOSAppZip,
19 /// macOS DMG image.
20 MacOSDMG,
21 /// Windows MSI installer.
22 WindowsMSI,
23 /// Windows EXE / setup installer.
24 WindowsSetUp,
25}
26
27/// Derive the target extract/installation path from the current executable path.
28///
29/// On macOS, this transforms `/Applications/App.app/Contents/MacOS/App`
30/// into `/Applications/App.app`.
31pub fn extract_path_from_executable(executable_path: &Path) -> Result<PathBuf> {
32 // Return the path of the current executable by default
33 // Example C:\Program Files\My App\
34 let extract_path = executable_path
35 .parent()
36 .map(PathBuf::from)
37 .ok_or(Error::FailedToDetermineExtractPath)?;
38
39 // MacOS example binary is in /Applications/TestApp.app/Contents/MacOS/myApp
40 // We need to get /Applications/<app>.app
41 // TODO(lemarier): Need a better way here
42 // Maybe we could search for <*.app> to get the right path
43 #[cfg(target_os = "macos")]
44 if extract_path
45 .display()
46 .to_string()
47 .contains("Contents/MacOS")
48 {
49 use std::path::PathBuf;
50
51 return extract_path
52 .parent()
53 .map(PathBuf::from)
54 .ok_or(Error::FailedToDetermineExtractPath)?
55 .parent()
56 .map(PathBuf::from)
57 .ok_or(Error::FailedToDetermineExtractPath);
58 }
59
60 Ok(extract_path)
61}