about summary refs log tree commit diff stats
path: root/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/interface/open/mod.rs')
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/mod.rs38
1 files changed, 32 insertions, 6 deletions
diff --git a/pkgs/by-name/ts/tskm/src/interface/open/mod.rs b/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
index 40e057c1..e403b4a8 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
@@ -8,7 +8,11 @@
 // You should have received a copy of the License along with this program.
 // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 
-use std::{fs::File, io::Read, str::FromStr};
+use std::{
+    fs::{self, File},
+    io::Read,
+    str::FromStr,
+};
 
 use anyhow::{anyhow, Context, Result};
 use taskchampion::chrono::NaiveDateTime;
@@ -20,15 +24,37 @@ use crate::task::Project;
 pub mod handle;
 pub use handle::handle;
 
+/// An Url that also accepts file paths
+#[derive(Debug, Clone)]
+pub struct UrlLike(Url);
+
+impl FromStr for UrlLike {
+    type Err = url::ParseError;
+
+    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+        if let Ok(u) = fs::canonicalize(s) {
+            Ok(Self(Url::from_file_path(u).expect(
+                "The path could be canonicalized, as such it is valid for this",
+            )))
+        } else {
+            Url::from_str(s).map(Self)
+        }
+    }
+}
+
+impl From<UrlLike> for Url {
+    fn from(value: UrlLike) -> Self {
+        value.0
+    }
+}
+
 impl Project {
     pub(super) fn get_sessionstore(&self) -> Result<SessionStore> {
         let path = dirs::data_local_dir()
             .context("Failed to get data dir")?
             .join("qutebrowser")
             .join(self.to_project_display())
-            // NOTE(@bpeetz): We could use another real session name, but this file should
-            // always exist. <2025-06-03>
-            .join("data/sessions/_autosave.yml");
+            .join("data/sessions/default.yml");
 
         let mut file = File::open(&path)
             .with_context(|| format!("Failed to open path '{}'", path.display()))?;
@@ -92,7 +118,7 @@ fn qute_store_from_yaml(yaml: &[Yaml]) -> Result<SessionStore> {
                                         Ok::<_, anyhow::Error>(TabHistory {
                                             active: hash
                                                 .get(&Yaml::String("active".to_owned()))
-                                                .ok_or(anyhow!("Missing tab history active"))?
+                                                .unwrap_or(&Yaml::Boolean(false))
                                                 .as_bool()
                                                 .ok_or(anyhow!("tab history active not bool"))?,
                                             last_visited: NaiveDateTime::from_str(
@@ -126,7 +152,7 @@ fn qute_store_from_yaml(yaml: &[Yaml]) -> Result<SessionStore> {
                                             .context("Failed to parse url")?,
                                             zoom: hash
                                                 .get(&Yaml::String("zoom".to_owned()))
-                                                .ok_or(anyhow!("Missing tab history zoom"))?
+                                                .unwrap_or(&Yaml::Real("1.0".to_owned()))
                                                 .as_f64()
                                                 .ok_or(anyhow!("tab history zoom not 64"))?,
                                         })