authoravatarclover caruso<git@paperclover.net>2026-10-19 16:24:37-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 22:58:56-07:00
log2f91a95387b710cc973f6ae8facbecca45b8a499
tree689c74794991eb8bc8fd9fd57f9004db9f808ae1
parente402bcaea68f6837c079a7176a870a9d6dbdfb65
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

fix(ios): keep the Recycle Bin reachable and its promises true

Review of the Recycle Bin: a notebook whose last section was deleted lost its Notebook Recycle Bin item, which is now kept for every open notebook folder. The bin is pruned of what it has held past 60 days when a notebook opens, as OneNote and the desktop do, so its footer holds. A section deleted with edits waiting is listed again at once, so the background publishes them to the binned file. On a share the bin is listed with the notebook, so Deleted Pages opens there, as it would not when the bin was made after the last listing; a lab test restores a page from a Samba share's bin while offline and finds it in place on a cold reopen once online. Deleted Pages that can't be opened says so rather than that the bin is empty, and Restore To greys out a folder already holding a section file of the same name, letters' case aside, and says why. - Notebook Recycle Bin stays in a notebook's menu after its last section is deleted. - The Recycle Bin is emptied of what it has held for 60 days when the notebook opens, as OneNote does. - The Recycle Bin says when it can't be opened instead of showing it empty. - The Recycle Bin of a notebook on a server opens its deleted pages. - Restore To greys out a folder holding a section of the same name, saying why, whatever the letters' case. - Each Restore button names what it restores to VoiceOver, and notes stay up while VoiceOver runs. Refs #133 Assisted-by: claude-opus-5.5

6 files changed, 227 insertions(+), 25 deletions(-)

