Files
tajniak81andClaude Opus 5.5 1f580ca6f8 Add Mobile 1.0 and UnifiedPush notifications
Mobile app (Android):
- Sign-in to any server, with authenticator codes. The server address and
  token are kept in secure storage; a dropped connection never signs out.
- Workspaces, recent pages, spaces and a foldable page tree; search; the
  inbox with mark-read.
- Pages open read-only in the shared editor from their saved content and
  join the live document to edit (with the native toolbar). Page links in
  the text open in the app (new "navigate" bridge message).
- Comments: threads, replies, resolve.
- "Save to Docwell" in the Android share sheet makes a page from shared
  text, with web addresses as links.
- Offline reading: every answer the app reads is kept on the phone, and
  used when the server can't be reached.
- Push through UnifiedPush (ntfy, NextPush, ...). The app uses the Android
  connector directly; the umbrella package pulls in a native crypto build
  for Linux that breaks `dart run` and tests.

Server:
- /me/devices registers a phone's UnifiedPush endpoint and Web Push keys
  (new push_devices collection). Each notification is also pushed,
  encrypted with RFC 8291 aes128gcm so the distributor can't read it; the
  app drops messages that don't decrypt. Endpoints answering 404/410 are
  forgotten. Endpoints follow the webhook address rules.
- /collab accepts the apps' own origins ("null" for the mobile editor page,
  wails:// for the desktop app). Sign-in is a token in the first message,
  not a cookie, so this opens no cross-site hijacking.

Tried on an Android 15 emulator: sign-in, browsing, reading, live editing,
sharing and offline reading. Not covered: push end to end (no distributor
on the emulator), iOS, and YouTube embeds, which refuse to play from the
app's local editor page (error 153).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 14:52:20 +01:00

64 lines
1.8 KiB
Dart

// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
/// The server address and sign-in token, kept between app starts. The token
/// lives in the Android Keystore / iOS Keychain through secure storage.
abstract class SessionStore {
Future<({String server, String token})?> load();
Future<void> save(String server, String token);
/// Signs out on this phone; the server address is kept for next time.
Future<void> clearToken();
Future<String?> lastServer();
}
class SecureSessionStore implements SessionStore {
SecureSessionStore([FlutterSecureStorage? storage])
: _storage = storage ?? const FlutterSecureStorage();
final FlutterSecureStorage _storage;
@override
Future<({String server, String token})?> load() async {
final server = await _storage.read(key: 'server');
final token = await _storage.read(key: 'token');
if (server == null || token == null) return null;
return (server: server, token: token);
}
@override
Future<void> save(String server, String token) async {
await _storage.write(key: 'server', value: server);
await _storage.write(key: 'token', value: token);
}
@override
Future<void> clearToken() => _storage.delete(key: 'token');
@override
Future<String?> lastServer() => _storage.read(key: 'server');
}
/// For tests.
class MemorySessionStore implements SessionStore {
String? server;
String? token;
@override
Future<({String server, String token})?> load() async =>
server == null || token == null ? null : (server: server!, token: token!);
@override
Future<void> save(String server, String token) async {
this.server = server;
this.token = token;
}
@override
Future<void> clearToken() async => token = null;
@override
Future<String?> lastServer() async => server;
}