Docs native: Oficina ID sign-in (slice A), plain-name menus, Settings, quiet updates
First native app on Oficina ID (spec Home 979dac4): RastrilloApple's kit onboarding is the first screen, the old server/browser sign-in stays under "Other ways to sign in…" (existing accounts keep it until replaced); entitlements on Sparkle, Mac App Store and iOS builds (Docs' keychain group first, then 9U4A84C4WK.works.oficina.id, app group, webcredentials: id.oficina.works), the Developer ID profile referenced by local path, never committed; per-request team sessions with 24 h and rate-limited 401 re-mint; team refresh at launch / picker / 403; offline store keyed by a fixed origin for Oficina ID accounts (survives team moves); live clients in Mac document windows; identity-wide sign-out guard with stated reasons; workspace stays mounted when Oficina ID is unreachable; --oficina-id-launch-check; PlainAppNameCommands, a Settings window, 12 localizations, quiet updates; snapshot catalog. Pins rastrillo/native main f1c7a14. Reviewed by Fable: APPROVE AFTER FIXES at d143194, APPROVE at 808018e; 61e06d0's two small changes checked by the lander. 10-gate and 20-native green; hub CI passed at 61e06d0. Release 0.1.8 (10) notarised from this tree; launch check passes on the stapled app. Squashed from native/oficina-id-slice-a into main.
99 files changed,
+2,108
−65
internal/lint/no_sessions_userid_test.go+3 −1native/BUILDING.md+76 −0native/apple/Package.resolved+1 −1native/apple/Package.swift+8 −1native/apple/Sources/DocsApp/DocsAccountWindow.swift+225 −30native/apple/Sources/DocsApp/DocsApp.swift+61 −4native/apple/Sources/DocsApp/DocsDocumentWindow.swift+1 −1native/apple/Sources/DocsApp/DocsWindows.swift+24 −0native/apple/Sources/DocsKit/DocsAttachments.swift+2 −2native/apple/Sources/DocsKit/DocsEditorContext.swift+1 −1native/apple/Sources/DocsKit/DocsJumpControls.swift+1 −1native/apple/Sources/DocsKit/DocsOfflineAccount.swift+47 −5native/apple/Sources/DocsKit/DocsOficinaID.swift+342 −0native/apple/Sources/DocsKit/DocsOficinaViews.swift+227 −0native/apple/Sources/DocsKit/DocsSharingView.swift+1 −1native/apple/Sources/DocsKit/DocsWorkspace.swift+47 −11native/apple/Sources/DocsKit/DocumentExportControls.swift+2 −2native/apple/Sources/DocsKit/Resources/Colophon.json+1 −1native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings+14 −0native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings+14 −0native/apple/Tests/DocsKitTests/OficinaIDAdoptionTests.swift+448 −0native/apple/Tests/DocsSnapshots/DocsSnapshots.swift+163 −0native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/ENVIRONMENT+10 −0native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-ax3.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/ENVIRONMENT+9 −0native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-light-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-dark-default.pngbinarynative/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-light-default.pngbinarynative/apple/Tests/DocsWindowTests/WindowRoutingTests.swift+26 −0native/ios/DocsPhone.entitlements+23 −0native/ios/Info.plist+15 −0native/ios/project.yml+49 −1native/mac-updates.json+17 −0native/macos/AppStore.entitlements+17 −0native/macos/DeveloperID.entitlements+23 −0native/macos/Info.plist+15 −0native/macos/project.yml+18 −1native/notices/native/provenance.json+1 −1native/scripts/snapshots.sh+36 −0
CI passed — run details
landed from native/oficina-id-slice-a
diff --git a/internal/lint/no_sessions_userid_test.go b/internal/lint/no_sessions_userid_test.go| index f6df02f..740d3c4 100644 |
| --- a/internal/lint/no_sessions_userid_test.go |
| +++ b/internal/lint/no_sessions_userid_test.go |
| @@ -53,7 +53,9 @@ func repoRoot(t *testing.T) string { |
| // only slow this test down for nothing. |
| func skipDir(name string) bool { |
| switch name { |
| - case ".git", "node_modules", "target": |
| + // .build is SwiftPM's and Xcode's: checkouts of other repositories |
| + // (rastrillo/native's own server among them), never Docs' code. |
| + case ".git", "node_modules", "target", ".build": |
| return true |
| } |
| return false |
diff --git a/native/BUILDING.md b/native/BUILDING.md| index 6788229..5e85ccb 100644 |
| --- a/native/BUILDING.md |
| +++ b/native/BUILDING.md |
| @@ -54,3 +54,79 @@ Native UI tests use fresh local credentials and isolated databases. See |
| [REVIEW.md](REVIEW.md) for their runner, exact evidence, and untested behavior. |
| Performance measurements and their limits are in |
| [benchmarks/README.md](benchmarks/README.md). |
| + |
| +## Oficina ID: entitlements, profiles and the launch check |
| + |
| +Docs signs in with Oficina ID first (Home's |
| +`docs/superpowers/specs/2026-11-14-oficina-id-native.md`, slice A), through |
| +rastrillo/native's `RastrilloApple/OficinaID` kit. "Other ways to sign in…" |
| +keeps the server address and browser approval. The kit needs these grants on |
| +every build: |
| + |
| +| Build | File | App group | |
| +| --- | --- | --- | |
| +| Mac, Sparkle (Developer ID) | `macos/DeveloperID.entitlements`, named by `mac-updates.json` | `9U4A84C4WK.works.oficina` | |
| +| Mac App Store | `macos/AppStore.entitlements` | `9U4A84C4WK.works.oficina` | |
| +| iPhone and iPad | `ios/DocsPhone.entitlements` | `group.works.oficina` | |
| + |
| +All three have `keychain-access-groups` = `9U4A84C4WK.works.oficina.docs` |
| +**first**, then `9U4A84C4WK.works.oficina.id` (a query that names no group |
| +lands in the first, and Docs' own items must never land in the group every |
| +Oficina app reads), and `webcredentials:id.oficina.works`. |
| + |
| +A Developer ID Mac app that claims these without an embedded provisioning |
| +profile is killed at launch. `mac-updates.json` names the profile by its local |
| +path, `~/private_keys/oficina/profiles/Oficina-Docs-macOS-Developer-ID.provisionprofile`; |
| +the profile itself is never committed. Elsewhere, pass |
| +`--provisioning-profile <path>`, which wins over the configuration, to |
| +`scripts/build-mac.sh` and to rastrillo's `release_mac.py`. A signed build: |
| + |
| +```sh |
| +native/scripts/build-mac.sh --updates-config mac-updates.json \ |
| + --sign-identity 'Developer ID Application: Team Tito Limited (9U4A84C4WK)' |
| +``` |
| + |
| +An ad hoc build (no `--sign-identity`) drops those grants and says so on |
| +stderr. It still runs, but Oficina ID cannot read the keychain there |
| +(-34018), so Welcome says it couldn't be read. Simulator builds |
| +(`CODE_SIGNING_ALLOWED=NO`) are the same. |
| + |
| +**The launch check** is the spec's launch gate (§13): before any Sparkle |
| +publish, run the final signed, notarised artifact's executable with |
| +`--oficina-id-launch-check`. |
| + |
| +```sh |
| +"native/build/Oficina Docs.app/Contents/MacOS/DocsMac" --oficina-id-launch-check |
| +``` |
| + |
| +macOS checks the embedded profile as the process starts. The check then reads |
| +the signed entitlements (the keychain groups in order, the App Group, the |
| +associated domain) and both keychain groups, prints counts (never an identity |
| +or a session) and exits 0 only if all of them work. An ad hoc build, or the |
| +unsigned test runner (`OficinaIDAdoptionTests`), fails every line. |
| + |
| +An Oficina ID team's offline store key is filed under one fixed origin, not the |
| +team's, so a team whose address changes (a label moved, a rename, self-hosting |
| +by DNS) keeps its store and unsent outbox. Docs refreshes the team list at |
| +launch, when the team picker opens (at most every five minutes) and on a 403, |
| +through the kit's `refreshTeams`. Signing out, switching team or replacing the |
| +Oficina ID waits for every team's outbox to drain, those a crash left on disk |
| +included, and on the Mac for every document window of the identity to close; |
| +the picker and Settings say which. |
| + |
| +Sign-in itself needs Home's native endpoints at `id.oficina.works` and the |
| +directory at `oficina.works`; passkeys also need Home's association file. The |
| +kit's in-memory `FakeOficinaIDService` stands in for all of them in |
| +`OficinaIDAdoptionTests` and the screenshot gate. |
| + |
| +## The screenshot gate |
| + |
| +`native/scripts/snapshots.sh [compare|record] [mac|iphone|all]` draws Docs' key |
| +screens (library, Oficina ID onboarding, Other ways to sign in, the team |
| +picker, Mac Settings) in light and dark, and on iPhone at AX3 too, and compares |
| +them with `apple/Tests/DocsSnapshots/__Snapshots__/docs`. The contact sheet is |
| +`apple/.build/snapshots/docs/index.html`. It is not in `.amadan/ci.d`: |
| +baselines are exact only on the OS and simulator runtime that drew them |
| +(`ENVIRONMENT` beside them). After an intended change, `record`, read the |
| +contact sheet, and commit the pictures in pushes under about 700 KB: the hub |
| +drops a push whose pack is over about 1 MB. |
diff --git a/native/apple/Package.resolved b/native/apple/Package.resolved| index bbefb0f..25ad9fc 100644 |
| --- a/native/apple/Package.resolved |
| +++ b/native/apple/Package.resolved |
| @@ -6,7 +6,7 @@ |
| "kind" : "remoteSourceControl", |
| "location" : "https://amadan.net/rastrillo/native", |
| "state" : { |
| - "revision" : "b6a4067e39efd641fd5fa149cc666fee47bdb9b5" |
| + "revision" : "f1c7a14db2ddb8960afabc8268cd92c490543397" |
| } |
| }, |
| { |
diff --git a/native/apple/Package.swift b/native/apple/Package.swift| index 3ca2a09..307a172 100644 |
| --- a/native/apple/Package.swift |
| +++ b/native/apple/Package.swift |
| @@ -3,7 +3,7 @@ import PackageDescription |
| import Foundation |
| let sharedNative: Package.Dependency = ProcessInfo.processInfo.environment["OFICINA_NATIVE_PACKAGE_PATH"].map { .package(name: "native", path: $0) } |
| - ?? .package(url: "https://amadan.net/rastrillo/native", revision: "b6a4067e39efd641fd5fa149cc666fee47bdb9b5") |
| + ?? .package(url: "https://amadan.net/rastrillo/native", revision: "f1c7a14db2ddb8960afabc8268cd92c490543397") |
| let package = Package(name: "DocsNative", defaultLocalization: "en", platforms: [.macOS(.v26), .iOS(.v26)], |
| products: [.library(name: "DocsKit", targets: ["DocsKit"]), .executable(name: "DocsMac", targets: ["DocsMac"])], |
| @@ -14,4 +14,11 @@ let package = Package(name: "DocsNative", defaultLocalization: "en", platforms: |
| .executableTarget(name: "DocsMac", dependencies: [.product(name: "RastrilloMacUpdates", package: "native", condition: .when(platforms: [.macOS])), "DocsKit", .product(name: "RastrilloApple", package: "native")], path: "Sources/DocsApp"), |
| .testTarget(name: "DocsKitTests", dependencies: ["DocsKit", .product(name: "RastrilloTestSupport", package: "native")]), |
| .testTarget(name: "DocsWindowTests", dependencies: ["DocsMac", .product(name: "RastrilloApple", package: "native")]), |
| + // The screenshot gate's Mac half; native/scripts/snapshots.sh runs it, |
| + // plain `swift test` skips it. ios/project.yml builds the same file |
| + // as DocsPhoneSnapshots for the iPhone half. |
| + .testTarget(name: "DocsSnapshots", dependencies: ["DocsKit", .product(name: "RastrilloSnapshots", package: "native"), |
| + .product(name: "RastrilloApple", package: "native"), |
| + .product(name: "RastrilloTestSupport", package: "native")], |
| + exclude: ["__Snapshots__"]), |
| ]) |
diff --git a/native/apple/Sources/DocsApp/DocsAccountWindow.swift b/native/apple/Sources/DocsApp/DocsAccountWindow.swift| index 472739f..abb08b6 100644 |
| --- a/native/apple/Sources/DocsApp/DocsAccountWindow.swift |
| +++ b/native/apple/Sources/DocsApp/DocsAccountWindow.swift |
| @@ -4,12 +4,39 @@ import SwiftUI |
| /// Each window owns its navigation and model lifetime. Switching an account in |
| /// one window must never discard another window's unconfirmed edits. |
| +/// |
| +/// Sign-in is Oficina ID first (spec 2026-11-14-oficina-id-native, slice A): |
| +/// the kit's onboarding until its model is signed in to a team, then that |
| +/// team's workspace. "Other ways to sign in…" is the server address and |
| +/// browser approval that came before, kept for self-hosted servers and local |
| +/// accounts; someone already signed in that way keeps those accounts until an |
| +/// Oficina ID replaces them (`DocsSignInRoute`). |
| struct DocsAccountWindow: View { |
| + @ObservedObject private var oficina: DocsOficinaSession |
| + @ObservedObject private var model: OficinaIDModel |
| + /// Why a sign-out or "Use another" was refused: said, not swallowed. |
| + @State private var leaveRefusal: DocsLeaveBlock? |
| @StateObject private var connection = NativeConnection(defaultServer: "https://docs.oficina.works") |
| + @AppStorage(DocsSignInRoute.key) private var storedRoute = "" |
| + @State private var pickingTeam = false |
| + @Environment(\.scenePhase) private var scenePhase |
| #if os(macOS) |
| @Bindable var windows: DocsWindows |
| @Environment(\.openWindow) private var openWindow |
| #endif |
| + |
| + #if os(macOS) |
| + init(oficina: DocsOficinaSession, windows: DocsWindows) { |
| + _oficina = ObservedObject(wrappedValue: oficina); _model = ObservedObject(wrappedValue: oficina.model); _windows = Bindable(windows) |
| + } |
| + #else |
| + init(oficina: DocsOficinaSession) { _oficina = ObservedObject(wrappedValue: oficina); _model = ObservedObject(wrappedValue: oficina.model) } |
| + #endif |
| + |
| + private var route: DocsSignInRoute { |
| + DocsSignInRoute.resolve(stored: storedRoute, hasServerAccounts: !connection.accounts.isEmpty) |
| + } |
| + |
| private func transport(for account: String?) -> @MainActor () -> NativeTransport? { |
| let connection = connection |
| return DocsAccountTransport.supplier(account: account, |
| @@ -19,41 +46,209 @@ struct DocsAccountWindow: View { |
| var body: some View { |
| Group { |
| - if let client = connection.client { |
| - #if os(macOS) |
| - if let account = connection.activeAccountID { |
| - DocsWorkspace(client: client, accountID: account, transport: transport(for: account), accounts: connection.showAccounts, signOut: { |
| - guard connection.activeAccountID == account, windows.canSignOut(account) else { return } |
| - windows.entries.removeAll { $0.account == account } |
| - connection.signOut() |
| - }, createDocument: { |
| - guard connection.activeAccountID == account else { return } |
| - let id = windows.reserveDraft(account: account, client: client) |
| - openWindow(id: "document", value: id) |
| - }, canSignOut: windows.canSignOut(account), createRequested: $windows.createRequested, accountsRequested: $windows.accountsRequested, openDocument: { document, title in |
| - guard connection.activeAccountID == account else { return } |
| - let id = windows.reserve(account: account, document: document, title: title, client: client) |
| - openWindow(id: "document", value: id) |
| - }, updateRecents: { documents in |
| - guard connection.activeAccountID == account else { return } |
| - windows.updateRecents(documents, account: account, client: client) |
| - }) |
| - .id(account) |
| + switch route { |
| + case .oficinaID: |
| + // The mounted team stays while Oficina ID can't re-mint it (§11), with |
| + // the line saying so over it, rather than unmounting an open editor. |
| + if let state = oficina.mounted { oficinaWorkspace(state).safeAreaInset(edge: .top, spacing: 0) { oficinaBanner } } |
| + else { OficinaOnboardingView(model: model, otherWays: { storedRoute = DocsSignInRoute.server.rawValue }) } |
| + case .server: |
| + if let client = connection.client { serverWorkspace(client) } |
| + else { DocsOtherWaysView(connection: connection) { storedRoute = DocsSignInRoute.oficinaID.rawValue } } |
| + } |
| + } |
| + .onOpenURL(perform: connection.handleOpenURL) |
| + .task { await oficina.start() } |
| + // A sign-in with Oficina ID replaces the other ways for good (Appendix C). |
| + // Only one made here: an identity restored at launch (another app's, or |
| + // last run's) leaves the route someone chose alone. |
| + .onChange(of: oficina.signIns) { _, _ in storedRoute = DocsSignInRoute.oficinaID.rawValue } |
| + // "Use another" signs the identity out on every app: Docs' guards first. |
| + .onChange(of: model.confirmingReplace) { _, confirming in |
| + guard confirming, let identity = model.identity?.id else { return } |
| + Task { |
| + if let block = await DocsLeaveBlock.check(identity: identity, openDocuments: openDocuments(of: identity)) { |
| + model.cancelReplace(); leaveRefusal = block |
| } |
| - #else |
| - DocsWorkspace(client: client, accountID: connection.activeAccountID, transport: transport(for: connection.activeAccountID), accounts: connection.showAccounts, signOut: connection.signOut) |
| - .id(connection.activeAccountID) |
| - #endif |
| - } else { |
| - NativeAccountsView("Docs", systemImage: "doc.text", connection: connection) |
| } |
| - }.onOpenURL(perform: connection.handleOpenURL) |
| + } |
| + .alert(leaveRefusal?.message ?? "", isPresented: Binding(get: { leaveRefusal != nil }, set: { if !$0 { leaveRefusal = nil } })) { |
| + Button(OficinaIDText.text("cancel"), role: .cancel) { leaveRefusal = nil } |
| + } |
| + .onChange(of: scenePhase) { _, phase in |
| + if phase == .active { Task { await oficina.renewIfNeeded() } } |
| + } |
| #if os(macOS) |
| .onChange(of: windows.accountsRequested, initial: true) { _, requested in |
| - if requested && connection.client == nil { windows.accountsRequested = false } |
| + if requested && currentClient == nil { windows.accountsRequested = false } |
| + } |
| + .onChange(of: windows.signOutRequested, initial: true) { _, requested in |
| + if requested && currentClient == nil { windows.signOutRequested = false } |
| + } |
| + .focusedSceneValue(\.docsWindowAccount, currentAccount) |
| + .onChange(of: currentAccount, initial: true) { _, value in windows.activeAccount = value } |
| + .onChange(of: settingsAccount, initial: true) { _, value in windows.settingsAccount = value } |
| + .onChange(of: route == .oficinaID ? oficina.mounted?.identity.id : nil, initial: true) { _, value in windows.settingsIdentity = value } |
| + #endif |
| + } |
| + |
| + private var currentAccount: String? { |
| + switch route { |
| + case .oficinaID: return oficina.mounted.map(DocsOficinaSession.accountID) |
| + case .server: return connection.activeAccountID |
| + } |
| + } |
| + |
| + private var currentClient: NativeHTTP? { |
| + switch route { |
| + case .oficinaID: return oficina.mounted.flatMap { oficina.client(for: DocsOficinaSession.accountID($0)) } |
| + case .server: return connection.client |
| + } |
| + } |
| + |
| + // MARK: Oficina ID |
| + |
| + @ViewBuilder private func oficinaWorkspace(_ state: OficinaSignedIn) -> some View { |
| + let account = DocsOficinaSession.accountID(state) |
| + let client = oficina.client(for: account) ?? state.client() |
| + #if os(macOS) |
| + let canLeave = !openDocuments(of: state.identity.id) |
| + DocsWorkspace(client: client, accountID: account, transport: oficina.transport(for: account), accounts: { pickingTeam = true }, signOut: { |
| + signOutOficinaID(state) |
| + }, createDocument: { |
| + guard currentAccount == account else { return } |
| + let id = windows.reserveDraft(account: account, client: client) |
| + openWindow(id: "document", value: id) |
| + }, canSignOut: canLeave, createRequested: $windows.createRequested, accountsRequested: $windows.accountsRequested, |
| + signOutRequested: $windows.signOutRequested, accountsLabel: teamsLabel, signOutLabel: OficinaIDText.text("signOut", state.identity.label), |
| + openDocument: { document, title in |
| + guard currentAccount == account else { return } |
| + let id = windows.reserve(account: account, document: document, title: title, client: client) |
| + openWindow(id: "document", value: id) |
| + }, updateRecents: { documents in |
| + guard currentAccount == account else { return } |
| + windows.updateRecents(documents, account: account, client: client) |
| + }) |
| + .id(account) |
| + .onAppear { windows.transports[account] = oficina.transport(for: account) } |
| + .safeAreaInset(edge: .bottom, spacing: 0) { passkeyNudge } |
| + .sheet(isPresented: $pickingTeam) { teamPicker(state) } |
| + #else |
| + DocsWorkspace(client: client, accountID: account, transport: oficina.transport(for: account), accounts: { pickingTeam = true }, |
| + signOut: { signOutOficinaID(state) }, accountsLabel: teamsLabel, |
| + signOutLabel: OficinaIDText.text("signOut", state.identity.label)) |
| + .id(account) |
| + .safeAreaInset(edge: .bottom, spacing: 0) { passkeyNudge } |
| + .sheet(isPresented: $pickingTeam) { teamPicker(state) } |
| + #endif |
| + } |
| + |
| + private var teamsLabel: String { DocsOficinaSession.teamsTitle } |
| + |
| + @ViewBuilder private var passkeyNudge: some View { |
| + if model.offerPasskey { OficinaPasskeyNudge(model: model).padding(12) } |
| + } |
| + |
| + /// Whether a document window of any of `identity`'s teams is open (Mac). |
| + private func openDocuments(of identity: String) -> Bool { |
| + #if os(macOS) |
| + return windows.hasOpenDocuments(identity: identity) |
| + #else |
| + return false |
| + #endif |
| + } |
| + |
| + /// Over a mounted workspace: Oficina ID can't mint this team a session |
| + /// right now (§11), or a team switch failed. Try again, or carry on with |
| + /// what is open; nothing is unmounted. |
| + @ViewBuilder private var oficinaBanner: some View { |
| + if case .unavailable = model.step { |
| + HStack(spacing: 12) { |
| + OficinaErrorLine(OficinaIDText.text("unavailable.title") + ". " + OficinaIDText.text("unavailable.body")) |
| + Spacer(minLength: 0) |
| + Button(OficinaIDText.text("unavailable.retry")) { Task { await model.retry() } }.disabled(model.busy) |
| + .accessibilityIdentifier("docs.oficinaid.retry") |
| + } |
| + .padding(.horizontal, 16).padding(.vertical, 8).background(OficinaPalette.negativeSoft) |
| + } else if let error = model.error { |
| + OficinaErrorLine(error).padding(.horizontal, 16).padding(.vertical, 8) |
| + .frame(maxWidth: .infinity, alignment: .leading).background(OficinaPalette.negativeSoft) |
| + } |
| + } |
| + |
| + private func teamPicker(_ state: OficinaSignedIn) -> some View { |
| + DocsTeamPicker(model: model, current: state, leaveCheck: { |
| + await DocsLeaveBlock.check(identity: state.identity.id, openDocuments: openDocuments(of: state.identity.id)) |
| + }, refresh: { await oficina.pickerOpened() }, otherWays: { |
| + pickingTeam = false |
| + storedRoute = DocsSignInRoute.server.rawValue |
| + }, signOut: { |
| + pickingTeam = false |
| + signOutOficinaID(state) |
| + }, done: { pickingTeam = false }) |
| + } |
| + |
| + /// "Sign out of <label>": every team of the identity, on every Oficina app |
| + /// on this device (spec §10), after Docs' own guard: the workspace refuses |
| + /// while anything is unsent, and the Mac while a document window of any |
| + /// of the identity's teams is open. |
| + private func signOutOficinaID(_ state: OficinaSignedIn) { |
| + let identity = state.identity.id |
| + Task { |
| + // Identity-wide: every team's outbox, those a crash left on disk too. |
| + if let block = await DocsLeaveBlock.check(identity: identity, openDocuments: openDocuments(of: identity)) { |
| + leaveRefusal = block; return |
| + } |
| + guard model.identity?.id == identity else { return } |
| + #if os(macOS) |
| + windows.entries.removeAll { DocsOficinaSession.account($0.account, belongsTo: identity) } |
| + windows.transports = windows.transports.filter { !DocsOficinaSession.account($0.key, belongsTo: identity) } |
| + #endif |
| + model.signOut() |
| } |
| - .focusedSceneValue(\.docsWindowAccount, connection.activeAccountID) |
| - .onChange(of: connection.activeAccountID, initial: true) { _, value in windows.activeAccount = value } |
| + } |
| + |
| + // MARK: Other ways (server address) |
| + |
| + @ViewBuilder private func serverWorkspace(_ client: NativeHTTP) -> some View { |
| + #if os(macOS) |
| + if let account = connection.activeAccountID { |
| + DocsWorkspace(client: client, accountID: account, transport: transport(for: account), accounts: connection.showAccounts, signOut: { |
| + guard connection.activeAccountID == account, windows.canSignOut(account) else { return } |
| + windows.entries.removeAll { $0.account == account } |
| + connection.signOut() |
| + }, createDocument: { |
| + guard connection.activeAccountID == account else { return } |
| + let id = windows.reserveDraft(account: account, client: client) |
| + openWindow(id: "document", value: id) |
| + }, canSignOut: windows.canSignOut(account), createRequested: $windows.createRequested, accountsRequested: $windows.accountsRequested, |
| + signOutRequested: $windows.signOutRequested, openDocument: { document, title in |
| + guard connection.activeAccountID == account else { return } |
| + let id = windows.reserve(account: account, document: document, title: title, client: client) |
| + openWindow(id: "document", value: id) |
| + }, updateRecents: { documents in |
| + guard connection.activeAccountID == account else { return } |
| + windows.updateRecents(documents, account: account, client: client) |
| + }) |
| + .id(account) |
| + } |
| + #else |
| + DocsWorkspace(client: client, accountID: connection.activeAccountID, transport: transport(for: connection.activeAccountID), accounts: connection.showAccounts, signOut: connection.signOut) |
| + .id(connection.activeAccountID) |
| #endif |
| } |
| + |
| + #if os(macOS) |
| + private var settingsAccount: DocsSettingsView.Account { |
| + switch route { |
| + case .oficinaID: |
| + guard let state = oficina.mounted else { return .none } |
| + return .oficinaID(identity: state.identity.label, team: state.team.name, teamLabel: state.team.label) |
| + case .server: |
| + guard let client = connection.client else { return .none } |
| + let name = connection.accounts.first { $0.id == connection.activeAccountID }?.name ?? "" |
| + return .server(name: name, host: client.origin.host ?? client.origin.absoluteString) |
| + } |
| + } |
| + #endif |
| } |
diff --git a/native/apple/Sources/DocsApp/DocsApp.swift b/native/apple/Sources/DocsApp/DocsApp.swift| index c529b74..8941857 100644 |
| --- a/native/apple/Sources/DocsApp/DocsApp.swift |
| +++ b/native/apple/Sources/DocsApp/DocsApp.swift |
| @@ -6,21 +6,51 @@ import RastrilloApple |
| import SwiftUI |
| @main struct DocsApp: App { |
| #if os(macOS) && canImport(RastrilloMacUpdates) |
| - @State private var updater = NativeUpdater() |
| + // Quiet, as Calls and Calendar: a scheduled check never opens a window; |
| + // an update downloads in the background and installs on quit. Needs |
| + // "install": "automatic" in mac-updates.json too (rastrillo/native |
| + // docs/mac-updates.md). |
| + @State private var updater = NativeUpdater(policy: .quiet) |
| #endif |
| #if os(macOS) |
| @State private var windows = DocsWindows() |
| @NSApplicationDelegateAdaptor(DocsApplicationDelegate.self) private var appDelegate |
| #endif |
| + /// One Oficina ID model for the whole app (slice A: one identity), read |
| + /// from the keychain once at launch, whichever window asks first. |
| + @StateObject private var oficina = DocsOficinaSession.live() |
| /// Every bundled face is registered here, synchronously, before the |
| /// first window exists, so no text view ever lays out with a face |
| /// missing (polish-audit/fonts/NO-FOUT.md §7). |
| - init() { DocsFonts.register() } |
| + init() { |
| + #if os(macOS) |
| + // The launch gate: run the signed executable with this argument. |
| + if CommandLine.arguments.contains(DocsOficinaLaunchCheck.argument) { |
| + let result = DocsOficinaLaunchCheck.run() |
| + result.lines.forEach { print($0) } |
| + exit(result.passed ? 0 : 1) |
| + } |
| + #endif |
| + DocsFonts.register() |
| + } |
| var body: some Scene { |
| #if os(macOS) |
| - Window(docsMacString("Home"), id: "home") { DocsAccountWindow(windows: windows) } |
| + Window(docsMacString("Home"), id: "home") { |
| + DocsAccountWindow(oficina: oficina, windows: windows) |
| + #if canImport(RastrilloMacUpdates) |
| + // The quiet updater's one line, only while an update waits: where an |
| + // update that needs the person (automatic downloads off) shows up. |
| + .safeAreaInset(edge: .bottom) { |
| + if updater.canInstallPendingUpdate { NativeUpdateNotice(updater: updater).padding(.bottom, 12) } |
| + } |
| + #endif |
| + } |
| .defaultSize(width: 1000, height: 760) |
| .commands { |
| + // First: About, Hide, Quit say "Docs", not the Finder name, and the |
| + // groups after it (Check for Updates, the Colophon) survive |
| + // (rastrillo/native docs/mac-updates.md). |
| + PlainAppNameCommands() |
| DocsWindowCommands(windows: windows) |
| DocsEditorCommands() |
| #if canImport(RastrilloMacUpdates) |
| @@ -36,8 +66,35 @@ import SwiftUI |
| // the typefaces' licences among it. |
| Window(DocsColophonView.title, id: "colophon") { DocsColophonView() } |
| .defaultSize(width: 680, height: 760) |
| + Settings { DocsSettingsWindow(windows: windows) } |
| #else |
| - WindowGroup { DocsAccountWindow() } |
| + WindowGroup { DocsAccountWindow(oficina: oficina) } |
| #endif |
| } |
| } |
| + |
| +#if os(macOS) |
| +/// Docs ▸ Settings… (⌘,): the home window's account and the version. Its |
| +/// buttons ask the home window, which holds the guards against stranding |
| +/// unsent changes. |
| +struct DocsSettingsWindow: View { |
| + let windows: DocsWindows |
| + @Environment(\.openWindow) private var openWindow |
| + @State private var block: DocsLeaveBlock? |
| + var body: some View { |
| + DocsSettingsView(account: windows.settingsAccount, block: block, manage: { |
| + windows.accountsRequested = true; openWindow(id: "home") |
| + }, signOut: { |
| + windows.signOutRequested = true; openWindow(id: "home") |
| + }, signIn: { openWindow(id: "home") }) |
| + // The same guard as the home window's, kept current while Settings is |
| + // open: open document windows change, outboxes drain. |
| + .task(id: "\(windows.settingsIdentity ?? "")|\(windows.activeAccount ?? "")|\(windows.entries.filter(\.isOpen).count)") { |
| + while !Task.isCancelled { |
| + block = await windows.leaveBlock() |
| + try? await Task.sleep(for: .seconds(2)) |
| + } |
| + } |
| + } |
| +} |
| +#endif |
diff --git a/native/apple/Sources/DocsApp/DocsDocumentWindow.swift b/native/apple/Sources/DocsApp/DocsDocumentWindow.swift| index 941e00d..b5ce9e2 100644 |
| --- a/native/apple/Sources/DocsApp/DocsDocumentWindow.swift |
| +++ b/native/apple/Sources/DocsApp/DocsDocumentWindow.swift |
| @@ -8,7 +8,7 @@ struct DocsDocumentWindow: View { |
| @Environment(\.openWindow) private var openWindow |
| var body: some View { |
| if let entry = windows.entries.first(where: { $0.id == id }) { |
| - DocsWorkspace(client: entry.client, accountID: entry.account, signOut: {}, documentID: entry.document, newDocument: entry.isDraft, documentChanged: { document, title in windows.attach(entry.id, document: document, title: title) }) |
| + DocsWorkspace(client: entry.client, accountID: entry.account, transport: windows.transports[entry.account], signOut: {}, documentID: entry.document, newDocument: entry.isDraft, documentChanged: { document, title in windows.attach(entry.id, document: document, title: title) }) |
| .id(entry.id) |
| .focusedSceneValue(\.docsWindowAccount, entry.account) |
| .onAppear { windows.setOpen(entry.id, true) } |
diff --git a/native/apple/Sources/DocsApp/DocsWindows.swift b/native/apple/Sources/DocsApp/DocsWindows.swift| index 41a682d..4a004f8 100644 |
| --- a/native/apple/Sources/DocsApp/DocsWindows.swift |
| +++ b/native/apple/Sources/DocsApp/DocsWindows.swift |
| @@ -20,6 +20,17 @@ import SwiftUI |
| var activeAccount: String? |
| var createRequested = false |
| var accountsRequested = false |
| + /// Settings' "Sign out", carried out by the home window's guard. |
| + var signOutRequested = false |
| + /// What Settings shows: the home window's account. |
| + var settingsAccount: DocsSettingsView.Account = .none |
| + /// The home window's Oficina ID, for Settings' identity-wide guard. |
| + var settingsIdentity: String? |
| + /// Oficina ID accounts' transports, so a document window reads the |
| + /// latest session of its team (re-minted every 24 hours and on a 401) |
| + /// rather than the one it opened with. Server accounts have none: their |
| + /// windows keep the client they were opened with, as before. |
| + var transports: [String: @MainActor () -> NativeTransport?] = [:] |
| func reserve(account: String, document: String, title: String, client: NativeHTTP) -> UUID { |
| if let index = entries.firstIndex(where: { $0.account == account && $0.client.origin == client.origin && $0.document == document }) { |
| var entry = entries.remove(at: index) |
| @@ -58,6 +69,19 @@ import SwiftUI |
| } |
| } |
| func canSignOut(_ account: String?) -> Bool { !entries.contains { $0.account == account && $0.isOpen } } |
| + /// Whether a document window of any of `identity`'s teams is open: |
| + /// signing out of an Oficina ID ends all of its teams at once. |
| + func hasOpenDocuments(identity: String) -> Bool { |
| + entries.contains { DocsOficinaSession.account($0.account, belongsTo: identity) && $0.isOpen } |
| + } |
| + /// Settings' guard, matching the home window's: identity-wide for an |
| + /// Oficina ID, the account's own windows for a server account. |
| + func leaveBlock() async -> DocsLeaveBlock? { |
| + if let identity = settingsIdentity { |
| + return await DocsLeaveBlock.check(identity: identity, openDocuments: hasOpenDocuments(identity: identity)) |
| + } |
| + return canSignOut(activeAccount) ? nil : .openDocuments |
| + } |
| } |
| extension FocusedValues { @Entry var docsWindowAccount: String? } |
| #endif |
diff --git a/native/apple/Sources/DocsKit/DocsAttachments.swift b/native/apple/Sources/DocsKit/DocsAttachments.swift| index 4dd1e0c..bebf1c1 100644 |
| --- a/native/apple/Sources/DocsKit/DocsAttachments.swift |
| +++ b/native/apple/Sources/DocsKit/DocsAttachments.swift |
| @@ -42,14 +42,14 @@ private final class ImageRedirectGuard: NSObject, URLSessionTaskDelegate, @unche |
| for node in projection.children { visit(node) } |
| return found.sorted() |
| } |
| - func images(forDocumentPath path: String, client: NativeHTTP) -> [String: DocsPlatformImage] { |
| + func images(forDocumentPath path: String, client: NativeTransport) -> [String: DocsPlatformImage] { |
| documentURL == URL(string: path, relativeTo: client.origin)?.absoluteURL ? images : [:] |
| } |
| static func resolvedURL(source: String, documentPath: String, origin: URL) -> URL? { |
| guard let document = URL(string: documentPath, relativeTo: origin)?.absoluteURL else { return nil } |
| return URL(string: source, relativeTo: document)?.absoluteURL |
| } |
| - func load(sources: [String], client: NativeHTTP, documentPath: String = "/") async { |
| + func load(sources: [String], client: NativeTransport, documentPath: String = "/") async { |
| let current = UUID(); generation = current |
| let document = URL(string: documentPath, relativeTo: client.origin)?.absoluteURL |
| if documentURL != document { images.removeAll(); documentURL = document } |
diff --git a/native/apple/Sources/DocsKit/DocsEditorContext.swift b/native/apple/Sources/DocsKit/DocsEditorContext.swift| index 9b9ac73..f604c9f 100644 |
| --- a/native/apple/Sources/DocsKit/DocsEditorContext.swift |
| +++ b/native/apple/Sources/DocsKit/DocsEditorContext.swift |
| @@ -6,7 +6,7 @@ import SwiftUI |
| struct DocsEditorContext { |
| let model: DocsModel |
| let rename: () -> Void |
| - let client: NativeHTTP |
| + let client: NativeTransport |
| let zoom: Binding<Double> |
| let paged: Binding<Bool> |
| let inspecting: Binding<Bool> |
diff --git a/native/apple/Sources/DocsKit/DocsJumpControls.swift b/native/apple/Sources/DocsKit/DocsJumpControls.swift| index c49dc36..561d2c9 100644 |
| --- a/native/apple/Sources/DocsKit/DocsJumpControls.swift |
| +++ b/native/apple/Sources/DocsKit/DocsJumpControls.swift |
| @@ -26,7 +26,7 @@ private struct DocumentSearchResult: Decodable, Identifiable { |
| @MainActor struct DocsJumpSheet: View { |
| let model: DocsModel |
| - let client: NativeHTTP |
| + let client: NativeTransport |
| @Environment(\.dismiss) private var dismiss |
| @FocusState private var searchFocused: Bool |
| @State private var query = "" |
diff --git a/native/apple/Sources/DocsKit/DocsOfflineAccount.swift b/native/apple/Sources/DocsKit/DocsOfflineAccount.swift| index b8faef2..f796354 100644 |
| --- a/native/apple/Sources/DocsKit/DocsOfflineAccount.swift |
| +++ b/native/apple/Sources/DocsKit/DocsOfflineAccount.swift |
| @@ -11,7 +11,7 @@ struct DocsOfflineMetadata: Codable { |
| /// All windows for an account share the same outbox and send reservation. |
| @MainActor @Observable final class DocsOfflineAccount { |
| - private static var accounts: [String: DocsOfflineAccount] = [:] |
| + static var accounts: [String: DocsOfflineAccount] = [:] |
| let store: BlobStore |
| let outbox: Outbox |
| let connectivity: NativeConnectivity |
| @@ -20,13 +20,55 @@ struct DocsOfflineMetadata: Codable { |
| private(set) var drainer: OutboxDrainer! |
| static func account(_ id: String, origin: URL, fallback: NativeTransport, transport: (@MainActor () -> NativeTransport?)?) -> DocsOfflineAccount { |
| if let existing = accounts[id] { if let transport { existing.supplier = transport; existing.drainer.sessionRestored() }; return existing } |
| - let root = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] |
| - .appendingPathComponent(Bundle.main.bundleIdentifier ?? "works.oficina.docs") |
| - .appendingPathComponent("accounts").appendingPathComponent(id) |
| - let store = NativeSealedStore(root: root, accountID: id, keys: KeychainKeyProvider(accountID: id, origin: origin)) |
| + let root = accountsRoot.appendingPathComponent(id) |
| + let store = NativeSealedStore(root: root, accountID: id, keys: keys(accountID: id, origin: origin)) |
| let account = DocsOfflineAccount(store: store, accountID: id, connectivity: .shared, transport: transport ?? { fallback }) |
| accounts[id] = account; return account |
| } |
| + static var accountsRoot: URL { |
| + FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] |
| + .appendingPathComponent(Bundle.main.bundleIdentifier ?? "works.oficina.docs") |
| + .appendingPathComponent("accounts") |
| + } |
| + |
| + /// What every Oficina ID team's store key is filed under, whatever its |
| + /// origin. A team's origin can change (a label moved, a rename, a team |
| + /// self-hosting by DNS) while its account, keyed by (identity, team), |
| + /// does not; keyed by origin, the store would find no key and delete |
| + /// itself, unsent outbox and all. Server accounts keep their origin: an |
| + /// account there is a host. |
| + nonisolated static let oficinaKeyOrigin = URL(string: "https://oficina-id.invalid")! |
| + |
| + nonisolated static func keys(accountID: String, origin: URL) -> KeychainKeyProvider { |
| + KeychainKeyProvider(accountID: accountID, origin: DocsOficinaSession.isOficinaAccount(accountID) ? oficinaKeyOrigin : origin) |
| + } |
| + |
| + /// Whether any of `identity`'s teams has changes on this device not yet |
| + /// sent: the outboxes open in this run, and any left on disk by an |
| + /// earlier one (a crash, a quit with a lane held) that nothing has |
| + /// opened since. Signing out must not strand them. |
| + static func hasUnsent(identity: String, root: URL? = nil, |
| + keys: (String) -> KeyProvider = { keys(accountID: $0, origin: oficinaKeyOrigin) }) async -> Bool { |
| + for (id, account) in accounts where DocsOficinaSession.account(id, belongsTo: identity) { |
| + if await !account.outbox.summary.isEmpty { return true } |
| + } |
| + let root = root ?? accountsRoot |
| + let names = (try? FileManager.default.contentsOfDirectory(atPath: root.path)) ?? [] |
| + for name in names.sorted() where DocsOficinaSession.account(name, belongsTo: identity) && accounts[name] == nil { |
| + let outbox = Outbox(store: NativeSealedStore(root: root.appendingPathComponent(name), accountID: name, keys: keys(name)), account: name) |
| + // An outbox that can't be read (its key unavailable, the device |
| + // locked) is skipped on purpose: it is not deleted, its store stays |
| + // on disk, and it resumes sending when the same identity signs in |
| + // again. Refusing sign-out over it would lock the person in. |
| + guard (try? await outbox.load()) != nil else { continue } |
| + if await !outbox.summary.isEmpty { return true } |
| + } |
| + return false |
| + } |
| + |
| + /// The account's session was replaced (Oficina ID re-minted it): an |
| + /// outbox that stopped on the old one's 401 sends again. |
| + static func sessionRestored(_ id: String) { accounts[id]?.drainer.sessionRestored() } |
| init(store: BlobStore, accountID: String, connectivity: NativeConnectivity, transport: @escaping @MainActor () -> NativeTransport?) { |
| self.store = store; outbox = Outbox(store: store, account: accountID) |
| replicaCache = DocsReplicaCache(store: store) |
diff --git a/native/apple/Sources/DocsKit/DocsOficinaID.swift b/native/apple/Sources/DocsKit/DocsOficinaID.swift| new file mode 100644 |
| index 0000000..58fff20 |
| --- /dev/null |
| +++ b/native/apple/Sources/DocsKit/DocsOficinaID.swift |
| @@ -0,0 +1,342 @@ |
| +import Combine |
| +import Foundation |
| +import RastrilloApple |
| + |
| +/// How Docs signs in, as the person last chose it. Oficina ID is the primary |
| +/// way (spec 2026-11-14-oficina-id-native §9, slice A); "Other ways to sign |
| +/// in…" keeps the server address and browser approval for self-hosted |
| +/// servers and local accounts (§11). |
| +public enum DocsSignInRoute: String, Sendable { |
| + case oficinaID = "oficina-id" |
| + case server |
| + |
| + /// The `UserDefaults` key the choice is kept under. |
| + public static let key = "docs.signin.route" |
| + |
| + /// The route to show. Nothing chosen yet means Oficina ID, except for |
| + /// someone already signed in the old way: their per-app sessions keep |
| + /// working until an Oficina ID replaces them (spec Appendix C). An |
| + /// Oficina ID sign-in chooses `.oficinaID` for good. |
| + public static func resolve(stored: String, hasServerAccounts: Bool) -> DocsSignInRoute { |
| + if let chosen = DocsSignInRoute(rawValue: stored) { return chosen } |
| + return hasServerAccounts ? .server : .oficinaID |
| + } |
| +} |
| + |
| +/// Docs' half of Oficina ID: the kit's model, and the team sessions it mints |
| +/// turned into the transports Docs' workspaces use. |
| +/// |
| +/// A workspace is keyed by `(identity, team)`, never by a session: a session |
| +/// is re-minted after 24 hours and on a 401, and the workspace, its offline |
| +/// store and its outbox must carry on through that. So the transport is a |
| +/// supplier that reads the latest session for its account on every request. |
| +@MainActor public final class DocsOficinaSession: ObservableObject { |
| + public let model: OficinaIDModel |
| + private var sessions: [String: (session: NativeSession, client: NativeHTTP)] = [:] |
| + private var lastRejection: [String: Date] = [:] |
| + private var lastRefusal: Date? |
| + private var renewing = false |
| + private var started = false |
| + private var watch: AnyCancellable? |
| + private let now: () -> Date |
| + |
| + nonisolated public static let configuration = OficinaIDConfiguration(app: "docs", appName: "Docs") |
| + |
| + /// The team the workspace shows. It is the signed-in team, and it stays |
| + /// while Oficina ID cannot mint that team a new session (spec §11): a |
| + /// 401 with Home unreachable must not unmount an open editor. Docs then |
| + /// shows the "Can't reach Oficina ID" line over the workspace instead. |
| + /// nil once the identity signs out, or the model moves to another team's |
| + /// question (not on it, choose, …). |
| + @Published public private(set) var mounted: OficinaSignedIn? |
| + |
| + /// Counts sign-ins a person made here: an identity chosen, a code or |
| + /// passkey, a team picked, a retry. Restoring the last team at launch is |
| + /// not one, so a restored identity never changes Docs' sign-in route. |
| + @Published public private(set) var signIns = 0 |
| + |
| + /// "Teams": the workspace's button for Docs' team picker. |
| + public static var teamsTitle: String { |
| + NSLocalizedString("native.oficinaid.teams", bundle: DocsResources.bundle, comment: "") |
| + } |
| + |
| + /// The App Group that holds the identity order and last-used team: team |
| + /// prefixed on the Mac, where it needs no profile, and the registered |
| + /// `group.works.oficina` on iOS (rastrillo/native APPLE.md). |
| + nonisolated public static var appGroup: String { |
| + #if os(macOS) |
| + "9U4A84C4WK.works.oficina" |
| + #else |
| + "group.works.oficina" |
| + #endif |
| + } |
| + |
| + /// The real wiring: the shared keychain group, Docs' own group, the App |
| + /// Group, Home over HTTPS and the platform's passkey sheet. |
| + public static func live() -> DocsOficinaSession { |
| + DocsOficinaSession(model: .live(configuration: configuration, appGroup: appGroup)) |
| + } |
| + |
| + public init(model: OficinaIDModel, now: @escaping () -> Date = Date.init) { |
| + self.model = model |
| + self.now = now |
| + watch = model.$step.sink { [weak self] step in self?.stepChanged(step) } |
| + } |
| + |
| + /// Reads the store once per launch, however many windows ask, then |
| + /// refreshes the team list (spec §9: at launch). |
| + public func start() async { |
| + guard !started else { return } |
| + started = true |
| + await model.start() |
| + await model.refreshTeams() |
| + } |
| + |
| + /// The team picker opened: refresh if the list is five minutes old. |
| + public func pickerOpened() async { await model.refreshTeams() } |
| + |
| + /// An instance answered 403: the person may have left the team, or been |
| + /// given another, so the list is fetched again, at most once a minute. |
| + func refused() async { |
| + if let last = lastRefusal, now().timeIntervalSince(last) < 60 { return } |
| + lastRefusal = now() |
| + await model.refreshTeams(maxAge: 0) |
| + } |
| + |
| + /// The team session in use, if the model has one. |
| + public var signedIn: OficinaSignedIn? { |
| + if case .signedIn(let state) = model.step { return state } |
| + return nil |
| + } |
| + |
| + /// The account Docs files an Oficina ID team under: its offline store, |
| + /// outbox and windows. Stable for the life of the identity on this |
| + /// device, whatever session the team holds. |
| + public static func accountID(_ state: OficinaSignedIn) -> String { |
| + accountID(identity: state.identity.id, team: state.team.sqid) |
| + } |
| + |
| + nonisolated public static func accountID(identity: String, team: String) -> String { |
| + prefix + component(identity) + "." + component(team) |
| + } |
| + |
| + nonisolated static let prefix = "oficina-id." |
| + |
| + /// An account ID names a directory and a keychain item, so each part is |
| + /// used as it is only when it is base64url-safe (as Home's identity IDs |
| + /// and sqids are). Anything else, a "." or "/" above all, is encoded, |
| + /// marked by a "~" no plain part can contain. |
| + nonisolated static func component(_ text: String) -> String { |
| + let plain = !text.isEmpty && text.unicodeScalars.allSatisfy { |
| + ("a"..."z").contains($0) || ("A"..."Z").contains($0) || ("0"..."9").contains($0) || $0 == "-" || $0 == "_" |
| + } |
| + return plain ? text : "~" + Base64URL.encode(Data(text.utf8)) |
| + } |
| + |
| + /// Whether `account` is one of `identity`'s teams: signing out of an |
| + /// identity ends all of them. |
| + nonisolated public static func account(_ account: String, belongsTo identity: String) -> Bool { |
| + account.hasPrefix(prefix + component(identity) + ".") |
| + } |
| + |
| + /// Whether `account` is an Oficina ID team's, as against a server |
| + /// account's (a UUID). |
| + nonisolated public static func isOficinaAccount(_ account: String) -> Bool { account.hasPrefix(prefix) } |
| + |
| + /// The client for `account`'s latest session, or nil once the identity |
| + /// has signed out. One client per session, so requests share a |
| + /// URLSession instead of making one each. |
| + public func client(for account: String) -> NativeHTTP? { sessions[account]?.client } |
| + |
| + /// What a workspace for `account` asks on every request. A 401 from it |
| + /// re-mints the session silently (spec §7); a request after sign-out |
| + /// gets no transport, and fails as `.unauthorized`. |
| + public func transport(for account: String) -> @MainActor () -> NativeTransport? { |
| + { [weak self] in |
| + guard let self, let client = self.sessions[account]?.client else { return nil } |
| + return DocsSessionWatch(inner: client, rejected: { [weak self] in |
| + Task { @MainActor in await self?.rejected(account) } |
| + }, refused: { [weak self] in |
| + Task { @MainActor in await self?.refused() } |
| + }) |
| + } |
| + } |
| + |
| + /// Re-mints a session older than 24 hours; call when a scene comes back. |
| + public func renewIfNeeded() async { |
| + guard !renewing else { return } |
| + renewing = true |
| + defer { renewing = false } |
| + await model.renewIfNeeded() |
| + } |
| + |
| + /// The instance refused the session. Only the team in use can be |
| + /// re-minted (another team's would mean switching to it), and at most |
| + /// once a minute per account, so an instance that keeps refusing cannot |
| + /// set off a loop of assertions. |
| + func rejected(_ account: String) async { |
| + guard let state = signedIn, Self.accountID(state) == account, !renewing else { return } |
| + if let last = lastRejection[account], now().timeIntervalSince(last) < 60 { return } |
| + lastRejection[account] = now() |
| + renewing = true |
| + defer { renewing = false } |
| + await model.sessionRejected() |
| + } |
| + |
| + /// Called as the step is about to change (`@Published` publishes before |
| + /// the property is set), so `model.step` is still the previous one. |
| + private func stepChanged(_ step: OficinaIDModel.Step) { |
| + let previous = model.step |
| + switch step { |
| + case .signedIn(let state): |
| + mounted = state |
| + if case .signedIn = previous {} else if previous != .loading { signIns += 1 } |
| + case .unavailable(let team) where mounted?.team.sqid == team.sqid && model.identity?.id == mounted?.identity.id: |
| + break |
| + default: |
| + mounted = nil |
| + } |
| + if case .signedIn(let state) = step { |
| + let account = Self.accountID(state) |
| + let previous = sessions[account]?.session |
| + if previous?.value != state.session.value { |
| + sessions[account] = (state.session, state.client()) |
| + // A workspace whose outbox stopped on the old session's 401 |
| + // sends again with the new one. |
| + if previous != nil { DocsOfflineAccount.sessionRestored(account) } |
| + } |
| + // Sessions of the identity's other teams stay, so their document |
| + // windows keep working; another identity's never do. |
| + sessions = sessions.filter { Self.account($0.key, belongsTo: state.identity.id) } |
| + } else if model.identity == nil { |
| + sessions.removeAll() |
| + lastRejection.removeAll() |
| + } |
| + } |
| +} |
| + |
| +/// Why Docs won't sign out, switch team or replace the Oficina ID just now, |
| +/// in a line the person sees instead of a button that silently does nothing. |
| +public enum DocsLeaveBlock: Equatable, Sendable { |
| + /// Changes on this device are still to be sent, in this window or in any |
| + /// team of the identity (an outbox left by a crash included). |
| + case sending |
| + /// A document window of one of the identity's teams is open (Mac). |
| + case openDocuments |
| + |
| + public var message: String { |
| + NSLocalizedString(self == .sending ? "native.leave.sending" : "native.leave.openDocuments", |
| + bundle: DocsResources.bundle, comment: "") |
| + } |
| + |
| + /// The identity-wide guard: open document windows first, then anything |
| + /// this window or any of the identity's teams has not sent. |
| + @MainActor public static func check(identity: String, openDocuments: Bool, unsentHere: Bool = false) async -> DocsLeaveBlock? { |
| + if openDocuments { return .openDocuments } |
| + if unsentHere { return .sending } |
| + return await DocsOfflineAccount.hasUnsent(identity: identity) ? .sending : nil |
| + } |
| +} |
| + |
| +/// A transport that tells Docs when the instance refuses its session: a 401, |
| +/// or the 303 to sign-in that `NativeClientError` also reads as an ended |
| +/// session; and when it refuses a request, a 403. Everything else passes |
| +/// through untouched. |
| +struct DocsSessionWatch: NativeTransport { |
| + let inner: NativeTransport |
| + let rejected: @Sendable () -> Void |
| + /// A 403: refused this request, not the session. Docs refreshes the team |
| + /// list on it (spec §9). |
| + var refused: @Sendable () -> Void = {} |
| + |
| + var origin: URL { inner.origin } |
| + |
| + func responseDetails(_ path: String, method: String, body: Data?, contentType: String, maxBytes: Int) async throws -> NativeResponse { |
| + let reply = try await inner.responseDetails(path, method: method, body: body, contentType: contentType, maxBytes: maxBytes) |
| + if reply.status == 401 || reply.status == 303 { rejected() } |
| + if reply.status == 403 { refused() } |
| + return reply |
| + } |
| + |
| + func stream(_ path: String, onOpen: @Sendable () async throws -> Void, onLine: @Sendable (String) async throws -> Void) async throws { |
| + do { try await inner.stream(path, onOpen: onOpen, onLine: onLine) } |
| + catch NativeClientError.unauthorized { rejected(); throw NativeClientError.unauthorized } |
| + } |
| + |
| + func download(_ path: String, to destination: URL) async throws { |
| + do { try await inner.download(path, to: destination) } |
| + catch NativeClientError.unauthorized { rejected(); throw NativeClientError.unauthorized } |
| + } |
| +} |
| + |
| +#if os(macOS) |
| +import Security |
| + |
| +/// The launch gate (spec §13, "Mac launch"): the final signed artifact must |
| +/// launch and read the shared group before any Sparkle publish, because a |
| +/// build killed at launch cannot update itself. Run the app's executable |
| +/// with `--oficina-id-launch-check`: macOS checks the embedded profile |
| +/// against the entitlements as it starts the process. This then checks the |
| +/// signed entitlements (keychain groups in order, the App Group, the |
| +/// associated domain) and reads, never writes, both keychain groups. It |
| +/// prints what it found and exits 0 only if all of it works. It prints |
| +/// counts, never an identity or a session. |
| +public enum DocsOficinaLaunchCheck { |
| + public static let argument = "--oficina-id-launch-check" |
| + |
| + public static func run() -> (passed: Bool, lines: [String]) { |
| + var lines: [String] = [], passed = true |
| + func check(_ name: String, _ body: () throws -> String) { |
| + do { lines.append("ok \(name): \(try body())") } |
| + catch { passed = false; lines.append("FAIL \(name): \(error)") } |
| + } |
| + let own = OficinaKeychainStore.appGroup(for: DocsOficinaSession.configuration.app) |
| + check("keychain-access-groups") { |
| + let groups = entitlement("keychain-access-groups") |
| + // A query that names no group lands in the first: it must be Docs' own. |
| + guard groups.first == own, groups.contains(OficinaKeychainStore.sharedGroup) else { |
| + throw LaunchCheckError("expected [\(own), \(OficinaKeychainStore.sharedGroup)], got \(groups)") |
| + } |
| + return groups.joined(separator: ", ") |
| + } |
| + check("shared group \(OficinaKeychainStore.sharedGroup)") { |
| + // The store Docs' onboarding reads at launch, records decoded. |
| + let store = OficinaIDStore(shared: OficinaKeychainStore(accessGroup: OficinaKeychainStore.sharedGroup), |
| + appPrivate: OficinaKeychainStore(accessGroup: own), |
| + group: UserDefaults(suiteName: DocsOficinaSession.appGroup) ?? .standard) |
| + return "readable, \(try store.identities().count) identities" |
| + + " (\(store.unreadableIdentities().count) only a newer app can read)" |
| + } |
| + check("Docs' group \(own)") { |
| + "readable, \(try OficinaKeychainStore(accessGroup: own).accounts(service: "works.oficina.id.session").count) sessions" |
| + } |
| + // On a Mac, containerURL answers for any app group, granted or not, |
| + // so the entitlement itself is what proves the grant. |
| + check("App Group \(DocsOficinaSession.appGroup)") { |
| + let groups = entitlement("com.apple.security.application-groups") |
| + guard groups.contains(DocsOficinaSession.appGroup) else { |
| + throw LaunchCheckError("not granted: com.apple.security.application-groups is \(groups)") |
| + } |
| + guard UserDefaults(suiteName: DocsOficinaSession.appGroup) != nil else { throw LaunchCheckError("no defaults suite") } |
| + return "granted" |
| + } |
| + check("associated domains") { |
| + let domains = entitlement("com.apple.developer.associated-domains") |
| + guard domains.contains("webcredentials:id.oficina.works") else { throw LaunchCheckError("got \(domains)") } |
| + return domains.joined(separator: ", ") |
| + } |
| + return (passed, lines) |
| + } |
| + |
| + /// A string-array entitlement of this process, as signed. |
| + static func entitlement(_ key: String) -> [String] { |
| + guard let task = SecTaskCreateFromSelf(nil) else { return [] } |
| + return SecTaskCopyValueForEntitlement(task, key as CFString, nil) as? [String] ?? [] |
| + } |
| + |
| + struct LaunchCheckError: Error, CustomStringConvertible { |
| + let description: String |
| + init(_ description: String) { self.description = description } |
| + } |
| +} |
| +#endif |
diff --git a/native/apple/Sources/DocsKit/DocsOficinaViews.swift b/native/apple/Sources/DocsKit/DocsOficinaViews.swift| new file mode 100644 |
| index 0000000..65daa9d |
| --- /dev/null |
| +++ b/native/apple/Sources/DocsKit/DocsOficinaViews.swift |
| @@ -0,0 +1,227 @@ |
| +import RastrilloApple |
| +import SwiftUI |
| + |
| +/// Docs' team picker for an Oficina ID (spec §9): the kit's team list for |
| +/// the identity, from its team cache, filtered to teams that have Docs. The |
| +/// several-identities account menu is slice A2; this is one identity's teams. |
| +@MainActor public struct DocsTeamPicker: View { |
| + @ObservedObject private var model: OficinaIDModel |
| + private let current: OficinaSignedIn |
| + private let leaveCheck: @MainActor () async -> DocsLeaveBlock? |
| + private let refresh: @MainActor () async -> Void |
| + @State private var block: DocsLeaveBlock? |
| + @State private var checked = false |
| + private let otherWays: () -> Void |
| + private let signOut: () -> Void |
| + private let done: () -> Void |
| + |
| + /// `leaveCheck` says why switching team or signing out would strand |
| + /// something (open document windows, changes not yet sent), and the |
| + /// picker shows that line by the controls it disables. `refresh` fetches |
| + /// the team list again if it is five minutes old (spec §9). |
| + public init(model: OficinaIDModel, current: OficinaSignedIn, |
| + leaveCheck: @escaping @MainActor () async -> DocsLeaveBlock? = { nil }, |
| + refresh: @escaping @MainActor () async -> Void = {}, |
| + otherWays: @escaping () -> Void, signOut: @escaping () -> Void, done: @escaping () -> Void) { |
| + self.model = model; self.current = current; self.leaveCheck = leaveCheck; self.refresh = refresh |
| + self.otherWays = otherWays; self.signOut = signOut; self.done = done |
| + } |
| + |
| + private var canLeave: Bool { checked && block == nil } |
| + |
| + /// The cached teams that have Docs, the current one always among them. |
| + public static func teams(_ cached: [OficinaTeam]?, current: OficinaTeam) -> [OficinaTeam] { |
| + var teams = (cached ?? []).filter { $0.origin(for: DocsOficinaSession.configuration.app) != nil } |
| + if !teams.contains(where: { $0.sqid == current.sqid }) { teams.append(current) } |
| + return teams.sorted { ($0.name.localizedLowercase, $0.sqid) < ($1.name.localizedLowercase, $1.sqid) } |
| + } |
| + |
| + private var teams: [OficinaTeam] { Self.teams(model.store.teams(current.identity.id)?.teams, current: current.team) } |
| + |
| + public var body: some View { |
| + NavigationStack { |
| + List { |
| + Section { |
| + OficinaIdentityRow(identity: current.identity, accent: .docs) |
| + } header: { Text(verbatim: "Oficina ID") } |
| + Section { |
| + ForEach(teams) { team in |
| + Button { choose(team) } label: { |
| + OficinaTeamRow(team: team).overlay(alignment: .trailing) { |
| + if team.sqid == current.team.sqid { |
| + Image(systemName: "checkmark").font(.headline).foregroundStyle(OficinaPalette.accent(.docs)) |
| + .padding(.trailing, 14).accessibilityHidden(true) |
| + } |
| + } |
| + } |
| + .buttonStyle(.plain) |
| + .disabled(team.sqid != current.team.sqid && (!canLeave || model.busy)) |
| + .accessibilityAddTraits(team.sqid == current.team.sqid ? .isSelected : []) |
| + .accessibilityIdentifier("docs.team-\(team.label)") |
| + } |
| + } header: { Text("native.oficinaid.teams", bundle: DocsResources.bundle) } footer: { |
| + if let block { DocsBlockLine(block) } |
| + else if let error = model.error { OficinaErrorLine(error) } |
| + } |
| + Section { |
| + Button(OficinaIDText.text("otherWays")) { otherWays() } |
| + .buttonStyle(.borderless) |
| + .accessibilityIdentifier("docs.otherWays") |
| + Button(role: .destructive) { signOut() } label: { |
| + Text(verbatim: OficinaIDText.text("signOut", current.identity.label)) |
| + } |
| + .buttonStyle(.borderless) |
| + // Its own colour would hide that it is disabled. |
| + .foregroundStyle(canLeave ? OficinaPalette.negative : OficinaPalette.textMuted) |
| + .disabled(!canLeave) |
| + .accessibilityIdentifier("docs.oficinaid.signOut") |
| + } |
| + } |
| + .navigationTitle(Text("native.oficinaid.teams", bundle: DocsResources.bundle)) |
| + .task { |
| + block = await leaveCheck(); checked = true |
| + await refresh() |
| + } |
| + #if os(iOS) |
| + .navigationBarTitleDisplayMode(.inline) |
| + #endif |
| + .toolbar { |
| + ToolbarItem(placement: .confirmationAction) { |
| + Button { done() } label: { Text("native.done", bundle: DocsResources.bundle) } |
| + } |
| + } |
| + } |
| + .tint(OficinaPalette.accent(.docs)) |
| + #if os(macOS) |
| + .frame(minWidth: 420, idealWidth: 460, minHeight: 440, idealHeight: 520) |
| + #endif |
| + } |
| + |
| + private func choose(_ team: OficinaTeam) { |
| + done() |
| + guard team.sqid != current.team.sqid else { return } |
| + Task { await model.choose(team) } |
| + } |
| +} |
| + |
| +/// The one line that says why a control is disabled. |
| +public struct DocsBlockLine: View { |
| + private let block: DocsLeaveBlock |
| + public init(_ block: DocsLeaveBlock) { self.block = block } |
| + public var body: some View { |
| + Label(block.message, systemImage: "info.circle").font(.callout).foregroundStyle(OficinaPalette.textMuted) |
| + .fixedSize(horizontal: false, vertical: true) |
| + .accessibilityIdentifier("docs.leaveBlock") |
| + } |
| +} |
| + |
| +/// "Other ways to sign in…": the server address and browser approval that |
| +/// stay for self-hosted servers and local accounts (spec §11), with the way |
| +/// back to Oficina ID beneath. With no account kept yet it is the sign-in |
| +/// itself; with some, their list and "Add account". |
| +@MainActor public struct DocsOtherWaysView: View { |
| + @ObservedObject private var connection: NativeConnection |
| + private let oficinaID: () -> Void |
| + |
| + public init(connection: NativeConnection, oficinaID: @escaping () -> Void) { |
| + self.connection = connection; self.oficinaID = oficinaID |
| + } |
| + |
| + public var body: some View { |
| + Group { |
| + if connection.accounts.isEmpty { |
| + NavigationStack { NativeSignInView("Docs", systemImage: "doc.text", connection: connection) } |
| + } else { |
| + NativeAccountsView("Docs", systemImage: "doc.text", connection: connection) |
| + } |
| + } |
| + .safeAreaInset(edge: .bottom, spacing: 0) { |
| + Button { connection.cancel(); oficinaID() } label: { |
| + Label { Text("native.oficinaid.signin", bundle: DocsResources.bundle) } icon: { Image(systemName: "person.crop.circle") } |
| + } |
| + .buttonStyle(.borderless) |
| + .accessibilityIdentifier("docs.oficinaid.signin") |
| + .padding(16) |
| + .frame(maxWidth: .infinity) |
| + } |
| + } |
| +} |
| + |
| +#if os(macOS) |
| +/// Docs ▸ Settings: who Docs is signed in as, and the version. SwiftUI would |
| +/// title the window "Oficina Docs Settings" from the display name; the plain |
| +/// name comes from the content's navigation title (rastrillo/native |
| +/// docs/mac-updates.md, "Not covered: the Settings window"). |
| +public struct DocsSettingsView: View { |
| + public enum Account: Equatable { |
| + case oficinaID(identity: String, team: String, teamLabel: String) |
| + case server(name: String, host: String) |
| + case none |
| + } |
| + |
| + private let account: Account |
| + private let block: DocsLeaveBlock? |
| + private let manage: () -> Void |
| + private let signOut: () -> Void |
| + private let signIn: () -> Void |
| + private let version: String |
| + |
| + /// `block` is the home window's guard: while it says why, "Change |
| + /// team…" and "Sign out" are disabled and the line is shown. |
| + public init(account: Account, block: DocsLeaveBlock?, version: String = DocsSettingsView.bundleVersion, |
| + manage: @escaping () -> Void, signOut: @escaping () -> Void, signIn: @escaping () -> Void) { |
| + self.account = account; self.block = block; self.version = version |
| + self.manage = manage; self.signOut = signOut; self.signIn = signIn |
| + } |
| + |
| + public static var bundleVersion: String { |
| + let info = Bundle.main.infoDictionary ?? [:] |
| + let short = info["CFBundleShortVersionString"] as? String ?? "0.1.0" |
| + return (info["CFBundleVersion"] as? String).map { "\(short) (\($0))" } ?? short |
| + } |
| + |
| + public var body: some View { |
| + Form { |
| + Section { |
| + switch account { |
| + case .oficinaID(let identity, let team, let teamLabel): |
| + LabeledContent { Text(verbatim: identity).textSelection(.enabled) } label: { Text(verbatim: "Oficina ID") } |
| + LabeledContent { Text(verbatim: "\(team) (\(teamLabel))") } label: { Text("native.settings.team", bundle: DocsResources.bundle) } |
| + HStack { |
| + Button { manage() } label: { Text("native.settings.changeTeam", bundle: DocsResources.bundle) } |
| + .disabled(block != nil) |
| + Spacer() |
| + Button(role: .destructive) { signOut() } label: { Text(verbatim: OficinaIDText.text("signOut", identity)) } |
| + .disabled(block != nil) |
| + } |
| + if let block { DocsBlockLine(block) } |
| + case .server(let name, let host): |
| + LabeledContent { Text(verbatim: name.isEmpty ? host : "\(name) (\(host))").textSelection(.enabled) } label: { |
| + Text("native.settings.server", bundle: DocsResources.bundle) |
| + } |
| + HStack { |
| + // Not guarded: a server account's list switches nothing |
| + // by itself, and the home window guards what it does. |
| + Button { manage() } label: { Text("native.settings.accounts", bundle: DocsResources.bundle) } |
| + Spacer() |
| + Button(role: .destructive) { signOut() } label: { Text("docs.signout.label", bundle: DocsResources.bundle) } |
| + .disabled(block != nil) |
| + } |
| + if let block { DocsBlockLine(block) } |
| + case .none: |
| + LabeledContent { Text("native.settings.signedOut", bundle: DocsResources.bundle) } label: { Text(verbatim: "Oficina ID") } |
| + Button { signIn() } label: { Text("native.settings.signIn", bundle: DocsResources.bundle) } |
| + } |
| + } header: { Text("native.settings.account", bundle: DocsResources.bundle) } |
| + Section { |
| + LabeledContent { Text(verbatim: version) } label: { Text("native.colophon.version", bundle: DocsResources.bundle) } |
| + } |
| + } |
| + .formStyle(.grouped) |
| + .frame(width: 480) |
| + .fixedSize(horizontal: false, vertical: true) |
| + .navigationTitle(Text("native.docs", bundle: DocsResources.bundle)) |
| + .tint(OficinaPalette.accent(.docs)) |
| + } |
| +} |
| +#endif |
diff --git a/native/apple/Sources/DocsKit/DocsSharingView.swift b/native/apple/Sources/DocsKit/DocsSharingView.swift| index 00b8f50..a80941b 100644 |
| --- a/native/apple/Sources/DocsKit/DocsSharingView.swift |
| +++ b/native/apple/Sources/DocsKit/DocsSharingView.swift |
| @@ -2,7 +2,7 @@ import RastrilloApple |
| import SwiftUI |
| @MainActor struct DocsSharingView: View { |
| - let client: NativeHTTP |
| + let client: NativeTransport |
| let sqid: String |
| @Environment(\.dismiss) private var dismiss |
| @State private var information: DocsShareInformation? |
diff --git a/native/apple/Sources/DocsKit/DocsWorkspace.swift b/native/apple/Sources/DocsKit/DocsWorkspace.swift| index 2559fcf..9a26437 100644 |
| --- a/native/apple/Sources/DocsKit/DocsWorkspace.swift |
| +++ b/native/apple/Sources/DocsKit/DocsWorkspace.swift |
| @@ -21,6 +21,11 @@ import SwiftUI |
| private let updateRecents: (([(String, String)]) -> Void)? |
| private let canSignOut: Bool |
| @Binding private var accountsRequested: Bool |
| + @Binding private var signOutRequested: Bool |
| + /// Oficina ID's words for the account controls: "Teams" and |
| + /// "Sign out of <label>". nil keeps the server sign-in's own. |
| + private let accountsLabel: String? |
| + private let signOutLabel: String? |
| @Binding private var createRequested: Bool |
| private let documentID: String? |
| private let openDocument: ((String, String) -> Void)? |
| @@ -29,13 +34,17 @@ import SwiftUI |
| private let signOut: () -> Void |
| private let accounts: (() -> Void)? |
| private let client: NativeHTTP |
| + private let transport: (@MainActor () -> NativeTransport?)? |
| + /// Why a sign-out asked from Settings was refused, said rather than swallowed. |
| + @State private var signOutRefusal: DocsLeaveBlock? |
| /// `transport` supplies the account's current session to the model on every |
| /// request; without one the model keeps `client` for its whole lifetime. |
| - public init(client: NativeHTTP, accountID: String? = nil, transport: (@MainActor () -> NativeTransport?)? = nil, accounts: (() -> Void)? = nil, signOut: @escaping () -> Void, documentID: String? = nil, newDocument: Bool = false, createDocument: (() -> Void)? = nil, documentChanged: ((String, String) -> Void)? = nil, canSignOut: Bool = true, createRequested: Binding<Bool> = .constant(false), accountsRequested: Binding<Bool> = .constant(false), openDocument: ((String, String) -> Void)? = nil, updateRecents: (([(String, String)]) -> Void)? = nil) { |
| + public init(client: NativeHTTP, accountID: String? = nil, transport: (@MainActor () -> NativeTransport?)? = nil, accounts: (() -> Void)? = nil, signOut: @escaping () -> Void, documentID: String? = nil, newDocument: Bool = false, createDocument: (() -> Void)? = nil, documentChanged: ((String, String) -> Void)? = nil, canSignOut: Bool = true, createRequested: Binding<Bool> = .constant(false), accountsRequested: Binding<Bool> = .constant(false), signOutRequested: Binding<Bool> = .constant(false), accountsLabel: String? = nil, signOutLabel: String? = nil, openDocument: ((String, String) -> Void)? = nil, updateRecents: (([(String, String)]) -> Void)? = nil) { |
| + self._signOutRequested = signOutRequested; self.accountsLabel = accountsLabel; self.signOutLabel = signOutLabel |
| self.updateRecents = updateRecents; self.canSignOut = canSignOut; self._createRequested = createRequested; self._accountsRequested = accountsRequested; self.documentID = documentID; self.openDocument = openDocument |
| self.newDocument = newDocument; self.createDocument = createDocument; self.documentChanged = documentChanged |
| let offline = accountID.map { DocsOfflineAccount.account($0, origin: client.origin, fallback: client, transport: transport) } |
| - _model = State(initialValue: DocsModel(transport: transport ?? { client }, draft: newDocument, offlineAccount: offline)); self.signOut = signOut; self.accounts = accounts; self.client = client |
| + _model = State(initialValue: DocsModel(transport: transport ?? { client }, draft: newDocument, offlineAccount: offline)); self.signOut = signOut; self.accounts = accounts; self.client = client; self.transport = transport |
| } |
| private var library: some View { |
| List { |
| @@ -51,14 +60,15 @@ import SwiftUI |
| .toolbar { |
| if let accounts { |
| ToolbarItem(placement: .navigation) { |
| - Button(docsMacString("Accounts"), systemImage: "chevron.backward", action: accounts).disabled(model.hasUnsavedChanges || model.creatingDocument) |
| + Button(accountsLabel ?? docsMacString("Accounts"), systemImage: accountsLabel == nil ? "chevron.backward" : "person.crop.circle", action: accounts).disabled(model.hasUnsavedChanges || model.creatingDocument) |
| + .accessibilityIdentifier("docs.accounts") |
| } |
| } |
| ToolbarItemGroup { |
| DocsJumpControls(presented: $jumping) |
| if model.canCreate { Button { beginDocument() } label: { Label { Text("docs.list.create.label", bundle: DocsResources.bundle) } icon: { Image(systemName: "plus") } }.accessibilityIdentifier("docs.create") } |
| - Button { if !model.hasUnsavedChanges && !model.creatingDocument { signOut() } } label: { Text("docs.signout.label", bundle: DocsResources.bundle) }.disabled(model.hasUnsavedChanges || model.creatingDocument) |
| + Button { if !model.hasUnsavedChanges && !model.creatingDocument { signOut() } } label: { signOutText }.disabled(model.hasUnsavedChanges || model.creatingDocument) |
| #if os(iOS) |
| // The Colophon, beside Sign out: the iPhone app has no |
| // settings screen of its own. The Mac has it in the Help menu. |
| @@ -93,12 +103,24 @@ import SwiftUI |
| Text("native.close", bundle: DocsResources.bundle) |
| } |
| } |
| + .alert(signOutRefusal?.message ?? "", isPresented: Binding(get: { signOutRefusal != nil }, set: { if !$0 { signOutRefusal = nil } })) { |
| + Button { signOutRefusal = nil } label: { Text("native.close", bundle: DocsResources.bundle) } |
| + } |
| .onChange(of: model.documents.map { "\($0.sqid)\u{0}\($0.title)" }) { |
| if query.isEmpty { updateRecents?(model.documents.map { ($0.sqid, $0.title) }) } |
| } |
| .onChange(of: accountsRequested && !model.creatingDocument, initial: true) { _, ready in |
| if ready { accountsRequested = false; accounts?() } |
| } |
| + // Settings' "Sign out" asks the home window, which holds the guard: |
| + // nothing unsent, no draft being created, no document windows open. |
| + .onChange(of: signOutRequested, initial: true) { _, requested in |
| + guard requested, documentID == nil, !newDocument else { return } |
| + signOutRequested = false |
| + if !canSignOut { signOutRefusal = .openDocuments } |
| + else if model.hasUnsavedChanges || model.creatingDocument { signOutRefusal = .sending } |
| + else { signOut() } |
| + } |
| .onChange(of: createRequested, initial: true) { _, requested in |
| if requested && documentID == nil { beginDocument(); createRequested = false } |
| } |
| @@ -107,7 +129,7 @@ import SwiftUI |
| .onChange(of: [model.detail?.sqid, model.detail?.title]) { |
| if !model.isDraft, let detail = model.detail { documentChanged?(detail.sqid, detail.title) } |
| } |
| - .sheet(isPresented: $jumping) { DocsJumpSheet(model: model, client: client) } |
| + .sheet(isPresented: $jumping) { DocsJumpSheet(model: model, client: liveClient) } |
| .onDisappear { Task { await model.stop() } } |
| .onChange(of: scenePhase) { _, phase in |
| if phase == .background { Task { await model.persistReplica() } } |
| @@ -124,9 +146,23 @@ import SwiftUI |
| Text("native.close.pending.detail", bundle: DocsResources.bundle) |
| } |
| .sheet(isPresented: $sharing) { |
| - if let detail = model.detail { DocsSharingView(client: client, sqid: detail.sqid) } |
| + if let detail = model.detail { DocsSharingView(client: liveClient, sqid: detail.sqid) } |
| } |
| } |
| + /// The client sharing, export, images and Jump use, resolved when they |
| + /// use it: the account's current session (re-minted every 24 hours and |
| + /// on a 401, and watched for both) when the window has a supplier, the |
| + /// one it was opened with otherwise. |
| + private var liveClient: NativeTransport { Self.liveClient(transport, fallback: client) } |
| + |
| + static func liveClient(_ transport: (@MainActor () -> NativeTransport?)?, fallback: NativeTransport) -> NativeTransport { |
| + transport?() ?? fallback |
| + } |
| + |
| + private var signOutText: Text { |
| + if let signOutLabel { return Text(verbatim: signOutLabel) } |
| + return Text("docs.signout.label", bundle: DocsResources.bundle) |
| + } |
| private func beginDocument() { |
| #if os(macOS) |
| createDocument?() |
| @@ -185,7 +221,7 @@ import SwiftUI |
| if model.loading { ProgressView() } |
| if let projection = model.projection { |
| let documentPath = "/d/" + (model.detail?.sqid ?? "") |
| - let text = NativeTextProjection.render(projection, images: images.images(forDocumentPath: documentPath, client: client)) |
| + let text = NativeTextProjection.render(projection, images: images.images(forDocumentPath: documentPath, client: liveClient)) |
| EditorToolbar(model: model, content: text) |
| Divider() |
| NativeDocumentTextView(content: text, generation: model.projectionGeneration, didRender: model.didRender, compositionChanged: model.compositionChanged, isEditable: model.detail?.can_write == true && !model.inputPaused, paged: paged, pendingInput: model.hasPendingInput, canRender: model.canRender, currentSelection: model.currentSelection, selection: $model.selection, edit: model.enqueue, action: { action in |
| @@ -200,7 +236,7 @@ import SwiftUI |
| return DocumentCommands(model: model, content: text).perform(action) |
| }, selectionMoved: model.selectionMovedExplicitly, canAction: { action in model.detail?.can_write == true && !model.hasPendingInput && !model.composing && !model.inputPaused && (action == "undo" ? projection.canUndo : projection.canRedo) }, explicitCommandRevision: model.explicitCommandRevision, zoom: zoom, typingMarks: model.typingMarks) |
| .id(model.editorIdentity) |
| - .task(id: [documentPath] + DocsImageStore.sources(in: projection)) { await images.load(sources: DocsImageStore.sources(in: projection), client: client, documentPath: documentPath) } |
| + .task(id: [documentPath] + DocsImageStore.sources(in: projection)) { await images.load(sources: DocsImageStore.sources(in: projection), client: liveClient, documentPath: documentPath) } |
| } else { |
| ContentUnavailableView { Label { Text("native.open", bundle: DocsResources.bundle) } icon: { Image(systemName: "doc.text") } } |
| } |
| @@ -214,7 +250,7 @@ import SwiftUI |
| DocsJumpControls(presented: $jumping) |
| if let detail = model.detail, !model.isDraft { |
| Toggle(isOn: $paged) { Text("docs.editor.menu.view.paged", bundle: DocsResources.bundle) } |
| - DocumentExportControls(client: client, sqid: detail.sqid, title: detail.title) { |
| + DocumentExportControls(client: liveClient, sqid: detail.sqid, title: detail.title) { |
| return await model.saveAll() |
| }.id(detail.sqid) |
| if let projection = model.projection { DocsToolsControls(projection: projection, content: NativeTextProjection.render(projection), selection: model.selection) } |
| @@ -228,7 +264,7 @@ import SwiftUI |
| #else |
| .background { |
| if let detail = model.detail, !model.isDraft { |
| - DocumentExportControls(client: client, sqid: detail.sqid, title: detail.title, prepare: { await model.saveAll() }, request: $exportRequest) |
| + DocumentExportControls(client: liveClient, sqid: detail.sqid, title: detail.title, prepare: { await model.saveAll() }, request: $exportRequest) |
| .frame(width: 0, height: 0).hidden().accessibilityHidden(true) |
| } |
| } |
| @@ -255,7 +291,7 @@ import SwiftUI |
| .overlay(alignment: .leading) { Divider() } |
| } |
| } |
| - .focusedSceneValue(\.docsEditor, DocsEditorContext(model: model, rename: beginRename, client: client, zoom: $zoom, paged: $paged, inspecting: $inspecting, sharing: $sharing, exportRequest: $exportRequest)) |
| + .focusedSceneValue(\.docsEditor, DocsEditorContext(model: model, rename: beginRename, client: liveClient, zoom: $zoom, paged: $paged, inspecting: $inspecting, sharing: $sharing, exportRequest: $exportRequest)) |
| #endif |
| } |
diff --git a/native/apple/Sources/DocsKit/DocumentExportControls.swift b/native/apple/Sources/DocsKit/DocumentExportControls.swift| index 7db4b70..d84fa0e 100644 |
| --- a/native/apple/Sources/DocsKit/DocumentExportControls.swift |
| +++ b/native/apple/Sources/DocsKit/DocumentExportControls.swift |
| @@ -23,7 +23,7 @@ struct ExportedDocument: Transferable { |
| } |
| } |
| @MainActor struct DocumentExportControls: View { |
| - let client: NativeHTTP |
| + let client: NativeTransport |
| let sqid: String |
| let title: String |
| let prepare: () async -> Bool |
| @@ -34,7 +34,7 @@ struct ExportedDocument: Transferable { |
| @State private var active = true |
| @State private var type = UTType.pdf |
| @State private var failed = false |
| - init(client: NativeHTTP, sqid: String, title: String, prepare: @escaping () async -> Bool, request: Binding<String?> = .constant(nil)) { |
| + init(client: NativeTransport, sqid: String, title: String, prepare: @escaping () async -> Bool, request: Binding<String?> = .constant(nil)) { |
| self.client = client; self.sqid = sqid; self.title = title; self.prepare = prepare; self._request = request |
| } |
| var body: some View { |
diff --git a/native/apple/Sources/DocsKit/Resources/Colophon.json b/native/apple/Sources/DocsKit/Resources/Colophon.json| index d234184..aac8ed9 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/Colophon.json |
| +++ b/native/apple/Sources/DocsKit/Resources/Colophon.json |
| @@ -1737,7 +1737,7 @@ |
| { |
| "ecosystem": "swift", |
| "name": "native", |
| - "version": "b6a4067e39ef", |
| + "version": "f1c7a14db2dd", |
| "notices": [ |
| { |
| "Name": "LICENSE", |
diff --git a/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings| index 9dd6cc3..a2c0b6a 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "الصفحة الرئيسية والمصدر"; |
| "native.colophon.missing" = "تُنشر هذه الحزمة بلا ملف ترخيص، فلا يوجد نص لعرضه."; |
| "native.colophon.notincluded" = "يُبنى التطبيق بهذه الأداة لكنها ليست جزءًا مما يوزّعه، لذا لا يُنسخ نص ترخيصها هنا. إنه في مصدر المشروع."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "تسجيل الدخول باستخدام Oficina ID"; |
| +"native.oficinaid.teams" = "الفرق"; |
| +"native.done" = "تم"; |
| +"native.settings.account" = "الحساب"; |
| +"native.settings.server" = "الخادم"; |
| +"native.settings.team" = "الفريق"; |
| +"native.settings.signedOut" = "لم يتم تسجيل الدخول"; |
| +"native.settings.changeTeam" = "تغيير الفريق…"; |
| +"native.settings.accounts" = "الحسابات…"; |
| +"native.settings.signIn" = "تسجيل الدخول…"; |
| +"native.leave.sending" = "لا يزال Docs يرسل التغييرات. حاول مرة أخرى بعد حفظها."; |
| +"native.leave.openDocuments" = "أغلق المستندات المفتوحة لهذا الحساب أولًا."; |
diff --git a/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings| index 5b942bf..14855a7 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "হোম পেজ ও সোর্স"; |
| "native.colophon.missing" = "এই প্যাকেজটি লাইসেন্স ফাইল ছাড়াই প্রকাশিত, তাই দেখানোর মতো কোনো লেখা নেই।"; |
| "native.colophon.notincluded" = "অ্যাপটি এটি দিয়ে তৈরি হয়, কিন্তু এটি অ্যাপের সঙ্গে দেওয়া হয় না, তাই এর লাইসেন্স এখানে কপি করা হয়নি। এটি প্রকল্পের সোর্সে আছে।"; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Oficina ID দিয়ে সাইন ইন করুন"; |
| +"native.oficinaid.teams" = "টিম"; |
| +"native.done" = "সম্পন্ন"; |
| +"native.settings.account" = "অ্যাকাউন্ট"; |
| +"native.settings.server" = "সার্ভার"; |
| +"native.settings.team" = "টিম"; |
| +"native.settings.signedOut" = "সাইন ইন করা নেই"; |
| +"native.settings.changeTeam" = "টিম পরিবর্তন করুন…"; |
| +"native.settings.accounts" = "অ্যাকাউন্ট…"; |
| +"native.settings.signIn" = "সাইন ইন করুন…"; |
| +"native.leave.sending" = "Docs এখনও পরিবর্তন পাঠাচ্ছে। সেগুলি সংরক্ষিত হলে আবার চেষ্টা করুন।"; |
| +"native.leave.openDocuments" = "প্রথমে এই অ্যাকাউন্টের খোলা ডকুমেন্টগুলি বন্ধ করুন।"; |
diff --git a/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings| index 107f5e7..5a3688f 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings |
| @@ -196,3 +196,17 @@ |
| "native.colophon.homeandsource" = "Home page and source"; |
| "native.colophon.missing" = "This package is published without a license file, so there is no text to show."; |
| "native.colophon.notincluded" = "The app is built with this, but it isn’t part of what the app ships, so its license text isn’t copied here. It is in the project’s source."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Sign in with Oficina ID"; |
| +"native.oficinaid.teams" = "Teams"; |
| +"native.done" = "Done"; |
| +"native.settings.account" = "Account"; |
| +"native.settings.server" = "Server"; |
| +"native.settings.team" = "Team"; |
| +"native.settings.signedOut" = "Not signed in"; |
| +"native.settings.changeTeam" = "Change team…"; |
| +"native.settings.accounts" = "Accounts…"; |
| +"native.settings.signIn" = "Sign in…"; |
| +"native.leave.sending" = "Docs is still sending changes. Try again once they’re saved."; |
| +"native.leave.openDocuments" = "Close this account’s open documents first."; |
diff --git a/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings| index ef6d150..b068458 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "Página principal y código fuente"; |
| "native.colophon.missing" = "Este paquete se publica sin archivo de licencia, así que no hay texto que mostrar."; |
| "native.colophon.notincluded" = "La app se compila con esto, pero no forma parte de lo que distribuye, así que su licencia no se copia aquí. Está en el código fuente del proyecto."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Iniciar sesión con Oficina ID"; |
| +"native.oficinaid.teams" = "Equipos"; |
| +"native.done" = "Listo"; |
| +"native.settings.account" = "Cuenta"; |
| +"native.settings.server" = "Servidor"; |
| +"native.settings.team" = "Equipo"; |
| +"native.settings.signedOut" = "Sin iniciar sesión"; |
| +"native.settings.changeTeam" = "Cambiar de equipo…"; |
| +"native.settings.accounts" = "Cuentas…"; |
| +"native.settings.signIn" = "Iniciar sesión…"; |
| +"native.leave.sending" = "Docs todavía está enviando cambios. Inténtalo de nuevo cuando se hayan guardado."; |
| +"native.leave.openDocuments" = "Cierra primero los documentos abiertos de esta cuenta."; |
diff --git a/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings| index 488f9d0..145a95a 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "Leathanach baile agus foinse"; |
| "native.colophon.missing" = "Foilsítear an pacáiste seo gan comhad ceadúnais, mar sin níl aon téacs le taispeáint."; |
| "native.colophon.notincluded" = "Tógtar an aip leis seo, ach ní cuid dá seachadann sí é, mar sin ní chóipeáiltear a cheadúnas anseo. Tá sé i bhfoinse an tionscadail."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Sínigh isteach le Oficina ID"; |
| +"native.oficinaid.teams" = "Foirne"; |
| +"native.done" = "Déanta"; |
| +"native.settings.account" = "Cuntas"; |
| +"native.settings.server" = "Freastalaí"; |
| +"native.settings.team" = "Foireann"; |
| +"native.settings.signedOut" = "Níl tú sínithe isteach"; |
| +"native.settings.changeTeam" = "Athraigh foireann…"; |
| +"native.settings.accounts" = "Cuntais…"; |
| +"native.settings.signIn" = "Sínigh isteach…"; |
| +"native.leave.sending" = "Tá Docs fós ag seoladh athruithe. Bain triail eile as nuair a bheidh siad sábháilte."; |
| +"native.leave.openDocuments" = "Dún doiciméid oscailte an chuntais seo ar dtús."; |
diff --git a/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings| index 574bece..2f8bcc7 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "होम पेज और सोर्स"; |
| "native.colophon.missing" = "यह पैकेज बिना लाइसेंस फ़ाइल के प्रकाशित है, इसलिए दिखाने के लिए कोई पाठ नहीं है।"; |
| "native.colophon.notincluded" = "ऐप इससे बनाया जाता है, पर यह ऐप के साथ नहीं आता, इसलिए इसका लाइसेंस यहाँ कॉपी नहीं किया गया है। वह प्रोजेक्ट के सोर्स में है।"; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Oficina ID से साइन इन करें"; |
| +"native.oficinaid.teams" = "टीमें"; |
| +"native.done" = "हो गया"; |
| +"native.settings.account" = "खाता"; |
| +"native.settings.server" = "सर्वर"; |
| +"native.settings.team" = "टीम"; |
| +"native.settings.signedOut" = "साइन इन नहीं है"; |
| +"native.settings.changeTeam" = "टीम बदलें…"; |
| +"native.settings.accounts" = "खाते…"; |
| +"native.settings.signIn" = "साइन इन करें…"; |
| +"native.leave.sending" = "Docs अभी भी बदलाव भेज रहा है। उनके सहेजे जाने के बाद फिर से कोशिश करें।"; |
| +"native.leave.openDocuments" = "पहले इस खाते के खुले दस्तावेज़ बंद करें।"; |
diff --git a/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings| index d75ab1f..5e26a65 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "ホームページとソース"; |
| "native.colophon.missing" = "このパッケージはライセンスファイルなしで公開されているため、表示する本文がありません。"; |
| "native.colophon.notincluded" = "アプリはこれを使ってビルドされますが、アプリには含まれないため、ライセンス本文はここに複製していません。プロジェクトのソースにあります。"; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Oficina ID でサインイン"; |
| +"native.oficinaid.teams" = "チーム"; |
| +"native.done" = "完了"; |
| +"native.settings.account" = "アカウント"; |
| +"native.settings.server" = "サーバ"; |
| +"native.settings.team" = "チーム"; |
| +"native.settings.signedOut" = "サインインしていません"; |
| +"native.settings.changeTeam" = "チームを変更…"; |
| +"native.settings.accounts" = "アカウント…"; |
| +"native.settings.signIn" = "サインイン…"; |
| +"native.leave.sending" = "Docs はまだ変更を送信中です。保存されてからもう一度お試しください。"; |
| +"native.leave.openDocuments" = "先にこのアカウントの開いている書類を閉じてください。"; |
diff --git a/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings| index 5a070db..2879eac 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "Página inicial e código-fonte"; |
| "native.colophon.missing" = "Este pacote é publicado sem ficheiro de licença, por isso não há texto para mostrar."; |
| "native.colophon.notincluded" = "A app é construída com isto, mas não faz parte do que distribui, por isso a licença não é copiada aqui. Está no código-fonte do projeto."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Iniciar sessão com o Oficina ID"; |
| +"native.oficinaid.teams" = "Equipas"; |
| +"native.done" = "Concluído"; |
| +"native.settings.account" = "Conta"; |
| +"native.settings.server" = "Servidor"; |
| +"native.settings.team" = "Equipa"; |
| +"native.settings.signedOut" = "Sessão não iniciada"; |
| +"native.settings.changeTeam" = "Mudar de equipa…"; |
| +"native.settings.accounts" = "Contas…"; |
| +"native.settings.signIn" = "Iniciar sessão…"; |
| +"native.leave.sending" = "O Docs ainda está a enviar alterações. Tente de novo quando estiverem guardadas."; |
| +"native.leave.openDocuments" = "Feche primeiro os documentos abertos desta conta."; |
diff --git a/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings| index 549dc7c..980a775 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "Сайт и исходный код"; |
| "native.colophon.missing" = "Этот пакет опубликован без файла лицензии, поэтому показать нечего."; |
| "native.colophon.notincluded" = "Приложение собирается с помощью этого инструмента, но он не входит в поставку, поэтому текст его лицензии здесь не приводится. Он есть в исходном коде проекта."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Войти с Oficina ID"; |
| +"native.oficinaid.teams" = "Команды"; |
| +"native.done" = "Готово"; |
| +"native.settings.account" = "Учётная запись"; |
| +"native.settings.server" = "Сервер"; |
| +"native.settings.team" = "Команда"; |
| +"native.settings.signedOut" = "Вход не выполнен"; |
| +"native.settings.changeTeam" = "Сменить команду…"; |
| +"native.settings.accounts" = "Учётные записи…"; |
| +"native.settings.signIn" = "Войти…"; |
| +"native.leave.sending" = "Docs ещё отправляет изменения. Повторите попытку, когда они сохранятся."; |
| +"native.leave.openDocuments" = "Сначала закройте открытые документы этой учётной записи."; |
diff --git a/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings| index 81196a7..6584734 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "Trang chủ và mã nguồn"; |
| "native.colophon.missing" = "Gói này được phát hành không kèm tệp giấy phép, nên không có nội dung để hiển thị."; |
| "native.colophon.notincluded" = "Ứng dụng được xây dựng bằng công cụ này nhưng nó không nằm trong ứng dụng, nên giấy phép không được chép ở đây. Giấy phép có trong mã nguồn của dự án."; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "Đăng nhập bằng Oficina ID"; |
| +"native.oficinaid.teams" = "Nhóm"; |
| +"native.done" = "Xong"; |
| +"native.settings.account" = "Tài khoản"; |
| +"native.settings.server" = "Máy chủ"; |
| +"native.settings.team" = "Nhóm"; |
| +"native.settings.signedOut" = "Chưa đăng nhập"; |
| +"native.settings.changeTeam" = "Đổi nhóm…"; |
| +"native.settings.accounts" = "Tài khoản…"; |
| +"native.settings.signIn" = "Đăng nhập…"; |
| +"native.leave.sending" = "Docs vẫn đang gửi các thay đổi. Hãy thử lại khi chúng đã được lưu."; |
| +"native.leave.openDocuments" = "Hãy đóng các tài liệu đang mở của tài khoản này trước."; |
diff --git a/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings| index 72dada2..d5f470a 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "主頁同原始碼"; |
| "native.colophon.missing" = "呢個套件發佈時冇附授權檔案,所以冇內容可以顯示。"; |
| "native.colophon.notincluded" = "個 app 係用呢樣嘢建置嘅,但佢唔係 app 嘅一部分,所以授權全文冇抄喺度。授權喺項目嘅原始碼入面。"; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "用 Oficina ID 登入"; |
| +"native.oficinaid.teams" = "團隊"; |
| +"native.done" = "完成"; |
| +"native.settings.account" = "帳戶"; |
| +"native.settings.server" = "伺服器"; |
| +"native.settings.team" = "團隊"; |
| +"native.settings.signedOut" = "未登入"; |
| +"native.settings.changeTeam" = "轉團隊…"; |
| +"native.settings.accounts" = "帳戶…"; |
| +"native.settings.signIn" = "登入…"; |
| +"native.leave.sending" = "Docs 仲傳緊啲改動。儲存好之後再試吓。"; |
| +"native.leave.openDocuments" = "請先閂咗呢個帳戶開緊嘅文件。"; |
diff --git a/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings| index 08f8290..2f929b0 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings |
| @@ -191,3 +191,17 @@ |
| "native.colophon.homeandsource" = "主页与源代码"; |
| "native.colophon.missing" = "该软件包发布时未附许可文件,因此没有可显示的内容。"; |
| "native.colophon.notincluded" = "应用使用它构建,但它不属于应用分发的内容,因此此处未复制其许可全文。许可见项目源代码。"; |
| + |
| +/* Oficina ID (spec 2026-11-14-oficina-id-native, slice A) and the Mac Settings window. */ |
| +"native.oficinaid.signin" = "使用 Oficina ID 登录"; |
| +"native.oficinaid.teams" = "团队"; |
| +"native.done" = "完成"; |
| +"native.settings.account" = "账户"; |
| +"native.settings.server" = "服务器"; |
| +"native.settings.team" = "团队"; |
| +"native.settings.signedOut" = "未登录"; |
| +"native.settings.changeTeam" = "更换团队…"; |
| +"native.settings.accounts" = "账户…"; |
| +"native.settings.signIn" = "登录…"; |
| +"native.leave.sending" = "Docs 仍在发送更改。保存后请重试。"; |
| +"native.leave.openDocuments" = "请先关闭此账户中打开的文档。"; |
diff --git a/native/apple/Tests/DocsKitTests/OficinaIDAdoptionTests.swift b/native/apple/Tests/DocsKitTests/OficinaIDAdoptionTests.swift| new file mode 100644 |
| index 0000000..1f33066 |
| --- /dev/null |
| +++ b/native/apple/Tests/DocsKitTests/OficinaIDAdoptionTests.swift |
| @@ -0,0 +1,448 @@ |
| +import CryptoKit |
| +import Foundation |
| +import RastrilloApple |
| +import RastrilloNative |
| +import RastrilloTestSupport |
| +import XCTest |
| +@testable import DocsKit |
| + |
| +/// Docs on Oficina ID (spec 2026-11-14-oficina-id-native, slice A), against |
| +/// the kit's in-memory Home, directory and instances: no keychain, App Group |
| +/// or network. |
| +@MainActor final class OficinaIDAdoptionTests: XCTestCase { |
| + final class Clock: @unchecked Sendable { var date = Date(timeIntervalSince1970: 1_800_000_000) } |
| + |
| + let paulca = URL(string: "https://paulca.docs.oficina.works")! |
| + let tito = URL(string: "https://tito.docs.oficina.works")! |
| + var service: FakeOficinaIDService! |
| + var clock: Clock! |
| + var suites: [String] = [] |
| + |
| + override func setUp() async throws { |
| + service = FakeOficinaIDService() |
| + clock = Clock() |
| + } |
| + |
| + override func tearDown() async throws { |
| + for suite in suites { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) } |
| + } |
| + |
| + private func defaults() -> UserDefaults { |
| + let suite = "OficinaIDAdoptionTests.\(UUID().uuidString)" |
| + suites.append(suite) |
| + return UserDefaults(suiteName: suite)! |
| + } |
| + |
| + private func team(_ sqid: String, _ name: String, _ label: String, apps: [String] = ["docs"]) -> OficinaTeam { |
| + OficinaTeam(sqid: sqid, label: label, name: name, role: "member", |
| + apps: apps.map { OficinaTeamApp(app: $0, origin: "https://\(label).\($0).oficina.works", consumerID: "\(sqid)-\($0)") }) |
| + } |
| + |
| + /// One device: the shared and private stores, the App Group and Docs' |
| + /// own defaults outlive an app run, so a second session on the same |
| + /// device is Docs launched again. |
| + final class Device { |
| + let shared = OficinaMemoryStore(), own = OficinaMemoryStore() |
| + let group: UserDefaults, defaults: UserDefaults |
| + init(group: UserDefaults, defaults: UserDefaults) { self.group = group; self.defaults = defaults } |
| + } |
| + |
| + private func device() -> Device { Device(group: defaults(), defaults: defaults()) } |
| + |
| + private func session(on device: Device? = nil) -> DocsOficinaSession { |
| + let clock = self.clock! |
| + let device = device ?? self.device() |
| + let store = OficinaIDStore(shared: device.shared, appPrivate: device.own, group: device.group) |
| + let model = OficinaIDModel(configuration: DocsOficinaSession.configuration, store: store, service: service, |
| + passkeys: FakePasskeys(), makeKey: { OficinaSoftwareKey() }, now: { clock.date }, |
| + appDefaults: device.defaults) |
| + return DocsOficinaSession(model: model, now: { clock.date }) |
| + } |
| + |
| + private func onePaulTeam(_ identity: String = "id-paul", email: String = "paul@tito.io") { |
| + service.addPerson(email: email, identityID: identity) |
| + service.setTeams([team("t1", "Paul", "paulca")], for: identity) |
| + service.admit(identity, at: paulca, as: .linked) |
| + } |
| + |
| + /// Welcome → Email → Code, as a person would. |
| + private func signIn(_ session: DocsOficinaSession, email: String = "paul@tito.io") async { |
| + await session.start() |
| + if session.model.step != .email { XCTAssertEqual(session.model.step, .welcome) } |
| + session.model.continueWithEmail() |
| + session.model.email = email |
| + await session.model.submitEmail() |
| + session.model.code = FakeOficinaIDService.goodCode |
| + await session.model.submitCode() |
| + } |
| + |
| + private func exchanges(at origin: URL) -> Int { service.calls.filter { $0 == "exchange \(origin.absoluteString)" }.count } |
| + |
| + func testRouteIsOficinaIDUnlessSomeoneSignedInTheOldWay() { |
| + XCTAssertEqual(DocsSignInRoute.resolve(stored: "", hasServerAccounts: false), .oficinaID) |
| + // Appendix C: old per-app sessions keep working until replaced. |
| + XCTAssertEqual(DocsSignInRoute.resolve(stored: "", hasServerAccounts: true), .server) |
| + XCTAssertEqual(DocsSignInRoute.resolve(stored: "oficina-id", hasServerAccounts: true), .oficinaID) |
| + XCTAssertEqual(DocsSignInRoute.resolve(stored: "server", hasServerAccounts: false), .server) |
| + XCTAssertEqual(DocsSignInRoute.resolve(stored: "something else", hasServerAccounts: false), .oficinaID) |
| + } |
| + |
| + func testAccountsBelongToTheirIdentityOnly() { |
| + let account = DocsOficinaSession.accountID(identity: "id-1", team: "t1") |
| + XCTAssertTrue(DocsOficinaSession.account(account, belongsTo: "id-1")) |
| + XCTAssertFalse(DocsOficinaSession.account(account, belongsTo: "id")) |
| + XCTAssertFalse(DocsOficinaSession.account(DocsOficinaSession.accountID(identity: "id-10", team: "t1"), belongsTo: "id-1")) |
| + XCTAssertFalse(DocsOficinaSession.account(UUID().uuidString, belongsTo: "id-1")) |
| + } |
| + |
| + func testOneDocsTeamSignsStraightInAndTheWorkspaceGetsItsSession() async throws { |
| + service.addPerson(email: "paul@tito.io", identityID: "id-paul") |
| + // A team without Docs is no team for Docs. |
| + service.setTeams([team("t1", "Paul", "paulca"), team("t3", "Sums", "sums", apps: ["sheets"])], for: "id-paul") |
| + service.admit("id-paul", at: paulca, as: .linked) |
| + let docs = session() |
| + await signIn(docs) |
| + let state = try XCTUnwrap(docs.signedIn) |
| + XCTAssertEqual(state.origin, paulca) |
| + let account = DocsOficinaSession.accountID(state) |
| + XCTAssertEqual(account, "oficina-id.id-paul.t1") |
| + let transport = try XCTUnwrap(docs.transport(for: account)()) |
| + XCTAssertEqual(transport.origin, paulca) |
| + XCTAssertEqual(docs.client(for: account)?.credential?.value, state.session.value) |
| + XCTAssertTrue(service.isLive(session: state.session)) |
| + // Another identity's account gets nothing. |
| + XCTAssertNil(docs.transport(for: DocsOficinaSession.accountID(identity: "id-other", team: "t1"))()) |
| + } |
| + |
| + func testARefusedSessionIsReMintedOnceAMinute() async throws { |
| + service.addPerson(email: "paul@tito.io", identityID: "id-paul") |
| + service.setTeams([team("t1", "Paul", "paulca")], for: "id-paul") |
| + service.admit("id-paul", at: paulca, as: .linked) |
| + let docs = session() |
| + await signIn(docs) |
| + let first = try XCTUnwrap(docs.signedIn) |
| + let account = DocsOficinaSession.accountID(first) |
| + XCTAssertEqual(exchanges(at: paulca), 1) |
| + |
| + service.expire(session: first.session) |
| + await docs.rejected(account) |
| + let second = try XCTUnwrap(docs.signedIn) |
| + XCTAssertNotEqual(second.session.value, first.session.value) |
| + XCTAssertEqual(docs.client(for: account)?.credential?.value, second.session.value, "the supplier follows the new session") |
| + XCTAssertEqual(exchanges(at: paulca), 2) |
| + |
| + // An instance that keeps refusing cannot set off a loop. |
| + await docs.rejected(account) |
| + XCTAssertEqual(exchanges(at: paulca), 2) |
| + clock.date.addTimeInterval(61) |
| + await docs.rejected(account) |
| + XCTAssertEqual(exchanges(at: paulca), 3) |
| + |
| + // Only the team in use is re-minted. |
| + await docs.rejected(DocsOficinaSession.accountID(identity: "id-paul", team: "t2")) |
| + XCTAssertEqual(exchanges(at: paulca), 3) |
| + } |
| + |
| + func testSigningOutLeavesNoTransport() async throws { |
| + service.addPerson(email: "paul@tito.io", identityID: "id-paul") |
| + service.setTeams([team("t1", "Paul", "paulca")], for: "id-paul") |
| + service.admit("id-paul", at: paulca, as: .linked) |
| + let docs = session() |
| + await signIn(docs) |
| + let state = try XCTUnwrap(docs.signedIn) |
| + let supplier = docs.transport(for: DocsOficinaSession.accountID(state)) |
| + XCTAssertNotNil(supplier()) |
| + docs.model.signOut() |
| + await docs.model.cleanup?.value |
| + XCTAssertEqual(docs.model.step, .welcome) |
| + XCTAssertNil(supplier(), "a workspace still open after sign-out must fail as unauthorized, not send") |
| + XCTAssertFalse(service.isLive(session: state.session), "the instance session is signed out too (§10)") |
| + } |
| + |
| + func testSwitchingTeamKeepsTheOtherTeamsSession() async throws { |
| + service.addPerson(email: "paul@tito.io", identityID: "id-paul") |
| + let paul = team("t1", "Paul", "paulca"), titoTeam = team("t2", "Tito", "tito") |
| + service.setTeams([paul, titoTeam], for: "id-paul") |
| + service.admit("id-paul", at: paulca, as: .linked) |
| + service.admit("id-paul", at: tito, as: .linked) |
| + let docs = session() |
| + await signIn(docs) |
| + guard case .teams(let teams) = docs.model.step else { return XCTFail("two Docs teams ask which: \(docs.model.step)") } |
| + XCTAssertEqual(DocsTeamPicker.teams(teams, current: paul).map(\.sqid), ["t1", "t2"]) |
| + await docs.model.choose(paul) |
| + let first = try XCTUnwrap(docs.signedIn) |
| + await docs.model.choose(titoTeam) |
| + let second = try XCTUnwrap(docs.signedIn) |
| + XCTAssertEqual(second.origin, tito) |
| + // A document window of the first team keeps its session. |
| + XCTAssertEqual(docs.client(for: DocsOficinaSession.accountID(first))?.credential?.value, first.session.value) |
| + XCTAssertNotNil(docs.client(for: DocsOficinaSession.accountID(second))) |
| + } |
| + |
| + func testTeamPickerListsDocsTeamsAndAlwaysTheCurrentOne() { |
| + let paul = team("t1", "Paul", "paulca"), sums = team("t3", "Sums", "sums", apps: ["sheets"]) |
| + let campbells = team("t2", "campbells", "campbells") |
| + XCTAssertEqual(DocsTeamPicker.teams([sums, paul, campbells], current: paul).map(\.sqid), ["t2", "t1"]) |
| + // An empty or missing cache still shows the team in use. |
| + XCTAssertEqual(DocsTeamPicker.teams(nil, current: paul).map(\.sqid), ["t1"]) |
| + } |
| + |
| + func testTheWatchReportsRefusedSessionsOnly() async throws { |
| + final class Count: @unchecked Sendable { var value = 0 } |
| + let count = Count() |
| + let scripted = ScriptedTransport([.respond(status: 200), .respond(status: 401), .respond(status: 303), |
| + .respond(status: 403), .respond(status: 401)]) |
| + let watch = DocsSessionWatch(inner: scripted) { count.value += 1 } |
| + _ = try await watch.responseDetails("/", method: "GET", body: nil, contentType: "application/json", maxBytes: 1024) |
| + XCTAssertEqual(count.value, 0) |
| + _ = try await watch.responseDetails("/", method: "GET", body: nil, contentType: "application/json", maxBytes: 1024) |
| + _ = try await watch.responseDetails("/", method: "GET", body: nil, contentType: "application/json", maxBytes: 1024) |
| + XCTAssertEqual(count.value, 2, "401 and the 303 to sign-in are an ended session") |
| + _ = try await watch.responseDetails("/", method: "GET", body: nil, contentType: "application/json", maxBytes: 1024) |
| + XCTAssertEqual(count.value, 2, "403 is a refusal of the request, not of the session") |
| + do { |
| + try await watch.stream("/d/x/stream", onOpen: {}, onLine: { _ in }) |
| + XCTFail("a refused stream throws") |
| + } catch NativeClientError.unauthorized {} |
| + XCTAssertEqual(count.value, 3) |
| + } |
| + |
| + // MARK: Review round (Fable, d143194) |
| + |
| + func testIdentityAndTeamThatAreNotPathSafeAreEncoded() { |
| + let odd = DocsOficinaSession.accountID(identity: "a/b", team: "c.d") |
| + XCTAssertFalse(odd.contains("/")) |
| + XCTAssertEqual(odd.split(separator: ".").count, 3, "prefix, identity, team: no stray dots") |
| + XCTAssertTrue(DocsOficinaSession.account(odd, belongsTo: "a/b")) |
| + XCTAssertFalse(DocsOficinaSession.account(odd, belongsTo: "a")) |
| + XCTAssertNotEqual(DocsOficinaSession.accountID(identity: "a", team: "b"), DocsOficinaSession.accountID(identity: "~a", team: "b")) |
| + XCTAssertEqual(DocsOficinaSession.accountID(identity: "Ab_9-z", team: "t1"), "oficina-id.Ab_9-z.t1", "safe parts stay readable") |
| + XCTAssertTrue(DocsOficinaSession.isOficinaAccount(odd)) |
| + XCTAssertFalse(DocsOficinaSession.isOficinaAccount(UUID().uuidString)) |
| + } |
| + |
| + func testReplacingTheIdentityPurgesItsSessions() async throws { |
| + onePaulTeam() |
| + onePaulTeam("id-till", email: "till@lagged.io") |
| + let docs = session() |
| + await signIn(docs) |
| + let paul = DocsOficinaSession.accountID(try XCTUnwrap(docs.signedIn)) |
| + docs.model.useAnother() |
| + XCTAssertTrue(docs.model.confirmingReplace) |
| + docs.model.confirmReplace() |
| + XCTAssertNil(docs.transport(for: paul)(), "the replaced identity's workspaces get no session") |
| + XCTAssertNil(docs.mounted) |
| + await signIn(docs, email: "till@lagged.io") |
| + let till = DocsOficinaSession.accountID(try XCTUnwrap(docs.signedIn)) |
| + XCTAssertNotEqual(till, paul) |
| + XCTAssertNotNil(docs.transport(for: till)()) |
| + XCTAssertNil(docs.transport(for: paul)(), "and never comes back") |
| + } |
| + |
| + func testAReMintRestartsAnOutboxStoppedByTheEndedSession() async throws { |
| + onePaulTeam() |
| + let docs = session() |
| + await signIn(docs) |
| + let account = DocsOficinaSession.accountID(try XCTUnwrap(docs.signedIn)) |
| + var supplied: NativeTransport? = nil |
| + let offline = DocsOfflineAccount(store: EphemeralDocsStore(), accountID: account, |
| + connectivity: NativeConnectivity(source: ScriptedPathSource(.satisfied)), |
| + transport: { supplied }) |
| + DocsOfflineAccount.accounts[account] = offline |
| + defer { DocsOfflineAccount.accounts[account] = nil } |
| + try await offline.outbox.enqueue(lane: "doc:k", kind: "update", payload: Data([1])) |
| + let stopped = await offline.drainer.drain() |
| + XCTAssertEqual(stopped, .sessionEnded) |
| + XCTAssertTrue(offline.drainer.sessionEnded) |
| + supplied = docs.transport(for: account)() |
| + await docs.rejected(account) |
| + XCTAssertFalse(offline.drainer.sessionEnded, "the new session restarts the stopped outbox") |
| + } |
| + |
| + func testA401WithHomeDownKeepsTheWorkspaceMounted() async throws { |
| + onePaulTeam() |
| + let docs = session() |
| + await signIn(docs) |
| + let first = try XCTUnwrap(docs.signedIn) |
| + let account = DocsOficinaSession.accountID(first) |
| + service.expire(session: first.session) |
| + service.failNext("assert", with: .offline) |
| + await docs.rejected(account) |
| + guard case .unavailable = docs.model.step else { return XCTFail("Home down: \(docs.model.step)") } |
| + XCTAssertEqual(docs.mounted, first, "the open workspace stays, under the Can't reach line") |
| + XCTAssertNotNil(docs.transport(for: account)()) |
| + await docs.model.retry() |
| + let second = try XCTUnwrap(docs.signedIn) |
| + XCTAssertEqual(docs.mounted, second) |
| + XCTAssertNotEqual(second.session.value, first.session.value) |
| + XCTAssertEqual(docs.client(for: account)?.credential?.value, second.session.value) |
| + } |
| + |
| + func testOnlyASignInMadeHereCountsNotARestore() async throws { |
| + onePaulTeam() |
| + let device = device() |
| + let first = session(on: device) |
| + await signIn(first) |
| + XCTAssertNotNil(first.signedIn) |
| + XCTAssertEqual(first.signIns, 1) |
| + // Docs launched again: the team comes back with no sign-in. |
| + let again = session(on: device) |
| + await again.start() |
| + XCTAssertNotNil(again.signedIn) |
| + XCTAssertEqual(again.signIns, 0, "a restored identity must not change the route someone chose") |
| + } |
| + |
| + func testRenewAfterADayGoesThroughTheSession() async throws { |
| + onePaulTeam() |
| + let docs = session() |
| + await signIn(docs) |
| + let first = try XCTUnwrap(docs.signedIn) |
| + let account = DocsOficinaSession.accountID(first) |
| + await docs.renewIfNeeded() |
| + XCTAssertEqual(exchanges(at: paulca), 1, "a fresh session is kept") |
| + clock.date.addTimeInterval(25 * 3600) |
| + await docs.renewIfNeeded() |
| + XCTAssertEqual(exchanges(at: paulca), 2) |
| + let renewed = try XCTUnwrap(docs.signedIn) |
| + XCTAssertNotEqual(renewed.session.value, first.session.value) |
| + XCTAssertEqual(docs.client(for: account)?.credential?.value, renewed.session.value) |
| + } |
| + |
| + func testTeamsRefreshAtLaunchOnTheMenuAndOnA403() async throws { |
| + onePaulTeam() |
| + let device = device() |
| + await signIn(session(on: device)) |
| + let titoTeam = team("t2", "Tito", "tito") |
| + service.setTeams([team("t1", "Paul", "paulca"), titoTeam], for: "id-paul") |
| + let teamsCalls = { self.service.calls.filter { $0 == "teams" }.count } |
| + clock.date.addTimeInterval(301) |
| + let docs = session(on: device) |
| + await docs.start() |
| + XCTAssertEqual(docs.model.store.teams("id-paul")?.teams.map(\.sqid), ["t1", "t2"], "launch refreshes") |
| + let afterLaunch = teamsCalls() |
| + await docs.pickerOpened() |
| + XCTAssertEqual(teamsCalls(), afterLaunch, "the menu waits five minutes") |
| + service.setTeams([team("t1", "Paul", "paulca")], for: "id-paul") |
| + await docs.refused() |
| + XCTAssertEqual(docs.model.store.teams("id-paul")?.teams.map(\.sqid), ["t1"], "a 403 refreshes at once") |
| + await docs.refused() |
| + XCTAssertEqual(teamsCalls(), afterLaunch + 1, "at most once a minute") |
| + clock.date.addTimeInterval(301) |
| + await docs.pickerOpened() |
| + XCTAssertEqual(teamsCalls(), afterLaunch + 2) |
| + } |
| + |
| + func testTheWatchReports403sAsRefusals() async throws { |
| + final class Count: @unchecked Sendable { var rejected = 0, refused = 0 } |
| + let count = Count() |
| + let watch = DocsSessionWatch(inner: ScriptedTransport([.respond(status: 403), .respond(status: 200)]), |
| + rejected: { count.rejected += 1 }, refused: { count.refused += 1 }) |
| + _ = try await watch.responseDetails("/", method: "GET", body: nil, contentType: "application/json", maxBytes: 1024) |
| + _ = try await watch.responseDetails("/", method: "GET", body: nil, contentType: "application/json", maxBytes: 1024) |
| + XCTAssertEqual(count.refused, 1) |
| + XCTAssertEqual(count.rejected, 0) |
| + } |
| + |
| + func testSharingExportImagesAndJumpUseTheCurrentSession() async throws { |
| + onePaulTeam() |
| + let docs = session() |
| + await signIn(docs) |
| + let first = try XCTUnwrap(docs.signedIn) |
| + let account = DocsOficinaSession.accountID(first) |
| + let opened = first.client() |
| + service.expire(session: first.session) |
| + await docs.rejected(account) |
| + let renewed = try XCTUnwrap(docs.signedIn) |
| + let live = DocsWorkspace.liveClient(docs.transport(for: account), fallback: opened) |
| + let watched = try XCTUnwrap(live as? DocsSessionWatch, "watched for 401s") |
| + XCTAssertEqual((watched.inner as? NativeHTTP)?.credential?.value, renewed.session.value) |
| + // A window without a supplier (a server account's) keeps its client. |
| + XCTAssertTrue(DocsWorkspace.liveClient(nil, fallback: opened) as AnyObject === opened) |
| + } |
| + |
| + // MARK: The store key outlives an origin change |
| + |
| + /// A keychain in memory, one item per KeychainKeyProvider account. |
| + final class MemoryKeychain: @unchecked Sendable { |
| + let lock = NSLock() |
| + var items: [String: StoreKeyState] = [:] |
| + struct Keys: KeyProvider { |
| + let chain: MemoryKeychain, account: String |
| + func copyKey() -> (OSStatus, SymmetricKey?) { |
| + chain.lock.withLock { chain.items[account].map { (errSecSuccess, SymmetricKey(data: $0.current)) } ?? (errSecItemNotFound, nil) } |
| + } |
| + func addKey(_ key: SymmetricKey) -> OSStatus { |
| + chain.lock.withLock { |
| + guard chain.items[account] == nil else { return errSecDuplicateItem } |
| + chain.items[account] = StoreKeyState(current: key.withUnsafeBytes { Data($0) }); return errSecSuccess |
| + } |
| + } |
| + func deleteKey() -> OSStatus { chain.lock.withLock { chain.items[account] = nil }; return errSecSuccess } |
| + func sealState() -> (OSStatus, StoreKeyState?) { |
| + chain.lock.withLock { chain.items[account].map { (errSecSuccess, $0) } ?? (errSecItemNotFound, nil) } |
| + } |
| + func saveSealState(_ state: StoreKeyState) -> OSStatus { chain.lock.withLock { chain.items[account] = state }; return errSecSuccess } |
| + } |
| + func keys(_ account: String, origin: URL) -> Keys { Keys(chain: self, account: DocsOfflineAccount.keys(accountID: account, origin: origin).account) } |
| + } |
| + |
| + func testAnOficinaTeamsStoreAndOutboxSurviveAnOriginChange() async throws { |
| + let root = FileManager.default.temporaryDirectory.appendingPathComponent("docs-origin-\(UUID().uuidString)") |
| + defer { try? FileManager.default.removeItem(at: root) } |
| + let chain = MemoryKeychain() |
| + let account = DocsOficinaSession.accountID(identity: "id-paul", team: "t1") |
| + let old = URL(string: "https://paul.docs.oficina.works")!, moved = URL(string: "https://paulca.docs.oficina.works")! |
| + let before = Outbox(store: NativeSealedStore(root: root, accountID: account, keys: chain.keys(account, origin: old)), account: account) |
| + try await before.enqueue(lane: "doc:k", kind: "update", payload: Data([7])) |
| + let after = Outbox(store: NativeSealedStore(root: root, accountID: account, keys: chain.keys(account, origin: moved)), account: account) |
| + try await after.load() |
| + let kept = await after.entries(lane: "doc:k", excludingInFlight: false) |
| + XCTAssertEqual(kept.map(\.payload), [Data([7])], "the label moved; the unsent change did not go with it") |
| + // A server account is its host: a new origin is a new account. |
| + let server = UUID().uuidString |
| + XCTAssertNotEqual(DocsOfflineAccount.keys(accountID: server, origin: old).account, |
| + DocsOfflineAccount.keys(accountID: server, origin: moved).account) |
| + } |
| + |
| + func testUnsentChangesLeftOnDiskBlockSigningOutOfThatIdentity() async throws { |
| + let root = FileManager.default.temporaryDirectory.appendingPathComponent("docs-unsent-\(UUID().uuidString)") |
| + defer { try? FileManager.default.removeItem(at: root) } |
| + let chain = MemoryKeychain() |
| + let account = DocsOficinaSession.accountID(identity: "id-paul", team: "t2") |
| + let keys: (String) -> KeyProvider = { chain.keys($0, origin: DocsOfflineAccount.oficinaKeyOrigin) } |
| + // An outbox a crash left behind, for a team not opened this run. |
| + let left = Outbox(store: NativeSealedStore(root: root.appendingPathComponent(account), accountID: account, keys: keys(account)), account: account) |
| + try await left.enqueue(lane: "doc:k", kind: "update", payload: Data([1])) |
| + let paul = await DocsOfflineAccount.hasUnsent(identity: "id-paul", root: root, keys: keys) |
| + let till = await DocsOfflineAccount.hasUnsent(identity: "id-till", root: root, keys: keys) |
| + XCTAssertTrue(paul) |
| + XCTAssertFalse(till) |
| + // Once sent, nothing blocks. |
| + let entries = await left.entries(lane: "doc:k", excludingInFlight: false) |
| + try await left.ack(entries.map(\.id)) |
| + let sent = await DocsOfflineAccount.hasUnsent(identity: "id-paul", root: root, keys: keys) |
| + XCTAssertFalse(sent) |
| + } |
| + |
| + func testTheLeaveGuardOrdersOpenDocumentsFirst() async { |
| + let open = await DocsLeaveBlock.check(identity: "id-nobody", openDocuments: true, unsentHere: true) |
| + XCTAssertEqual(open, .openDocuments) |
| + let unsent = await DocsLeaveBlock.check(identity: "id-nobody", openDocuments: false, unsentHere: true) |
| + XCTAssertEqual(unsent, .sending) |
| + XCTAssertFalse(DocsLeaveBlock.sending.message.isEmpty) |
| + XCTAssertNotEqual(DocsLeaveBlock.sending.message, "native.leave.sending", "the line is translated, not a key") |
| + } |
| + |
| + #if os(macOS) |
| + func testTheLaunchCheckFailsWithoutTheEntitlements() { |
| + // The test runner is not signed with Docs' entitlements: every check |
| + // that needs them must say FAIL, or the gate could not catch a build |
| + // that lost them. |
| + let result = DocsOficinaLaunchCheck.run() |
| + XCTAssertFalse(result.passed) |
| + for name in ["keychain-access-groups", "shared group", "Docs' group", "App Group", "associated domains"] { |
| + XCTAssertTrue(result.lines.contains { $0.hasPrefix("FAIL \(name)") }, "\(name): \(result.lines)") |
| + } |
| + } |
| + #endif |
| +} |
diff --git a/native/apple/Tests/DocsSnapshots/DocsSnapshots.swift b/native/apple/Tests/DocsSnapshots/DocsSnapshots.swift| new file mode 100644 |
| index 0000000..fb7faf1 |
| --- /dev/null |
| +++ b/native/apple/Tests/DocsSnapshots/DocsSnapshots.swift |
| @@ -0,0 +1,163 @@ |
| +import DocsKit |
| +import Foundation |
| +import RastrilloApple |
| +import RastrilloSnapshots |
| +import RastrilloTestSupport |
| +import SwiftUI |
| +import XCTest |
| + |
| +/// Docs' key screens for the screenshot gate (rastrillo/native |
| +/// RastrilloSnapshots): the library, Oficina ID onboarding as Docs shows it, |
| +/// Other ways to sign in, the team picker and, on the Mac, Settings. Drawn |
| +/// from fixtures with no server, keychain, App Group or network, in light and |
| +/// dark, and on iPhone at the default size and AX3. |
| +/// |
| +/// `native/scripts/snapshots.sh` runs it (compare, or record); `swift test` |
| +/// alone skips it, because baselines match only the OS that drew them. The |
| +/// Mac half runs from `swift test`; the iPhone half is the same file in the |
| +/// `DocsPhoneSnapshots` target of `ios/project.yml`. |
| +/// |
| +/// The editor is not here: its text views draw, but a document's first |
| +/// layout can finish after the gate's settle window, and anything in a web |
| +/// view or Metal layer draws blank. Bundled faces are registered first, or |
| +/// the baselines would record fallback faces. |
| +final class DocsSnapshots: XCTestCase { |
| + @MainActor func testKeyScreens() async throws { |
| + try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, |
| + "Run with native/scripts/snapshots.sh") |
| + DocsFonts.register() |
| + let fixtures = await Fixtures.make() |
| + await assertSnapshots(of: Self.catalog(fixtures)) |
| + } |
| + |
| + @MainActor static func catalog(_ fixtures: Fixtures) -> SnapshotCatalog { |
| + var screens: [SnapshotScreen] = [ |
| + SnapshotScreen("library", mac: .fixed(width: 1000, height: 700), iphone: .fixed(width: 402, height: 874)) { |
| + Fixtures.library(["Quarterly plan", "Meeting notes, 12 January", "Letter to the landlord", "Recipes"]) |
| + }, |
| + SnapshotScreen("library-empty", mac: .fixed(width: 1000, height: 700), iphone: .fixed(width: 402, height: 874)) { |
| + Fixtures.library([]) |
| + }, |
| + SnapshotScreen("onboarding-welcome") { |
| + OficinaOnboardingView(model: fixtures.welcome, otherWays: {}) |
| + }, |
| + SnapshotScreen("onboarding-code") { |
| + OficinaOnboardingView(model: fixtures.code, otherWays: {}) |
| + }, |
| + SnapshotScreen("onboarding-teams") { |
| + OficinaOnboardingView(model: fixtures.teams, otherWays: {}) |
| + }, |
| + SnapshotScreen("other-ways", mac: .fixed(width: 520, height: 480), iphone: .fixed(width: 402, height: 640)) { |
| + DocsOtherWaysView(connection: Fixtures.connection()) {} |
| + }, |
| + SnapshotScreen("team-picker", mac: .fixed(width: 460, height: 540), iphone: .fixed(width: 402, height: 720)) { |
| + DocsTeamPicker(model: fixtures.signedIn, current: fixtures.signedInState, |
| + otherWays: {}, signOut: {}, done: {}) |
| + }, |
| + SnapshotScreen("team-picker-blocked", mac: .fixed(width: 460, height: 540), iphone: .fixed(width: 402, height: 720)) { |
| + // Open documents or unsent changes: the switch and sign-out |
| + // are disabled, and the line says why. |
| + DocsTeamPicker(model: fixtures.signedIn, current: fixtures.signedInState, leaveCheck: { .sending }, |
| + otherWays: {}, signOut: {}, done: {}) |
| + }, |
| + ] |
| + #if os(macOS) |
| + screens.append(SnapshotScreen("settings", mac: .width(480), iphone: nil) { |
| + DocsSettingsView(account: .oficinaID(identity: "paul@tito.io", team: "Paul", teamLabel: "paulca"), block: nil, |
| + version: "0.1.0 (1)", manage: {}, signOut: {}, signIn: {}) |
| + }) |
| + screens.append(SnapshotScreen("settings-blocked", mac: .width(480), iphone: nil) { |
| + DocsSettingsView(account: .oficinaID(identity: "paul@tito.io", team: "Paul", teamLabel: "paulca"), block: .openDocuments, |
| + version: "0.1.0 (1)", manage: {}, signOut: {}, signIn: {}) |
| + }) |
| + screens.append(SnapshotScreen("settings-server", mac: .width(480), iphone: nil) { |
| + DocsSettingsView(account: .server(name: "Tito", host: "tito.docs.oficina.works"), block: nil, |
| + version: "0.1.0 (1)", manage: {}, signOut: {}, signIn: {}) |
| + }) |
| + #endif |
| + return SnapshotCatalog(app: "docs", settings: SnapshotSettings(tint: OficinaPalette.accent(.docs)), screens: screens) |
| + } |
| +} |
| + |
| +/// Oficina ID models walked to each step through the kit's in-memory Home, |
| +/// directory and instances, exactly as a person would get there: nothing |
| +/// touches the keychain, an App Group or the network. |
| +@MainActor final class Fixtures { |
| + static let origin = URL(string: "https://docs.snapshot.invalid")! |
| + let welcome: OficinaIDModel |
| + let code: OficinaIDModel |
| + let teams: OficinaIDModel |
| + let signedIn: OficinaIDModel |
| + let signedInState: OficinaSignedIn |
| + |
| + private init(welcome: OficinaIDModel, code: OficinaIDModel, teams: OficinaIDModel, signedIn: OficinaIDModel, state: OficinaSignedIn) { |
| + self.welcome = welcome; self.code = code; self.teams = teams; self.signedIn = signedIn; signedInState = state |
| + } |
| + |
| + static func make() async -> Fixtures { |
| + let welcome = model(), code = model(), teams = model(), signedIn = model() |
| + await welcome.start() |
| + await walk(code, to: 1) |
| + await walk(teams, to: 2) |
| + await walk(signedIn, to: 2) |
| + if case .teams(let list) = signedIn.step, let first = list.first { await signedIn.choose(first) } |
| + guard case .signedIn(let state) = signedIn.step else { preconditionFailure("fixture did not sign in: \(signedIn.step)") } |
| + return Fixtures(welcome: welcome, code: code, teams: teams, signedIn: signedIn, state: state) |
| + } |
| + |
| + private static func team(_ sqid: String, _ name: String, _ label: String) -> OficinaTeam { |
| + OficinaTeam(sqid: sqid, label: label, name: name, role: "member", |
| + apps: [OficinaTeamApp(app: "docs", origin: "https://\(label).docs.oficina.works", consumerID: "\(sqid)-docs")]) |
| + } |
| + |
| + private static func model() -> OficinaIDModel { |
| + let service = FakeOficinaIDService() |
| + service.addPerson(email: "paul@tito.io", identityID: "id-paul") |
| + let teams = [team("t1", "Paul", "paulca"), team("t2", "Tito", "tito"), team("t3", "Campbells", "campbells")] |
| + service.setTeams(teams, for: "id-paul") |
| + for team in teams { service.admit("id-paul", at: team.origin(for: "docs")!, as: .linked) } |
| + let suite = "DocsSnapshots.\(UUID().uuidString)" |
| + let defaults = UserDefaults(suiteName: suite)! |
| + defaults.removePersistentDomain(forName: suite) |
| + let store = OficinaIDStore(shared: OficinaMemoryStore(), appPrivate: OficinaMemoryStore(), group: defaults) |
| + return OficinaIDModel(configuration: DocsOficinaSession.configuration, store: store, service: service, |
| + passkeys: FakePasskeys(), makeKey: { OficinaSoftwareKey() }, |
| + now: { SnapshotSettings.now }, appDefaults: defaults) |
| + } |
| + |
| + /// 1: the code step. 2: the team step, after the code. |
| + private static func walk(_ model: OficinaIDModel, to stage: Int) async { |
| + await model.start() |
| + model.continueWithEmail() |
| + model.email = "paul@tito.io" |
| + await model.submitEmail() |
| + guard stage > 1 else { return } |
| + model.code = FakeOficinaIDService.goodCode |
| + await model.submitCode() |
| + } |
| + |
| + /// A workspace whose server answers the document list and nothing else. |
| + static func library(_ titles: [String]) -> some View { |
| + let documents = titles.enumerated().map { #"{"sqid":"d\#($0.offset)","title":"\#($0.element)","shared":\#($0.offset == 1)}"# } |
| + let list = Data(#"{"documents":[\#(documents.joined(separator: ","))],"can_create":true}"#.utf8) |
| + let server = ScriptedTransport(origin: origin) { call in |
| + call.path.hasPrefix("/?") ? .respond(status: 200, body: list) : .respond(status: 404) |
| + } |
| + return DocsWorkspace(client: NativeHTTP(origin: origin), transport: { server }, accounts: {}, signOut: {}, |
| + accountsLabel: DocsOficinaSession.teamsTitle, |
| + signOutLabel: OficinaIDText.text("signOut", "paul@tito.io")) |
| + } |
| + |
| + /// A connection on a throwaway defaults suite and an origin no app holds |
| + /// a credential for, so `NativeConnection.init`'s legacy-credential |
| + /// migration can never find (and move) a real item. |
| + static func connection() -> NativeConnection { |
| + let suite = "DocsSnapshots.connection.\(UUID().uuidString)" |
| + let defaults = UserDefaults(suiteName: suite)! |
| + defaults.removePersistentDomain(forName: suite) |
| + let connection = NativeConnection(defaultServer: origin.absoluteString, defaults: defaults, |
| + connectivity: NativeConnectivity(source: ScriptedPathSource(.satisfied))) |
| + connection.serverAddress = "https://docs.oficina.works" |
| + return connection |
| + } |
| +} |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/ENVIRONMENT b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/ENVIRONMENT| new file mode 100644 |
| index 0000000..a26fa8a |
| --- /dev/null |
| +++ b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/ENVIRONMENT |
| @@ -0,0 +1,10 @@ |
| +os: iOS 27.0.0 |
| +device: iPhone19,2 |
| +runtime: 27.0 (24A434) |
| +toolchain: Xcode 27.2 Build version 27B52 |
| +language: en |
| +locale: en_IE |
| +time zone: Europe/Dublin |
| +increase contrast: off |
| +reduce transparency: off |
| +differentiate without colour: off |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-ax3.png| new file mode 100644 |
| index 0000000..6d1943d |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-default.png| new file mode 100644 |
| index 0000000..f0b9b48 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-ax3.png| new file mode 100644 |
| index 0000000..20c9b2a |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-default.png| new file mode 100644 |
| index 0000000..7cc8983 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-ax3.png| new file mode 100644 |
| index 0000000..5c32d09 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-default.png| new file mode 100644 |
| index 0000000..3ce3331 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-empty-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-ax3.png| new file mode 100644 |
| index 0000000..4abd4c0 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-default.png| new file mode 100644 |
| index 0000000..c39ecbf |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/library-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-ax3.png| new file mode 100644 |
| index 0000000..1cb4ce1 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-default.png| new file mode 100644 |
| index 0000000..d5cd968 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-ax3.png| new file mode 100644 |
| index 0000000..6e9cf0d |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-default.png| new file mode 100644 |
| index 0000000..cee69c2 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-code-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-ax3.png| new file mode 100644 |
| index 0000000..002c1f2 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-default.png| new file mode 100644 |
| index 0000000..aef162c |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-ax3.png| new file mode 100644 |
| index 0000000..4c91781 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-default.png| new file mode 100644 |
| index 0000000..232ea0b |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-teams-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-ax3.png| new file mode 100644 |
| index 0000000..f948105 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-default.png| new file mode 100644 |
| index 0000000..7e5f01c |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-ax3.png| new file mode 100644 |
| index 0000000..5f171de |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-default.png| new file mode 100644 |
| index 0000000..32b1526 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/onboarding-welcome-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-ax3.png| new file mode 100644 |
| index 0000000..891dc9f |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-default.png| new file mode 100644 |
| index 0000000..eab8681 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-ax3.png| new file mode 100644 |
| index 0000000..3d9cdd9 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-default.png| new file mode 100644 |
| index 0000000..8c873bf |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/other-ways-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-ax3.png| new file mode 100644 |
| index 0000000..aaea719 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-default.png| new file mode 100644 |
| index 0000000..f969c48 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-ax3.png| new file mode 100644 |
| index 0000000..a5bb676 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-default.png| new file mode 100644 |
| index 0000000..26c453c |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-blocked-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-ax3.png| new file mode 100644 |
| index 0000000..27c9d20 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-default.png| new file mode 100644 |
| index 0000000..b254f82 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-ax3.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-ax3.png| new file mode 100644 |
| index 0000000..05d5c28 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-ax3.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-default.png| new file mode 100644 |
| index 0000000..9452f3f |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/iphone/team-picker-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/ENVIRONMENT b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/ENVIRONMENT| new file mode 100644 |
| index 0000000..2a04923 |
| --- /dev/null |
| +++ b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/ENVIRONMENT |
| @@ -0,0 +1,9 @@ |
| +os: macOS 27.0.0 |
| +toolchain: Xcode 27.2 Build version 27B52 |
| +language: en |
| +accent: #007AFF |
| +locale: en_IE |
| +time zone: Europe/Dublin |
| +increase contrast: off |
| +reduce transparency: off |
| +differentiate without colour: off |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-dark-default.png| new file mode 100644 |
| index 0000000..9721ca5 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-dark-default.png| new file mode 100644 |
| index 0000000..c841feb |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-light-default.png| new file mode 100644 |
| index 0000000..8c50567 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-empty-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-light-default.png| new file mode 100644 |
| index 0000000..488cbc5 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/library-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-dark-default.png| new file mode 100644 |
| index 0000000..42aeeb6 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-light-default.png| new file mode 100644 |
| index 0000000..ec63cda |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-code-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-dark-default.png| new file mode 100644 |
| index 0000000..1ccf6c3 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-light-default.png| new file mode 100644 |
| index 0000000..75c234c |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-teams-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-dark-default.png| new file mode 100644 |
| index 0000000..850fb10 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-light-default.png| new file mode 100644 |
| index 0000000..045e0a6 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/onboarding-welcome-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-dark-default.png| new file mode 100644 |
| index 0000000..33b0348 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-light-default.png| new file mode 100644 |
| index 0000000..e4fd9b7 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/other-ways-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-dark-default.png| new file mode 100644 |
| index 0000000..58b8aea |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-light-default.png| new file mode 100644 |
| index 0000000..5c9f3ee |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-blocked-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-dark-default.png| new file mode 100644 |
| index 0000000..45f6738 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-light-default.png| new file mode 100644 |
| index 0000000..029edcd |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-dark-default.png| new file mode 100644 |
| index 0000000..d165987 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-light-default.png| new file mode 100644 |
| index 0000000..741a780 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/settings-server-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-dark-default.png| new file mode 100644 |
| index 0000000..a178569 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-light-default.png| new file mode 100644 |
| index 0000000..20aef82 |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-blocked-light-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-dark-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-dark-default.png| new file mode 100644 |
| index 0000000..0c78fbd |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-dark-default.png differ |
diff --git a/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-light-default.png b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-light-default.png| new file mode 100644 |
| index 0000000..3859d7c |
| Binary files /dev/null and b/native/apple/Tests/DocsSnapshots/__Snapshots__/docs/mac/team-picker-light-default.png differ |
diff --git a/native/apple/Tests/DocsWindowTests/WindowRoutingTests.swift b/native/apple/Tests/DocsWindowTests/WindowRoutingTests.swift| index e81c94a..5a8a74b 100644 |
| --- a/native/apple/Tests/DocsWindowTests/WindowRoutingTests.swift |
| +++ b/native/apple/Tests/DocsWindowTests/WindowRoutingTests.swift |
| @@ -2,6 +2,7 @@ |
| import Foundation |
| import Testing |
| import RastrilloApple |
| +import DocsKit |
| @testable import DocsMac |
| @MainActor @Test func windowsReuseDocumentsWithinAccountAndOriginOnly() { |
| @@ -42,3 +43,28 @@ import RastrilloApple |
| #expect(windows.canSignOut("a")) |
| } |
| #endif |
| +#if os(macOS) |
| +/// Signing out of an Oficina ID ends every one of its teams, so any open |
| +/// document window of any of them blocks it, and Settings asks the same. |
| +@MainActor @Test func oficinaIDSignOutIsBlockedByAnyOfItsTeamsOpenWindows() async { |
| + let windows = DocsWindows() |
| + let client = NativeHTTP(origin: URL(string: "https://tito.docs.oficina.works")!) |
| + let tito = DocsOficinaSession.accountID(identity: "id-paul", team: "t2") |
| + let paul = DocsOficinaSession.accountID(identity: "id-paul", team: "t1") |
| + let id = windows.reserve(account: tito, document: "d", title: "Plan", client: client) |
| + windows.activeAccount = paul |
| + windows.settingsIdentity = "id-paul" |
| + #expect(windows.canSignOut(paul), "the home team's own windows are none") |
| + #expect(windows.hasOpenDocuments(identity: "id-paul"), "but another team of the identity has one") |
| + #expect(!windows.hasOpenDocuments(identity: "id-till")) |
| + #expect(await windows.leaveBlock() == .openDocuments) |
| + windows.setOpen(id, false) |
| + #expect(!windows.hasOpenDocuments(identity: "id-paul")) |
| + // A server account: its own windows only. |
| + windows.settingsIdentity = nil |
| + let server = UUID().uuidString |
| + windows.activeAccount = server |
| + _ = windows.reserve(account: server, document: "e", title: "Notes", client: client) |
| + #expect(await windows.leaveBlock() == .openDocuments) |
| +} |
| +#endif |
diff --git a/native/ios/DocsPhone.entitlements b/native/ios/DocsPhone.entitlements| new file mode 100644 |
| index 0000000..830da33 |
| --- /dev/null |
| +++ b/native/ios/DocsPhone.entitlements |
| @@ -0,0 +1,23 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| +<plist version="1.0"> |
| +<dict> |
| + <key>com.apple.developer.associated-domains</key> |
| + <array> |
| + <string>webcredentials:id.oficina.works</string> |
| + </array> |
| + <key>com.apple.security.application-groups</key> |
| + <array> |
| + <string>group.works.oficina</string> |
| + </array> |
| + <!-- Docs' own group FIRST: a keychain query that names no group lands in |
| + the first one, and Docs' sessions and offline keys must never land in |
| + the group every Oficina app reads (rastrillo/native APPLE.md, |
| + "Oficina ID, slice A"). The second is the shared Oficina ID group. --> |
| + <key>keychain-access-groups</key> |
| + <array> |
| + <string>9U4A84C4WK.works.oficina.docs</string> |
| + <string>9U4A84C4WK.works.oficina.id</string> |
| + </array> |
| +</dict> |
| +</plist> |
diff --git a/native/ios/Info.plist b/native/ios/Info.plist| index bdaf0f0..dc07ff2 100644 |
| --- a/native/ios/Info.plist |
| +++ b/native/ios/Info.plist |
| @@ -10,6 +10,21 @@ |
| <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> |
| <key>CFBundleInfoDictionaryVersion</key> |
| <string>6.0</string> |
| + <key>CFBundleLocalizations</key> |
| + <array> |
| + <string>en</string> |
| + <string>ar</string> |
| + <string>bn</string> |
| + <string>es</string> |
| + <string>ga</string> |
| + <string>hi</string> |
| + <string>ja</string> |
| + <string>pt</string> |
| + <string>ru</string> |
| + <string>vi</string> |
| + <string>yue</string> |
| + <string>zh-Hans</string> |
| + </array> |
| <key>CFBundleName</key> |
| <string>$(PRODUCT_NAME)</string> |
| <key>CFBundlePackageType</key> |
diff --git a/native/ios/project.yml b/native/ios/project.yml| index acb2455..ee5dea5 100644 |
| --- a/native/ios/project.yml |
| +++ b/native/ios/project.yml |
| @@ -8,7 +8,7 @@ packages: |
| path: ../apple |
| RastrilloNative: |
| url: https://amadan.net/rastrillo/native |
| - revision: b6a4067e39efd641fd5fa149cc666fee47bdb9b5 |
| + revision: f1c7a14db2ddb8960afabc8268cd92c490543397 |
| settings: |
| base: |
| SWIFT_VERSION: '6.0' |
| @@ -34,6 +34,10 @@ targets: |
| ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon |
| PROVISIONING_PROFILE_SPECIFIER: $(OFICINA_PROVISIONING_PROFILE) |
| PRODUCT_BUNDLE_IDENTIFIER: works.oficina.docs |
| + # Oficina ID (rastrillo/native APPLE.md, "Oficina ID, slice A"): Docs' |
| + # own keychain group first, then the shared one; group.works.oficina; |
| + # webcredentials:id.oficina.works for passkeys. |
| + CODE_SIGN_ENTITLEMENTS: DocsPhone.entitlements |
| TARGETED_DEVICE_FAMILY: 1,2 |
| GENERATE_INFOPLIST_FILE: true |
| INFOPLIST_KEY_CFBundleDisplayName: Oficina Docs |
| @@ -48,6 +52,21 @@ targets: |
| CFBundleTypeRole: Editor |
| CFBundleShortVersionString: $(MARKETING_VERSION) |
| CFBundleVersion: $(CURRENT_PROJECT_VERSION) |
| + # The twelve languages Docs ships. Without the key every resource |
| + # bundle (DocsKit's, RastrilloApple's) reads English. |
| + CFBundleLocalizations: |
| + - en |
| + - ar |
| + - bn |
| + - es |
| + - ga |
| + - hi |
| + - ja |
| + - pt |
| + - ru |
| + - vi |
| + - yue |
| + - zh-Hans |
| DocsReviewPhone: |
| type: application |
| platform: iOS |
| @@ -75,7 +94,36 @@ targets: |
| base: |
| GENERATE_INFOPLIST_FILE: true |
| TEST_TARGET_NAME: DocsReviewPhone |
| + # The screenshot gate's iPhone half: the Mac half's catalog file, run as a |
| + # logic test in the simulator by native/scripts/snapshots.sh. |
| + DocsPhoneSnapshots: |
| + type: bundle.unit-test |
| + platform: iOS |
| + sources: |
| + - path: ../apple/Tests/DocsSnapshots |
| + excludes: |
| + - __Snapshots__ |
| + dependencies: |
| + - package: DocsNative |
| + product: DocsKit |
| + - package: RastrilloNative |
| + product: RastrilloApple |
| + - package: RastrilloNative |
| + product: RastrilloSnapshots |
| + - package: RastrilloNative |
| + product: RastrilloTestSupport |
| + settings: |
| + base: |
| + GENERATE_INFOPLIST_FILE: true |
| + PRODUCT_BUNDLE_IDENTIFIER: works.oficina.docs.snapshots |
| schemes: |
| + DocsPhoneSnapshots: |
| + build: |
| + targets: |
| + DocsPhoneSnapshots: [test] |
| + test: |
| + targets: |
| + - DocsPhoneSnapshots |
| DocsReviewPhone: |
| build: |
| targets: |
diff --git a/native/mac-updates.json b/native/mac-updates.json| index bf454d5..ac2de30 100644 |
| --- a/native/mac-updates.json |
| +++ b/native/mac-updates.json |
| @@ -1,8 +1,25 @@ |
| { |
| "bundle_id": "works.oficina.docs", |
| + "install": "automatic", |
| "url_schemes": [ |
| "works.oficina.docs" |
| ], |
| + "localizations": [ |
| + "en", |
| + "ar", |
| + "bn", |
| + "es", |
| + "ga", |
| + "hi", |
| + "ja", |
| + "pt", |
| + "ru", |
| + "vi", |
| + "yue", |
| + "zh-Hans" |
| + ], |
| + "entitlements": "macos/DeveloperID.entitlements", |
| + "provisioning_profile": "~/private_keys/oficina/profiles/Oficina-Docs-macOS-Developer-ID.provisionprofile", |
| "feed_url": "https://raw.amadan.net/oficina/native-releases/main/docs/appcast.xml", |
| "public_ed_key": "/FxO7cZnM7P5c9ZrUPUJvpCnR65sNmrzte+I5vHarE8=", |
| "keychain_account": "oficina" |
diff --git a/native/macos/AppStore.entitlements b/native/macos/AppStore.entitlements| index a046386..313f1a9 100644 |
| --- a/native/macos/AppStore.entitlements |
| +++ b/native/macos/AppStore.entitlements |
| @@ -8,5 +8,22 @@ |
| <true/> |
| <key>com.apple.security.network.client</key> |
| <true/> |
| + <key>com.apple.developer.associated-domains</key> |
| + <array> |
| + <string>webcredentials:id.oficina.works</string> |
| + </array> |
| + <key>com.apple.security.application-groups</key> |
| + <array> |
| + <string>9U4A84C4WK.works.oficina</string> |
| + </array> |
| + <!-- Docs' own group FIRST: a keychain query that names no group lands in |
| + the first one, and Docs' sessions and offline keys must never land in |
| + the group every Oficina app reads (rastrillo/native APPLE.md, |
| + "Oficina ID, slice A"). The second is the shared Oficina ID group. --> |
| + <key>keychain-access-groups</key> |
| + <array> |
| + <string>9U4A84C4WK.works.oficina.docs</string> |
| + <string>9U4A84C4WK.works.oficina.id</string> |
| + </array> |
| </dict> |
| </plist> |
diff --git a/native/macos/DeveloperID.entitlements b/native/macos/DeveloperID.entitlements| new file mode 100644 |
| index 0000000..2aa4c0a |
| --- /dev/null |
| +++ b/native/macos/DeveloperID.entitlements |
| @@ -0,0 +1,23 @@ |
| +<?xml version="1.0" encoding="UTF-8"?> |
| +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| +<plist version="1.0"> |
| +<dict> |
| + <key>com.apple.developer.associated-domains</key> |
| + <array> |
| + <string>webcredentials:id.oficina.works</string> |
| + </array> |
| + <key>com.apple.security.application-groups</key> |
| + <array> |
| + <string>9U4A84C4WK.works.oficina</string> |
| + </array> |
| + <!-- Docs' own group FIRST: a keychain query that names no group lands in |
| + the first one, and Docs' sessions and offline keys must never land in |
| + the group every Oficina app reads (rastrillo/native APPLE.md, |
| + "Oficina ID, slice A"). The second is the shared Oficina ID group. --> |
| + <key>keychain-access-groups</key> |
| + <array> |
| + <string>9U4A84C4WK.works.oficina.docs</string> |
| + <string>9U4A84C4WK.works.oficina.id</string> |
| + </array> |
| +</dict> |
| +</plist> |
diff --git a/native/macos/Info.plist b/native/macos/Info.plist| index 9b6f5f2..9a78f00 100644 |
| --- a/native/macos/Info.plist |
| +++ b/native/macos/Info.plist |
| @@ -14,6 +14,21 @@ |
| <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> |
| <key>CFBundleInfoDictionaryVersion</key> |
| <string>6.0</string> |
| + <key>CFBundleLocalizations</key> |
| + <array> |
| + <string>en</string> |
| + <string>ar</string> |
| + <string>bn</string> |
| + <string>es</string> |
| + <string>ga</string> |
| + <string>hi</string> |
| + <string>ja</string> |
| + <string>pt</string> |
| + <string>ru</string> |
| + <string>vi</string> |
| + <string>yue</string> |
| + <string>zh-Hans</string> |
| + </array> |
| <key>CFBundleName</key> |
| <string>Docs</string> |
| <key>CFBundlePackageType</key> |
diff --git a/native/macos/project.yml b/native/macos/project.yml| index 8f5ffe9..3e7c571 100644 |
| --- a/native/macos/project.yml |
| +++ b/native/macos/project.yml |
| @@ -7,7 +7,7 @@ packages: |
| path: ../apple |
| RastrilloNative: |
| url: https://amadan.net/rastrillo/native |
| - revision: b6a4067e39efd641fd5fa149cc666fee47bdb9b5 |
| + revision: f1c7a14db2ddb8960afabc8268cd92c490543397 |
| settings: |
| base: |
| SWIFT_VERSION: '6.0' |
| @@ -43,6 +43,23 @@ targets: |
| CFBundleVersion: $(CURRENT_PROJECT_VERSION) |
| CFBundleIconFile: AppIcon |
| LSApplicationCategoryType: public.app-category.productivity |
| + # The twelve languages Docs ships: PlainAppNameCommands' titles and |
| + # DocsKit's strings appear only in languages the app declares |
| + # (rastrillo/native docs/mac-updates.md). The Sparkle build gets the |
| + # same list from mac-updates.json. |
| + CFBundleLocalizations: |
| + - en |
| + - ar |
| + - bn |
| + - es |
| + - ga |
| + - hi |
| + - ja |
| + - pt |
| + - ru |
| + - vi |
| + - yue |
| + - zh-Hans |
| NSHighResolutionCapable: true |
| CFBundleURLTypes: |
| - CFBundleURLName: works.oficina.docs.signin |
diff --git a/native/notices/native/provenance.json b/native/notices/native/provenance.json| index a25207c..0da081e 100644 |
| --- a/native/notices/native/provenance.json |
| +++ b/native/notices/native/provenance.json |
| @@ -1,6 +1,6 @@ |
| { |
| "comment": "Rastrillo Native's LICENSE, copied unaltered from the checkout SwiftPM resolves for native/apple/Package.resolved (git status clean). internal/shipped refuses it if Package.resolved pins another location or revision.", |
| "location": "https://amadan.net/rastrillo/native", |
| - "revision": "b6a4067e39efd641fd5fa149cc666fee47bdb9b5", |
| + "revision": "f1c7a14db2ddb8960afabc8268cd92c490543397", |
| "sha256": "d8d2562a7cb68ffdfe91fc66af1ed4a8a4e272aa4ab59bea7451ba34b9aba3d4" |
| } |
diff --git a/native/scripts/snapshots.sh b/native/scripts/snapshots.sh| new file mode 100755 |
| index 0000000..1bc22d4 |
| --- /dev/null |
| +++ b/native/scripts/snapshots.sh |
| @@ -0,0 +1,36 @@ |
| +#!/bin/sh |
| +# Docs' screenshot gate (rastrillo/native RastrilloSnapshots): the library, |
| +# Oficina ID onboarding, Other ways to sign in, the team picker and Settings, |
| +# light and dark, and on iPhone at the default size and AX3. |
| +# |
| +# native/scripts/snapshots.sh [compare|record] [mac|iphone|all] |
| +# |
| +# compare (the default) fails on any changed, missing or stale picture; |
| +# record redraws the baselines in apple/Tests/DocsSnapshots/__Snapshots__/docs. |
| +# Review the contact sheet, apple/.build/snapshots/docs/index.html, before |
| +# committing a recording, and push baselines in commits under ~700 KB: the |
| +# hub drops a push whose pack is over about 1 MB. |
| +# |
| +# Not in .amadan/ci.d: baselines are exact only on the OS and simulator |
| +# runtime that drew them (ENVIRONMENT beside them says which). The runner |
| +# scripts are rastrillo/native's own, from the pinned checkout; the iPhone |
| +# half runs on its "Rastrillo Snapshots" simulator under its lock. |
| +set -eu |
| +cd "$(dirname "$0")/.." |
| +mode=${1:-compare} |
| +platforms=${2:-all} |
| +case "$mode" in compare|record) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac |
| +if [ "${OFICINA_SKIP_PREPARE:-0}" != 1 ]; then scripts/build-crdt.sh; fi |
| +swift package --package-path apple resolve |
| +shared=${OFICINA_NATIVE_PACKAGE_PATH:-apple/.build/checkouts/native} |
| +case "$shared" in /*) ;; *) shared="$(pwd)/$shared" ;; esac |
| +tools="$shared/tools" |
| +case "$platforms" in mac|all) |
| + (cd apple && "$tools/snapshots-mac.sh" "$mode" DocsSnapshots) ;; |
| +esac |
| +case "$platforms" in iphone|all) |
| + xcodegen generate --spec ios/project.yml |
| + # Build products stay under apple/.build, beside the Mac half's. |
| + (cd apple && SNAPSHOT_DERIVED_DATA=.build/xcode "$tools/snapshots-iphone.sh" "$mode" DocsPhoneSnapshots DocsPhoneSnapshots \ |
| + -project ../ios/DocsPhone.xcodeproj) ;; |
| +esac |