Skip to content

Commit 71bf666

Browse files
committed
Replace auto-open with user instructions
Stop attempting to auto-mount/open the WebDAV volume and instead print manual instructions for the user. main.rs: remove the spawned async task that retried and opened the network connection, and call os::open_connection synchronously so errors are surfaced immediately. src/os/linux.rs: remove mounting/retry logic and xdg-open spawn, print gio/xdg-open commands for the user, and keep a best-effort silent unmount on close. src/os/macos.rs: print an instruction to open the volume via Finder, add Stdio redirection and use status for diskutil unmount to keep shutdown cleanup silent. Imports updated accordingly. This simplifies behavior, avoids background retries/spawns, and gives users explicit steps to open the volume.
1 parent bcd5026 commit 71bf666

3 files changed

Lines changed: 14 additions & 72 deletions

File tree

src/main.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6767
println!("\n[+] Serveur en ligne sur http://127.0.0.1:8080/");
6868
println!("[*] Appuyez sur CTRL+C pour quitter proprement.");
6969

70-
// Déclenchement de la connexion réseau (Asynchrone)
71-
tokio::task::spawn(async {
72-
// Pause d'une seconde pour s'assurer que le serveur est prêt
73-
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
74-
println!("[*] Ouverture de la connexion réseau...");
75-
76-
if let Err(e) = crate::os::open_connection(8080) {
77-
eprintln!("[!] Note : {}", e);
78-
}
79-
});
70+
if let Err(e) = crate::os::open_connection(8080) {
71+
eprintln!("[!] Note : {}", e);
72+
}
8073

8174
loop {
8275
tokio::select! {

src/os/linux.rs

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,19 @@
11
use std::process::{Command, Stdio};
2-
use std::thread;
3-
use std::time::Duration;
42

53
pub fn open_connection(port: u16) -> Result<(), String> {
6-
let dav_url = format!("dav://127.0.0.1:{}/", port);
7-
let mut is_ready = false;
8-
9-
for _ in 0..5 {
10-
let mount_status = Command::new("gio")
11-
.args(["mount", &dav_url])
12-
.stdout(Stdio::null())
13-
.stderr(Stdio::null())
14-
.status();
15-
16-
if let Ok(status) = mount_status {
17-
if status.success() {
18-
is_ready = true;
19-
break;
20-
}
21-
}
22-
23-
let info_status = Command::new("gio")
24-
.args(["info", &dav_url])
25-
.stdout(Stdio::null())
26-
.stderr(Stdio::null())
27-
.status();
28-
29-
if let Ok(status) = info_status {
30-
if status.success() {
31-
is_ready = true;
32-
break;
33-
}
34-
}
35-
36-
thread::sleep(Duration::from_millis(500));
37-
}
38-
39-
if !is_ready {
40-
return Err(
41-
"Le système n'a pas pu monter le volume réseau après plusieurs tentatives.".to_string(),
42-
);
43-
}
44-
45-
Command::new("xdg-open")
46-
.arg(&dav_url)
47-
.stdout(Stdio::null())
48-
.stderr(Stdio::null())
49-
.spawn()
50-
.map_err(|e| format!("Erreur xdg-open : {}", e))?;
51-
4+
println!("\n[i] Pour accéder au volume, ouvrez un nouveau terminal et tapez :");
5+
println!(" gio mount dav://127.0.0.1:{}/", port);
6+
println!(" xdg-open dav://127.0.0.1:{}/", port);
527
Ok(())
538
}
549

5510
pub fn close_connection(port: u16) -> Result<(), String> {
5611
let dav_url = format!("dav://127.0.0.1:{}/", port);
57-
12+
// Le démontage automatique à la fermeture fonctionne bien et nettoie le système
5813
let _ = Command::new("gio")
5914
.args(["mount", "-u", &dav_url])
6015
.stdout(Stdio::null())
6116
.stderr(Stdio::null())
6217
.status();
63-
6418
Ok(())
6519
}

src/os/macos.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
use std::process::Command;
1+
use std::process::{Command, Stdio};
22

33
pub fn open_connection(port: u16) -> Result<(), String> {
4-
// On utilise webdav:// pour forcer l'ouverture via le Finder et non Safari
5-
let url = format!("webdav://127.0.0.1:{}/", port);
6-
7-
Command::new("open")
8-
.arg(&url)
9-
.spawn()
10-
.map_err(|e| format!("Erreur Open macOS : {}", e))?;
11-
4+
println!("\n[i] Pour accéder au volume sous macOS, ouvrez un nouveau terminal et tapez :");
5+
println!(" open webdav://127.0.0.1:{}/", port);
126
Ok(())
137
}
148

159
pub fn close_connection(_port: u16) -> Result<(), String> {
16-
// Le Finder montera le volume sous l'IP par défaut.
17-
// On garde le démontage forcé pour fermer la connexion.
10+
// Nettoyage automatique silencieux à l'arrêt
1811
let _ = Command::new("diskutil")
1912
.args(["unmount", "force", "/Volumes/127.0.0.1"])
20-
.output();
13+
.stdout(Stdio::null())
14+
.stderr(Stdio::null())
15+
.status();
2116
Ok(())
2217
}

0 commit comments

Comments
 (0)