apps/ios/Snowbound/Notebooks.swift+7-1
......@@ -262,6 +262,11 @@ final class Notebook {
262262 self.problem = library == nil ? (problem ?? "The notebook can’t be read.") : nil
263263 follow()
264264 reload(done: done)
265 // As OneNote prunes the recycle bin after opening.
266 if let library {
267 let pointer = Int(bitPattern: library)
268 background({ sb_library_purge_recycle_bin(OpaquePointer(bitPattern: pointer)) }) { _ in }
269 }
265270 }
266271 }
267272
......@@ -785,7 +790,8 @@ final class Section {
785790 done()
786791 if recycled > 0, let window {
787792 let title = recycled == 1 ? "Page Moved to Recycle Bin" : "\(recycled) Pages Moved to Recycle Bin"
788 SyncToast.show(title, "Tap to restore", symbol: "trash", hint: "Opens the Recycle Bin", in: window) {
793 let detail = recycled == 1 ? "Restore it from the Recycle Bin" : "Restore them from the Recycle Bin"
794 SyncToast.show(title, detail, symbol: "trash", hint: "Opens the Recycle Bin", in: window) {
789795 [notebook = self.notebook] in RecycleBinViewController.present(notebook, in: window)
790796 }
791797 }
apps/ios/Snowbound/Recycle.swift+40-21
......@@ -1,8 +1,9 @@
11import UIKit
22
33extension Notebook {
4 /// Whether the notebook keeps a recycle bin: a folder does, a lone section doesn't.
5 var hasRecycleBin: Bool { tabs.contains { !$0.path.isEmpty && !$0.path.hasPrefix("/") } }
4 /// Whether the notebook keeps a recycle bin: an open folder does, even with no sections
5 /// left, and a lone section, listed by its file's path or none, doesn't.
6 var hasRecycleBin: Bool { handle != nil && !tabs.contains { $0.path.isEmpty || $0.path.hasPrefix("/") } }
67}
78
89/// OneNote's Notebook Recycle Bin: the pages and sections deleted from a notebook, each
......@@ -14,6 +15,7 @@ final class RecycleBinViewController: UITableViewController {
1415 /// Deleted Pages, open while the bin shows.
1516 private var deleted: Section?
1617 private var sections: [Tab] = []
18 private var observers: [NSObjectProtocol] = []
1719
1820 /// Shows `notebook`'s bin as a sheet over the controller on top of `window`.
1921 static func present(_ notebook: Notebook, in window: UIWindow?) {
......@@ -33,16 +35,24 @@ final class RecycleBinViewController: UITableViewController {
3335
3436 required init?(coder: NSCoder) { fatalError() }
3537
38 deinit { observers.forEach(NotificationCenter.default.removeObserver) }
39
3640 override func viewDidLoad() {
3741 super.viewDidLoad()
3842 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "binned")
3943 navigationItem.rightBarButtonItem = UIBarButtonItem(
4044 systemItem: .done, primaryAction: UIAction { [weak self] _ in self?.dismiss(animated: true) })
41 NotificationCenter.default.addObserver(forName: Section.changed, object: nil, queue: .main) { [weak self] note in
42 if let self, note.object as AnyObject? === deleted { show() }
43 }
44 NotificationCenter.default.addObserver(forName: Notebook.listed, object: notebook, queue: .main) { [weak self] _ in
45 self?.reload()
45 observers = [
46 NotificationCenter.default.addObserver(forName: Section.changed, object: nil, queue: .main) { [weak self] note in
47 if let self, note.object as AnyObject? === deleted { show() }
48 },
49 NotificationCenter.default.addObserver(forName: Notebook.listed, object: notebook, queue: .main) {
50 [weak self] _ in self?.reload()
51 },
52 ]
53 // Each row's Restore button takes its size as the row is made.
54 registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, _) in
55 self.tableView.reloadData()
4656 }
4757 var loading = UIContentUnavailableConfiguration.loading()
4858 loading.text = "Opening…"
......@@ -53,26 +63,29 @@ final class RecycleBinViewController: UITableViewController {
5363 private var pages: [Row] { deleted?.rows ?? [] }
5464
5565 private func reload() {
56 guard let library = notebook.handle else { return }
66 guard let library = notebook.handle else { return failed(notebook.problem) }
5767 let pointer = Int(bitPattern: library)
5868 background({ decode([Tab].self, sb_library_recycle_bin(OpaquePointer(bitPattern: pointer))) }) { [weak self] tabs in
5969 guard let self else { return }
60 guard let tabs else {
61 var failed = UIContentUnavailableConfiguration.empty()
62 failed.text = "Can’t Open Recycle Bin"
63 failed.secondaryText = "Check that the notebook can be reached, then try again."
64 contentUnavailableConfiguration = failed
65 return
66 }
70 guard let tabs else { return failed(nil) }
6771 sections = tabs.filter { $0.path != Self.deletedPages }
6872 guard deleted == nil, let tab = tabs.first(where: { $0.path == Self.deletedPages }) else { return show() }
69 Section.open(tab, of: notebook) { [weak self] section, _ in
73 Section.open(tab, of: notebook) { [weak self] section, problem in
74 guard let section else { return self?.failed(problem) ?? () }
7075 self?.deleted = section
7176 self?.show()
7277 }
7378 }
7479 }
7580
81 /// Says the bin can't be read, rather than that it is empty.
82 private func failed(_ problem: String?) {
83 var failed = UIContentUnavailableConfiguration.empty()
84 failed.text = "Can’t Open Recycle Bin"
85 failed.secondaryText = problem ?? "Check that the notebook can be reached, then try again."
86 contentUnavailableConfiguration = failed
87 }
88
7689 private func show() {
7790 tableView.reloadData()
7891 var empty = UIContentUnavailableConfiguration.empty()
......@@ -119,6 +132,7 @@ final class RecycleBinViewController: UITableViewController {
119132 let button = UIButton(configuration: restore)
120133 button.menu = menu(at: indexPath)
121134 button.showsMenuAsPrimaryAction = true
135 button.accessibilityLabel = "Restore \(content.text ?? "")"
122136 button.sizeToFit()
123137 cell.accessoryView = button
124138 return cell
......@@ -142,16 +156,21 @@ final class RecycleBinViewController: UITableViewController {
142156 Arranging.move(page: page, of: notebook, from: Self.deletedPages, to: tab.path)
143157 }
144158 }
145 return UIMenu(title: "Restore To", children: choices)
159 let none = UIAction(title: "No Sections", subtitle: "Add or restore a section first", attributes: .disabled) { _ in }
160 return UIMenu(title: "Restore To", children: choices.isEmpty ? [none] : choices)
146161 }
147162 let path = sections[indexPath.row].path
148163 let file = path.split(separator: "/").last.map(String.init) ?? path
149164 let choices = ([""] + notebook.groups).map { folder in
150 // A section of the same file name there would refuse it.
151 let taken = notebook.entries(in: folder).contains { $0.split(separator: "/").last.map(String.init) == file }
152 return UIAction(title: folder.isEmpty ? notebook.name : place(folder), attributes: taken ? .disabled : []) {
153 [notebook] _ in Arranging.place(path, of: notebook, in: folder)
165 // A section of the same file name there would refuse it, as the file systems
166 // notebooks live on ignore case.
167 let taken = notebook.entries(in: folder).contains {
168 ($0.split(separator: "/").last.map(String.init) ?? $0).caseInsensitiveCompare(file) == .orderedSame
154169 }
170 return UIAction(
171 title: folder.isEmpty ? notebook.name : place(folder),
172 subtitle: taken ? "A section with this name is already here" : nil, attributes: taken ? .disabled : []
173 ) { [notebook] _ in Arranging.place(path, of: notebook, in: folder) }
155174 }
156175 return UIMenu(title: "Restore To", children: choices)
157176 }
apps/ios/Snowbound/Sync.swift+8-1
......@@ -172,7 +172,14 @@ enum SyncToast {
172172 ])
173173 UIView.animate(withDuration: 0.3) { toast.alpha = 1 }
174174 UIAccessibility.post(notification: .announcement, argument: "\(title). \(detail)")
175 DispatchQueue.main.asyncAfter(deadline: .now() + 6, execute: dismiss)
175 // VoiceOver needs time to reach it, so it stays while VoiceOver runs.
176 func expire() {
177 DispatchQueue.main.asyncAfter(deadline: .now() + 6) { [weak toast] in
178 guard toast?.superview != nil else { return }
179 if UIAccessibility.isVoiceOverRunning { expire() } else { dismiss() }
180 }
181 }
182 expire()
176183 }
177184}
178185
crates/mobile/include/snowbound.h+1
......@@ -74,6 +74,7 @@ char *sb_library_move_page(const Library *library, const char *from, const char
7474 uint32_t level, const char *discard, const char *author, const char *date, const char *time);
7575char *sb_library_place(const Library *library, const char *path, const char *folder, const char *paths);
7676char *sb_library_recycle_bin(const Library *library);
77void sb_library_purge_recycle_bin(const Library *library);
7778bool sb_library_delete(const Library *library, const char *path);
7879char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query);
7980char *sb_library_tagged(const Library *library);
crates/mobile/src/library.rs+26-2
......@@ -718,8 +718,9 @@ impl Library {
718718 if matches!(self.place, Place::File(_) | Place::Document(..)) {
719719 return Ok(Vec::new());
720720 }
721 // Listed again, a share's bin sections open by the identities the listing keeps.
722 self.tabs()?;
721723 self.with_notebook(false, |notebook| {
722 notebook.refresh()?;
723724 let mut binned = Vec::new();
724725 let catalog = notebook.catalog();
725726 if let Some(bin) = catalog
......@@ -733,13 +734,28 @@ impl Library {
733734 })
734735 }
735736
737 /// Deletes for good what the recycle bin has held unchanged past OneNote's 60 days, as
738 /// OneNote 2010 prunes it after opening; a guest leaves that to its host's notebook, and a
739 /// share not reached is left for the next time.
740 pub(crate) fn purge_recycle_bin(&self) -> Result<usize> {
741 if matches!(self.place, Place::Hosted(_)) || self.notebook().is_none() {
742 return Ok(0);
743 }
744 // Time32 counts seconds from 1980; FILETIME, tenths of microseconds from 1601.
745 let now = (filetime() / 10_000_000).saturating_sub(11_960_006_400);
746 let now = u32::try_from(now).unwrap_or(u32::MAX);
747 self.with_notebook(true, |notebook| Ok(notebook.purge_recycle_bin(now)?))
748 }
749
736750 /// Moves the section or group at catalog `path` into the recycle bin, as OneNote 2010
737751 /// deletes one.
738752 pub(crate) fn delete(&self, path: &str) -> Result<()> {
739753 self.with_notebook(true, |notebook| {
740754 notebook.refresh()?;
741755 Ok(notebook.delete(path)?)
742 })
756 })?;
757 // Listed again, the background syncs the binned sections, edits waiting among them.
758 self.tabs().map(drop)
743759 }
744760
745761 /// The section at catalog `path`, through a replica in the cache, following Work
......@@ -2092,6 +2108,14 @@ pub extern "C" fn sb_library_recycle_bin(library: &Library) -> *mut c_char {
20922108 json(library.recycle_bin())
20932109}
20942110
2111/// Deletes for good what the notebook's recycle bin has held unchanged past 60 days, as
2112/// OneNote 2010 does after opening a notebook. Writes to the notebook, so call it off the main
2113/// thread.
2114#[unsafe(no_mangle)]
2115pub extern "C" fn sb_library_purge_recycle_bin(library: &Library) {
2116 report(library.purge_recycle_bin());
2117}
2118
20952119/// Moves the section or group at catalog `path` into the notebook's recycle bin; false where
20962120/// it can't. Writes to the notebook, so call it off the main thread.
20972121///
crates/mobile/src/tests.rs+145
......@@ -618,6 +618,63 @@ fn deleted_pages_and_sections_restore_from_the_recycle_bin_to_where_they_are_put
618618 );
619619}
620620
621/// A group deleted through the C surface takes its sections to the recycle bin, one with an
622/// edit not yet published keeping it there; and a page leaves Deleted Pages while the bin
623/// holds it open, as the iOS sheet does.
624#[test]
625fn a_group_with_an_unpublished_edit_goes_to_the_bin_and_an_open_bin_gives_up_its_page() {
626 const DELETED: &str = "OneNote_RecycleBin/OneNote_DeletedPages.one";
627 let date = ["Monday, October 19, 2026", "9:00 AM"];
628 let (_directory, root, library, features) = notebook_open("Features.one", true);
629 let duplicate = open(&library, "Group A/Duplicate.one");
630 let before = duplicate.rows().unwrap().len();
631 duplicate.new_page(None, date[0], date[1]).unwrap();
632 duplicate.shared.section.written().unwrap();
633 drop(duplicate);
634 let group = CString::new("Group A").unwrap();
635 assert!(unsafe { library::sb_library_delete(&library, group.as_ptr()) });
636 let binned = "OneNote_RecycleBin/Duplicate.one";
637 let listed = take_json(library::sb_library_recycle_bin(&library));
638 assert!(
639 listed
640 .as_array()
641 .unwrap()
642 .iter()
643 .any(|tab| tab["path"] == binned)
644 );
645 assert!(!root.join("Group A").exists());
646 sb_library_set_offline(&library, false);
647 sb_library_sync_now(&library);
648 let stored = || {
649 let bytes = std::fs::read(root.join(binned)).unwrap();
650 notebook::session::stored_pages(&bytes).unwrap().len()
651 };
652 assert!(
653 eventually(|| stored() == before + 1),
654 "the edit reached the binned section"
655 );
656
657 let space = features.rows().unwrap()[0].id.parse().unwrap();
658 features.delete_page(space, date[0], date[1]).unwrap();
659 drop(features);
660 let bin = open(&library, DELETED);
661 let recycled = bin.shared.section.pages().unwrap()[0].0;
662 let restored = library
663 .move_page(
664 DELETED,
665 recycled,
666 "Features.one",
667 None,
668 1,
669 None,
670 "Clover Test",
671 date,
672 )
673 .unwrap();
674 assert_eq!((restored.added, restored.copied), (None, None));
675 assert!(bin.shared.section.pages().unwrap().is_empty());
676}
677
621678#[test]
622679fn deleting_a_lone_section_page_still_creates_its_replacement_without_a_bin() {
623680 let directory = tempfile::tempdir().unwrap();
......@@ -4341,3 +4398,91 @@ fn a_provider_that_lists_but_cannot_open_opens_from_the_offline_copies() {
43414398 assert!(stored_text(&file, space).contains("Offline"));
43424399 closed(section);
43434400}
4401
4402/// A page restored from a share's recycle bin while working offline waits in the cache and
4403/// publishes once online: a cold reopen finds it, content and identity kept, in the section
4404/// it was restored to, and Deleted Pages empty. `ONESTORE_SMB_LAB=HOST:PORT` names a guest
4405/// share `agent` (`tools/w7/linux_vm.py up NAME`); the notebook goes in a fresh folder.
4406#[test]
4407#[ignore = "requires an owned Samba share at ONESTORE_SMB_LAB"]
4408fn a_page_restored_offline_on_a_share_publishes_once_online() {
4409 const DELETED: &str = "OneNote_RecycleBin/OneNote_DeletedPages.one";
4410 let date = ["Monday, October 19, 2026", "9:00 AM"];
4411 let server = || library::Server {
4412 address: std::env::var("ONESTORE_SMB_LAB").unwrap(),
4413 share: "agent".into(),
4414 user: String::new(),
4415 password: String::new(),
4416 domain: String::new(),
4417 };
4418 let root = format!("snowbound-recycle-{}", std::process::id());
4419 let directory = tempfile::tempdir().unwrap();
4420 let client = Arc::new(server().connect().unwrap());
4421 client.create_directory(&root).unwrap();
4422 let mut notebook = notebook::session::Notebook::open_smb(
4423 Arc::clone(&client),
4424 &root,
4425 directory.path().join("made"),
4426 )
4427 .unwrap();
4428 for (name, title) in [("Kept", "Restored over SMB"), ("Target", "Already there")] {
4429 let page = onestore::PageCreation::new(None, Some(title), "Clover Test").unwrap();
4430 notebook.create_section("", name, &page).unwrap();
4431 }
4432 drop(notebook);
4433
4434 let library =
4435 Arc::new(Library::server(server(), &root, &directory.path().join("cache")).unwrap());
4436 library.tabs().unwrap();
4437 let kept = open(&library, "Kept.one");
4438 let deleted = space(&kept, "Restored over SMB");
4439 let page = kept.shared.section.page(deleted).unwrap();
4440 kept.delete_page(deleted, date[0], date[1]).unwrap();
4441 drop(kept);
4442 // As the iOS sheet lists the bin, then opens Deleted Pages.
4443 assert_eq!(library.recycle_bin().unwrap()[0].path, DELETED);
4444 let bin = open(&library, DELETED);
4445 let recycled = bin.shared.section.pages().unwrap()[0].0;
4446
4447 sb_library_set_offline(&library, true);
4448 let restored = library
4449 .move_page(
4450 DELETED,
4451 recycled,
4452 "Target.one",
4453 None,
4454 1,
4455 None,
4456 "Clover Test",
4457 date,
4458 )
4459 .unwrap();
4460 assert_eq!((restored.added, restored.copied), (None, None));
4461 assert!(
4462 !bin.shared.section.pending().unwrap().is_empty(),
4463 "the bin's edit waits offline"
4464 );
4465 drop(bin);
4466 sb_library_set_offline(&library, false);
4467 sb_library_sync_now(&library);
4468 library.close(Duration::from_secs(60)).unwrap();
4469 drop(library);
4470
4471 let cold = Arc::new(Library::server(server(), &root, &directory.path().join("cold")).unwrap());
4472 cold.tabs().unwrap();
4473 let target = open(&cold, "Target.one");
4474 let arrived = space(&target, "Restored over SMB");
4475 assert_eq!(
4476 target.shared.section.page(arrived).unwrap().identity,
4477 page.identity
4478 );
4479 drop(target);
4480 assert!(
4481 open(&cold, DELETED)
4482 .shared
4483 .section
4484 .pages()
4485 .unwrap()
4486 .is_empty()
4487 );
4488}