aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts/tskm/src/interface/open
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/handle.rs63
1 files changed, 35 insertions, 28 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");
+ let lock_file = dirs::home_dir()
+ .expect("Exists")
+ .join(".mozilla/firefox")
+ .join(selected_project.to_project_display())
+ .join("lock");
- (
- ip.parse().expect("Should be a valid ip address"),
- pid.parse().expect("Should be a valid pid"),
- )
- };
+ 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.
}
};