Skip to content

Commit def40ba

Browse files
AlexW00claude
andcommitted
Fix macOS sidebar empty after restart or app update (#38)
Bookmarks were created and resolved with `options: []` instead of `.withSecurityScope`, so the sandbox access grant was not embedded in the bookmark data. macOS sometimes caches grants across restarts, masking the bug — but OS updates and app re-signs clear the cache, leaving `contentsOfDirectory` to fail silently and the sidebar empty. Changes: - Use `.withSecurityScope` when creating and resolving bookmarks - Check and log `startAccessingSecurityScopedResource()` return value - Replace silent `try?` in `contentsOfDirectory` with explicit error logging Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 156d7eb commit def40ba

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

ZettelMac/Stores/MacNoteStore.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,19 @@ public final class MacNoteStore: NSObject, NSFilePresenter {
115115
let directory = storageDirectory
116116
let notes = await Task.detached { () -> [Note] in
117117
let fm = FileManager.default
118-
guard let files = try? fm.contentsOfDirectory(
119-
at: directory,
120-
includingPropertiesForKeys: [
121-
.contentModificationDateKey,
122-
.creationDateKey,
123-
.ubiquitousItemDownloadingStatusKey
124-
],
125-
options: [.skipsHiddenFiles]
126-
) else {
118+
let files: [URL]
119+
do {
120+
files = try fm.contentsOfDirectory(
121+
at: directory,
122+
includingPropertiesForKeys: [
123+
.contentModificationDateKey,
124+
.creationDateKey,
125+
.ubiquitousItemDownloadingStatusKey
126+
],
127+
options: [.skipsHiddenFiles]
128+
)
129+
} catch {
130+
print("[MacNoteStore] Error listing directory \(directory.path): \(error)")
127131
return []
128132
}
129133

@@ -501,7 +505,7 @@ public final class MacNoteStore: NSObject, NSFilePresenter {
501505
private func saveStorageDirectoryBookmark(_ url: URL) {
502506
do {
503507
let bookmark = try url.bookmarkData(
504-
options: [],
508+
options: .withSecurityScope,
505509
includingResourceValuesForKeys: nil,
506510
relativeTo: nil
507511
)
@@ -520,7 +524,7 @@ public final class MacNoteStore: NSObject, NSFilePresenter {
520524
var isStale = false
521525
let url = try URL(
522526
resolvingBookmarkData: bookmark,
523-
options: [],
527+
options: .withSecurityScope,
524528
relativeTo: nil,
525529
bookmarkDataIsStale: &isStale
526530
)
@@ -529,7 +533,9 @@ public final class MacNoteStore: NSObject, NSFilePresenter {
529533
saveStorageDirectoryBookmark(url)
530534
}
531535

532-
_ = url.startAccessingSecurityScopedResource()
536+
if !url.startAccessingSecurityScopedResource() {
537+
print("[MacNoteStore] Warning: failed to start security-scoped access for \(url.path)")
538+
}
533539
return url
534540
} catch {
535541
print("[MacNoteStore] Error restoring bookmark: \(error)")

0 commit comments

Comments
 (0)