Skip to content

Commit a2aed29

Browse files
committed
chore: add env dependency; fix macOS FFI signatures and path resolution; clean imports
1 parent 71c68e9 commit a2aed29

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

apps/desktop/src-tauri/Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ url = "2"
3434
percent-encoding = "2"
3535
tauri-plugin-os = "2.3.1"
3636
tauri-plugin-store = "2.4.0"
37+
env = "1.0.1"
3738

3839
[dev-dependencies]
3940
tempfile = "3.13.0"

apps/desktop/src-tauri/src/commands.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ fn current_http_handler_windows() -> Result<String, String> {
3838
#[cfg(target_os = "macos")]
3939
fn current_http_handler_macos() -> Result<String, String> {
4040
use core_foundation::base::TCFType;
41-
use core_foundation::string::CFString;
41+
use core_foundation::string::{CFString, CFStringRef};
4242

4343
#[link(name = "CoreServices", kind = "framework")]
4444
extern "C" {
45-
fn LSCopyDefaultHandlerForURLScheme(
46-
scheme: core_foundation::sys::string::CFStringRef,
47-
) -> core_foundation::sys::string::CFStringRef;
45+
fn LSCopyDefaultHandlerForURLScheme(scheme: CFStringRef) -> CFStringRef;
4846
}
4947

5048
let scheme = CFString::new("http");

apps/desktop/src-tauri/src/platform/macos.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
use core_foundation::base::TCFType;
22
use core_foundation::string::CFString;
3-
use core_foundation::url::{kCFURLPOSIXPathStyle, CFURL};
3+
use core_foundation::url::{kCFURLPOSIXPathStyle, CFURL, CFURLRef};
44
use std::path::Path;
5-
use tauri::AppHandle;
5+
use tauri::{AppHandle, Manager};
66

77
#[link(name = "CoreServices", kind = "framework")]
88
extern "C" {
9-
fn LSRegisterURL(in_url: core_foundation::sys::url::CFURLRef, in_update: bool) -> i32;
9+
fn LSRegisterURL(in_url: CFURLRef, in_update: bool) -> i32;
1010
}
1111

1212
pub fn register(app: &AppHandle) -> Result<(), String> {
13-
if let Some(bundle_path) = app.path_resolver().app_bundle_path() {
14-
try_register_path(&bundle_path)?;
15-
} else if let Ok(exe_path) = std::env::current_exe() {
13+
if let Ok(resource_dir) = app.path().resource_dir() {
14+
if let Some(bundle_path) = resource_dir.parent().and_then(|p| p.parent()) {
15+
try_register_path(bundle_path)?;
16+
return Ok(());
17+
}
18+
}
19+
20+
if let Ok(exe_path) = std::env::current_exe() {
1621
try_register_path(&exe_path)?;
1722
}
1823

@@ -25,7 +30,7 @@ fn try_register_path(path: &Path) -> Result<(), String> {
2530
"Failed to resolve application path for LaunchServices registration".to_string()
2631
})?;
2732
let cf_path = CFString::new(path_str);
28-
let url = CFURL::from_file_system_path(&cf_path, kCFURLPOSIXPathStyle, is_directory);
33+
let url = CFURL::from_file_system_path(cf_path, kCFURLPOSIXPathStyle, is_directory);
2934
let status = unsafe { LSRegisterURL(url.as_concrete_TypeRef(), true) };
3035

3136
if status != 0 {

apps/desktop/src-tauri/src/routing.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::preferences::PreferencesState;
22
use chrono::Utc;
33
use crowser::browser::{get_all_existing_browsers, get_browser_path};
44
use serde::{Deserialize, Serialize};
5-
use std::env;
65
use std::path::PathBuf;
76
use std::process::Command;
87
use std::sync::Arc;
@@ -12,8 +11,10 @@ use tokio::time::{sleep, Duration};
1211
use url::Url;
1312
use uuid::Uuid;
1413

15-
#[cfg(any(target_os = "linux", target_os = "macos"))]
16-
use dirs::{config_dir, home_dir};
14+
#[cfg(target_os = "linux")]
15+
use dirs::config_dir;
16+
#[cfg(target_os = "macos")]
17+
use dirs::home_dir;
1718

1819
#[cfg(target_os = "windows")]
1920
use std::os::windows::process::CommandExt;

0 commit comments

Comments
 (0)