diff options
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/interface')
-rw-r--r-- | pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs | 12 | ||||
-rw-r--r-- | pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs | 9 | ||||
-rw-r--r-- | pkgs/by-name/ts/tskm/src/interface/open/handle.rs | 66 |
3 files changed, 50 insertions, 37 deletions
diff --git a/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs b/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs index 577de02c..d904b12e 100644 --- a/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs +++ b/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs @@ -13,10 +13,10 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> { match command { NeorgCommand::Task { id } => { let project = id.project(state)?; - let path = dirs::data_local_dir() + let base = dirs::data_local_dir() .expect("This should exists") - .join("tskm/notes") - .join(project.get_neorg_path()?); + .join("tskm/notes"); + let path = base.join(project.get_neorg_path()?); fs::create_dir_all(path.parent().expect("This should exist"))?; @@ -69,11 +69,7 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> { .args([ "commit", "--message", - format!( - "chore({}): Update", - path.parent().expect("Should have a parent").display() - ) - .as_str(), + format!("chore({}): Update", project.get_neorg_path()?.display()).as_str(), "--no-gpg-sign", ]) .current_dir(path.parent().expect("Will exist")) diff --git a/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs b/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs index dc5cdf19..51d58ab3 100644 --- a/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs +++ b/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs @@ -8,11 +8,18 @@ pub mod handle; pub use handle::handle; impl Project { + /// Return the stored neorg path of this project. + /// The returned path will never start with a slash (/). pub(super) fn get_neorg_path(&self) -> Result<PathBuf> { let project_path = run_task(&[ "_get", format!("rc.context.{}.rc.neorg_path", self.to_context_display()).as_str(), ])?; - Ok(PathBuf::from(project_path.as_str())) + + let final_path = project_path + .strip_prefix('/') + .unwrap_or(project_path.as_str()); + + Ok(PathBuf::from(final_path)) } } 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 15c7ac4d..4d7341b2 100644 --- a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs +++ b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs @@ -6,7 +6,7 @@ use std::{ }; use anyhow::{bail, Context, Result}; -use log::{error, info}; +use log::{error, info, warn}; use url::Url; use crate::{cli::OpenCommand, rofi, state::State, task}; @@ -159,35 +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()) + })?; - assert_eq!(ip, Ipv4Addr::new(127, 0, 0, 1)); - 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()); + 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"), + ) + }; + + 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. } }; |