chore: Switch to open crate rather than in-house solution

This commit is contained in:
LynithDev 2026-07-13 18:41:55 +02:00
parent 8cd617a78b
commit cdd4504b84
3 changed files with 6 additions and 60 deletions

6
Cargo.lock generated
View file

@ -4133,6 +4133,7 @@ dependencies = [
"oneclient_core",
"oneclient_db",
"oneclient_macro",
"open",
"polyio",
"regex",
"rfd",
@ -4142,7 +4143,6 @@ dependencies = [
"tracing",
"tracing-subscriber",
"uuid",
"windows-sys 0.60.2",
]
[[package]]
@ -4216,9 +4216,9 @@ dependencies = [
[[package]]
name = "open"
version = "5.3.6"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd8d3b65c44123a56e0133d2cd06ce4361bd3ca99d41198b2f25e3c3db9b8b4a"
checksum = "a0b3d059e795d52b8a72fef45658620edd4d9c359b338564aa14391ffa511ed5"
dependencies = [
"is-wsl",
"libc",

View file

@ -34,8 +34,8 @@ regex.workspace = true
cargo-packager-updater = "=0.2.3"
# file dialog
rfd = "=0.17.2"
open = "=5.4.0"
# clipboard image copy + decode for it
arboard.workspace = true
@ -47,9 +47,6 @@ freya.workspace = true
[target.'cfg(target_os = "macos")'.dependencies]
mimalloc = "=0.1.52"
[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { version = "0.60", features = ["Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_Foundation"] }
# Build then package (per OS):
# cargo build --release -p oneclient_app
# cargo packager --release -p oneclient_app --formats <nsis|app,dmg|deb,appimage>

View file

@ -1,56 +1,9 @@
#[cfg(not(target_os = "windows"))]
pub fn open_url(url: &str) {
let result = {
#[cfg(target_os = "linux")]
{
std::process::Command::new("xdg-open").arg(url).spawn()
}
#[cfg(target_os = "macos")]
{
std::process::Command::new("open").arg(url).spawn()
}
};
if let Err(err) = result {
if let Err(err) = open::that_detached(url) {
tracing::warn!("failed to open url {url}: {err}");
}
}
#[cfg(target_os = "windows")]
pub fn open_url(url: &str) {
use std::os::windows::ffi::OsStrExt;
use windows_sys::Win32::UI::Shell::ShellExecuteW;
// SW_SHOWNORMAL
const SW_SHOWNORMAL: i32 = 1;
fn wide(s: &str) -> Vec<u16> {
std::ffi::OsStr::new(s)
.encode_wide()
.chain(std::iter::once(0))
.collect()
}
let operation = wide("open");
let file = wide(url);
let ret = unsafe {
ShellExecuteW(
std::ptr::null_mut(),
operation.as_ptr(),
file.as_ptr(),
std::ptr::null(),
std::ptr::null(),
SW_SHOWNORMAL,
)
};
if (ret as isize) <= 32 {
tracing::warn!("failed to open url {url}: ShellExecuteW returned {}", ret as isize);
}
}
pub fn copy_image_to_clipboard(path: std::path::PathBuf) {
std::thread::spawn(move || {
let img = match image::open(&path) {
@ -95,13 +48,9 @@ pub mod macos {
fn release_unused_memory() {
unsafe {
unsafe extern "C" {
fn malloc_zone_pressure_relief(
zone: *mut core::ffi::c_void,
goal: usize,
) -> usize;
fn malloc_zone_pressure_relief(zone: *mut core::ffi::c_void, goal: usize) -> usize;
}
malloc_zone_pressure_relief(core::ptr::null_mut(), 0);
}
}
}