Add sleeping tab recovery
This commit is contained in:
@@ -13,7 +13,6 @@ use sync::SyncObjectPolicies;
|
||||
|
||||
mod bookmarks;
|
||||
mod commands;
|
||||
mod crashes;
|
||||
mod downloads;
|
||||
mod history;
|
||||
mod notes;
|
||||
@@ -25,6 +24,7 @@ mod spaces;
|
||||
mod splits;
|
||||
mod sync;
|
||||
mod tab_groups;
|
||||
mod tab_lifecycle;
|
||||
mod tab_order;
|
||||
mod tabs;
|
||||
|
||||
|
||||
@@ -277,11 +277,20 @@ impl BrowserCore {
|
||||
self.crash_active_tab()?;
|
||||
Ok(true)
|
||||
}
|
||||
"sleep-tab" | "sleep tab" | "discard-tab" | "discard tab" => {
|
||||
self.discard_active_tab()?;
|
||||
Ok(true)
|
||||
}
|
||||
"recover-tab" | "recover tab" | "recover-crashed-tab" | "recover crashed tab" => {
|
||||
let tab_id = self.active_tab()?.id().clone();
|
||||
self.recover_crashed_tab(&tab_id)?;
|
||||
Ok(true)
|
||||
}
|
||||
"wake-tab" | "wake tab" | "restore-sleeping-tab" | "restore sleeping tab" => {
|
||||
let tab_id = self.active_tab()?.id().clone();
|
||||
self.wake_discarded_tab(&tab_id)?;
|
||||
Ok(true)
|
||||
}
|
||||
"close-split-view" | "close split view" => {
|
||||
Ok(self.close_active_saved_split_view()?.is_some())
|
||||
}
|
||||
|
||||
+23
@@ -20,6 +20,29 @@ impl BrowserCore {
|
||||
}
|
||||
|
||||
pub fn recover_crashed_tab(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
self.mark_tab_ready(tab_id)
|
||||
}
|
||||
|
||||
pub fn discard_active_tab(&mut self) -> Result<TabId, CoreError> {
|
||||
let tab_id = self.active_tab_id.clone();
|
||||
self.discard_tab(&tab_id)
|
||||
}
|
||||
|
||||
pub fn discard_tab(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
let tab = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
tab.mark_discarded();
|
||||
Ok(tab_id.clone())
|
||||
}
|
||||
|
||||
pub fn wake_discarded_tab(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
self.mark_tab_ready(tab_id)
|
||||
}
|
||||
|
||||
fn mark_tab_ready(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
{
|
||||
let tab = self
|
||||
.tabs
|
||||
@@ -0,0 +1,74 @@
|
||||
use std::error::Error;
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{CommandIntent, TabState, UrlText};
|
||||
|
||||
#[test]
|
||||
fn discard_active_tab_preserves_tab_metadata() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/sleep")?);
|
||||
let title = core.active_tab()?.title().to_string();
|
||||
core.set_tab_favicon_key(&tab_id, "favicons/example.ico")?;
|
||||
|
||||
core.discard_active_tab()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(active_tab.id(), &tab_id);
|
||||
assert_eq!(active_tab.state(), &TabState::Discarded);
|
||||
assert_eq!(active_tab.url().as_str(), "https://example.com/sleep");
|
||||
assert_eq!(active_tab.title(), title);
|
||||
assert_eq!(active_tab.favicon_key(), Some("favicons/example.ico"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wake_discarded_tab_marks_tab_ready() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/wake")?);
|
||||
|
||||
core.discard_active_tab()?;
|
||||
core.wake_discarded_tab(&tab_id)?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(active_tab.id(), &tab_id);
|
||||
assert_eq!(active_tab.state(), &TabState::Ready);
|
||||
assert_eq!(active_tab.url().as_str(), "https://example.com/wake");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sleep_tab_command_discards_active_tab() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/sleep-command")?);
|
||||
|
||||
core.set_command_query(">sleep-tab");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("sleep-tab".to_string())));
|
||||
assert_eq!(snapshot.active_tab_id, tab_id);
|
||||
assert_eq!(active_tab.state(), &TabState::Discarded);
|
||||
assert_eq!(active_tab.url().as_str(), "https://example.com/sleep-command");
|
||||
assert_eq!(snapshot.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wake_tab_command_restores_active_discarded_tab() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/wake-command")?);
|
||||
core.discard_active_tab()?;
|
||||
|
||||
core.set_command_query(">wake-tab");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("wake-tab".to_string())));
|
||||
assert_eq!(snapshot.active_tab_id, tab_id);
|
||||
assert_eq!(active_tab.state(), &TabState::Ready);
|
||||
assert_eq!(active_tab.url().as_str(), "https://example.com/wake-command");
|
||||
assert_eq!(snapshot.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user