diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-04-08 12:59:35 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-04-08 12:59:35 +0200 |
commit | b7904b3f1aee2583770e7d0de13661e3b2a6f546 (patch) | |
tree | 3717c83a4ef09a30f94363e96352d7c09d849e7a /pkgs/by-name | |
parent | fix(modules/xdg/url-handler.sh): Use correct tskm invocation (diff) | |
download | nixos-config-b7904b3f1aee2583770e7d0de13661e3b2a6f546.zip |
fix(pkgs/tskm/open/open_in_browser): Handle the no lock file case
Diffstat (limited to 'pkgs/by-name')
-rw-r--r-- | pkgs/by-name/ts/tskm/src/interface/open/handle.rs | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs index 836d9ce7..4d7341b2 100644 --- a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs +++ b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs @@ -159,38 +159,45 @@ fn open_in_browser( if let Some(url) = url { args.push(url.to_string()); } else { - let (ip, pid): (IpAddr, u32) = { - let link = fs::read_link( - dirs::home_dir() - .expect("Exists") - .join(".mozilla/firefox") - .join(selected_project.to_project_display()) - .join("lock"), - )?; - let (ip, pid) = link - .to_str() - .expect("Should work") - .split_once(':') - .expect("The split works"); - - ( - ip.parse().expect("Should be a valid ip address"), - pid.parse().expect("Should be a valid pid"), - ) - }; + let lock_file = dirs::home_dir() + .expect("Exists") + .join(".mozilla/firefox") + .join(selected_project.to_project_display()) + .join("lock"); + + if lock_file.exists() { + let (ip, pid): (IpAddr, u32) = { + let link = fs::read_link(&lock_file).with_context(|| { + format!("Failed to readlink lock at '{}'", lock_file.display()) + })?; - if ip != Ipv4Addr::new(127, 0, 0, 2) { - warn!("Your ip is weird.."); - } + let (ip, pid) = link + .to_str() + .expect("Should work") + .split_once(':') + .expect("The split works"); - if PathBuf::from("/proc").join(pid.to_string()).exists() { - // Another Firefox instance has already been started for this project - // Add a buffer URL to force Firefox to open it in the already open instance - args.push("about:newtab".to_owned()); + ( + ip.parse().expect("Should be a valid ip address"), + pid.parse().expect("Should be a valid pid"), + ) + }; + + if ip != Ipv4Addr::new(127, 0, 0, 2) { + warn!("Your ip is weird.."); + } + + if PathBuf::from("/proc").join(pid.to_string()).exists() { + // Another Firefox instance has already been started for this project + // Add a buffer URL to force Firefox to open it in the already open instance + args.push("about:newtab".to_owned()); + } else { + // This project does not yet have another Firefox instance + // We do not need to add anything to the arguments, Firefox will open a new + // instance. + } } else { - // This project does not yet have another Firefox instance - // We do not need to add anything to the arguments, Firefox will open a new - // instance. + // There is no lock file and thus no instance already open. } }; |