zed: Add ability to restore last session w/ multiple windows (#14965)
This adds the ability for Zed to restore multiple windows after restarting. It's now the default behavior. Release Notes: - Added ability to restore all windows that were open when Zed was quit. Previously only the last used workspace was restored. This is now the default behavior. To get back the old behavior, add the following to your settings: `{"restore_on_startup": "last_workspace"}` (Part of [#4985](https://github.com/zed-industries/zed/issues/4985) and [#4683](https://github.com/zed-industries/zed/issues/4683)) Demo: https://github.com/user-attachments/assets/57a375ec-0c6a-4724-97c4-3fea8f18bc2d --------- Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
53f828df7d
commit
17ef9a367f
18 changed files with 660 additions and 172 deletions
23
crates/session/Cargo.toml
Normal file
23
crates/session/Cargo.toml
Normal file
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "session"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/session.rs"
|
||||
doctest = false
|
||||
|
||||
[features]
|
||||
test-support = [
|
||||
"db/test-support",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
db.workspace = true
|
||||
uuid.workspace = true
|
||||
util.workspace = true
|
1
crates/session/LICENSE-GPL
Symbolic link
1
crates/session/LICENSE-GPL
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-GPL
|
44
crates/session/src/session.rs
Normal file
44
crates/session/src/session.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use db::kvp::KEY_VALUE_STORE;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Session {
|
||||
session_id: String,
|
||||
old_session_id: Option<String>,
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub async fn new() -> Self {
|
||||
let key_name = "session_id".to_string();
|
||||
|
||||
let old_session_id = KEY_VALUE_STORE.read_kvp(&key_name).ok().flatten();
|
||||
|
||||
let session_id = Uuid::new_v4().to_string();
|
||||
|
||||
KEY_VALUE_STORE
|
||||
.write_kvp(key_name, session_id.clone())
|
||||
.await
|
||||
.log_err();
|
||||
|
||||
Self {
|
||||
session_id,
|
||||
old_session_id,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn test() -> Self {
|
||||
Self {
|
||||
session_id: Uuid::new_v4().to_string(),
|
||||
old_session_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &str {
|
||||
&self.session_id
|
||||
}
|
||||
pub fn last_session_id(&self) -> Option<&str> {
|
||||
self.old_session_id.as_deref()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue