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>
113 lines
3.1 KiB
Dart
113 lines
3.1 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../api/docwell_api.dart';
|
|
|
|
/// A short, human explanation of a failed request.
|
|
String describeError(Object e) {
|
|
if (e is DocwellApiException) {
|
|
if (e.status == 404) return 'Not found, or you no longer have access.';
|
|
if (e.status == 403) return "You don't have permission to do that.";
|
|
return e.message.isNotEmpty ? e.message : 'The server refused (${e.code}).';
|
|
}
|
|
if (e is SocketException || e is HttpException) {
|
|
return "Can't reach the server, and this hasn't been opened before.";
|
|
}
|
|
return "Can't reach the server.";
|
|
}
|
|
|
|
class OfflineBanner extends StatelessWidget {
|
|
const OfflineBanner({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) => MaterialBanner(
|
|
key: const Key('offline'),
|
|
leading: const Icon(Icons.cloud_off_outlined),
|
|
content: const Text('Offline: showing what was saved on this phone.'),
|
|
actions: const [SizedBox.shrink()],
|
|
);
|
|
}
|
|
|
|
class ErrorTile extends StatelessWidget {
|
|
const ErrorTile({super.key, required this.message, required this.onRetry});
|
|
|
|
final String message;
|
|
final VoidCallback onRetry;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
children: [
|
|
Text(message, textAlign: TextAlign.center),
|
|
const SizedBox(height: 12),
|
|
FilledButton(onPressed: onRetry, child: const Text('Retry')),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
class SectionTitle extends StatelessWidget {
|
|
const SectionTitle(this.text, {super.key});
|
|
|
|
final String text;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 20, 16, 4),
|
|
child: Text(
|
|
text.toUpperCase(),
|
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
|
letterSpacing: 0.8,
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// A page's emoji icon, or a generic page icon.
|
|
class PageIcon extends StatelessWidget {
|
|
const PageIcon(this.icon, {super.key});
|
|
|
|
final String icon;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SizedBox(
|
|
width: 28,
|
|
child: Center(
|
|
child: icon.isEmpty
|
|
? const Icon(Icons.description_outlined)
|
|
: Text(icon, style: const TextStyle(fontSize: 20)),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// PocketBase dates look like "2026-10-30 21:05:00.000Z".
|
|
String shortDate(String s) {
|
|
final d = DateTime.tryParse(s.replaceFirst(' ', 'T'))?.toLocal();
|
|
if (d == null) return '';
|
|
final now = DateTime.now();
|
|
final hm =
|
|
'${d.hour.toString().padLeft(2, '0')}:${d.minute.toString().padLeft(2, '0')}';
|
|
if (d.year == now.year && d.month == now.month && d.day == now.day) {
|
|
return hm;
|
|
}
|
|
return '${d.day}.${d.month.toString().padLeft(2, '0')}.${d.year} $hm';
|
|
}
|
|
|
|
/// A stable colour for a user id, as the web editor's carets use.
|
|
String userColor(String id) {
|
|
const hues = [
|
|
'#2f7d6d', '#7c5cc4', '#c2571a', '#2f6fbf', //
|
|
'#b8327a', '#5f8a1f', '#a0761c', '#1f8a9a',
|
|
];
|
|
var h = 0;
|
|
for (final c in id.codeUnits) {
|
|
h = (h * 31 + c) & 0xffffffff;
|
|
}
|
|
return hues[h % hues.length];
|
|
}
|