feature: OneDrive folder as a second send transport
send(anchor:) now branches on TransportSettings.transport(). OneDrive mode skips AirDrop entirely: it verifies the resolved OneDrive folder exists right before composing (never trusts stale state), archives the session immediately after the PDF lands, and sets "Saved to OneDrive — N page(s). Open it in Files on your iPad." AirDrop's existing behaviour, including handleDidFailToShareItems, is untouched and only reached from the .airDrop branch. AppModel seeds outbox/watch from TransportSettings.effectiveFolders() instead of FolderSettings.resolve() directly, tracks the live `transport`, and bootstrap() creates the OneDrive folder and sets the watcher's recordUncommented flag (true only for AirDrop) before the watcher starts. Settings gets a "Send via" segmented picker above Folders. AirDrop shows the existing watch/output rows; OneDrive shows a single read-only OneDrive folder row (Choose... reuses the existing directory picker) plus one caption explaining the same-folder round trip, or a "No OneDrive folder found" prompt when nothing resolves (Choose... stays usable). Switching transport re-points the watcher's folder and recordUncommended live; AirDrop's own folder overrides are stored separately and are untouched by a OneDrive-and-back round trip. Menu's "Send..." row reads "Send to OneDrive" when that transport is active. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ZiTXPbPCSjzPVsfoweAbp
This commit is contained in:
@@ -33,6 +33,25 @@ struct SettingsView: View {
|
||||
.frame(minHeight: 22)
|
||||
}
|
||||
|
||||
GridRow {
|
||||
Text("Send via")
|
||||
.font(.headline)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.gridCellColumns(2)
|
||||
.padding(.top, 6)
|
||||
}
|
||||
|
||||
GridRow {
|
||||
Picker("Send via", selection: transportBinding) {
|
||||
ForEach(SendTransport.allCases, id: \.self) { transport in
|
||||
Text(transport.displayName).tag(transport)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
.pickerStyle(.segmented)
|
||||
.gridCellColumns(2)
|
||||
}
|
||||
|
||||
GridRow {
|
||||
Text("Folders")
|
||||
.font(.headline)
|
||||
@@ -41,17 +60,48 @@ struct SettingsView: View {
|
||||
.padding(.top, 6)
|
||||
}
|
||||
|
||||
GridRow(alignment: .center) {
|
||||
fieldLabel("Watch folder")
|
||||
folderValue(path: model.watchFolderURL.path) {
|
||||
model.chooseWatchFolder()
|
||||
if model.transport == .airDrop {
|
||||
GridRow(alignment: .center) {
|
||||
fieldLabel("Watch folder")
|
||||
folderValue(path: model.watchFolderURL.path) {
|
||||
model.chooseWatchFolder()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GridRow(alignment: .center) {
|
||||
fieldLabel("Output folder")
|
||||
folderValue(path: model.outboxURL.path) {
|
||||
model.chooseOutboxFolder()
|
||||
GridRow(alignment: .center) {
|
||||
fieldLabel("Output folder")
|
||||
folderValue(path: model.outboxURL.path) {
|
||||
model.chooseOutboxFolder()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GridRow(alignment: .center) {
|
||||
fieldLabel("OneDrive folder")
|
||||
if let folder = resolvedOneDriveFolder {
|
||||
folderValue(path: folder.path) {
|
||||
model.chooseOneDriveFolder()
|
||||
}
|
||||
} else {
|
||||
HStack(spacing: 8) {
|
||||
Text("No OneDrive folder found — sign in to OneDrive or choose a folder.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Button("Choose…") { model.chooseOneDriveFolder() }
|
||||
}
|
||||
.frame(minHeight: 22)
|
||||
}
|
||||
}
|
||||
|
||||
GridRow {
|
||||
Text(
|
||||
"The PDF is saved here and this same folder is watched for the marked-up copy. On the iPad open it from Files > OneDrive."
|
||||
)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.gridCellColumns(2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +118,17 @@ struct SettingsView: View {
|
||||
.onDisappear { disarmHotkeyRecorder() }
|
||||
}
|
||||
|
||||
private var transportBinding: Binding<SendTransport> {
|
||||
Binding(get: { model.transport }, set: { model.chooseTransport($0) })
|
||||
}
|
||||
|
||||
/// Ground truth from OneDriveLocator, not `model.outboxURL` — the model may be
|
||||
/// showing an AirDrop-folder fallback when no real OneDrive folder resolves, and
|
||||
/// the Settings row must say so plainly rather than repeat that fallback path.
|
||||
private var resolvedOneDriveFolder: URL? {
|
||||
OneDriveLocator.resolveOneDriveFolder()
|
||||
}
|
||||
|
||||
private func armHotkeyRecorder() {
|
||||
guard !isRecordingHotkey else { return }
|
||||
isRecordingHotkey = true
|
||||
@@ -190,6 +251,53 @@ extension AppModel: SettingsWindowPresenting {
|
||||
}
|
||||
}
|
||||
|
||||
/// Settings "Send via" picker action. Persists the choice, recomputes the effective
|
||||
/// outbox/watch folder for the new transport, creates the OneDrive folder if it
|
||||
/// doesn't exist yet, and re-points the running watcher (folder + recordUncommented)
|
||||
/// at the new state. Switching back to AirDrop restores its own stored overrides
|
||||
/// untouched, since AirDrop and OneDrive folder settings are stored under separate keys.
|
||||
func chooseTransport(_ value: SendTransport) {
|
||||
guard value != transport else { return }
|
||||
TransportSettings.setTransport(value)
|
||||
setTransport(value)
|
||||
let folders = TransportSettings.effectiveFolders()
|
||||
if value == .oneDrive {
|
||||
try? FileManager.default.createDirectory(
|
||||
at: folders.outbox, withIntermediateDirectories: true
|
||||
)
|
||||
}
|
||||
setFolderURLs(outbox: folders.outbox, watch: folders.watch)
|
||||
Task {
|
||||
await watcher.setRecordUncommented(value == .airDrop)
|
||||
do {
|
||||
try await watcher.updateWatchFolder(folders.watch)
|
||||
} catch {
|
||||
setStatus(
|
||||
(error as? ShotdeckError)?.errorDescription ?? "Could not switch the watch folder."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func chooseOneDriveFolder() {
|
||||
let start = OneDriveLocator.resolveOneDriveFolder() ?? FileManager.default.homeDirectoryForCurrentUser
|
||||
guard let url = chooseDirectory(startingAt: start) else { return }
|
||||
TransportSettings.setOneDriveFolder(url)
|
||||
try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
||||
guard transport == .oneDrive else { return }
|
||||
setFolderURLs(outbox: url, watch: url)
|
||||
Task {
|
||||
do {
|
||||
try await watcher.updateWatchFolder(url)
|
||||
setStatus("OneDrive folder set to \(url.lastPathComponent).")
|
||||
} catch {
|
||||
setStatus(
|
||||
(error as? ShotdeckError)?.errorDescription ?? "Could not switch the watch folder."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func chooseDirectory(startingAt directory: URL) -> URL? {
|
||||
let panel = NSOpenPanel()
|
||||
panel.canChooseDirectories = true
|
||||
|
||||
Reference in New Issue
Block a user