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>
203 lines
5.7 KiB
Dart
203 lines
5.7 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../api/docwell_api.dart';
|
|
import '../app.dart';
|
|
import '../share.dart';
|
|
import 'page_screen.dart';
|
|
import 'widgets.dart';
|
|
|
|
final _url = RegExp(r'https?://[^\s<>"]+');
|
|
|
|
/// The document for shared text: a paragraph per line, with web addresses
|
|
/// as links.
|
|
Map<String, dynamic> sharedDoc(String text) {
|
|
List<Map<String, dynamic>> inline(String line) {
|
|
final out = <Map<String, dynamic>>[];
|
|
var at = 0;
|
|
for (final m in _url.allMatches(line)) {
|
|
if (m.start > at) {
|
|
out.add({'type': 'text', 'text': line.substring(at, m.start)});
|
|
}
|
|
out.add({
|
|
'type': 'text',
|
|
'text': m[0],
|
|
'marks': [
|
|
{
|
|
'type': 'link',
|
|
'attrs': {'href': m[0]},
|
|
},
|
|
],
|
|
});
|
|
at = m.end;
|
|
}
|
|
if (at < line.length) out.add({'type': 'text', 'text': line.substring(at)});
|
|
return out;
|
|
}
|
|
|
|
return {
|
|
'type': 'doc',
|
|
'content': [
|
|
for (final line in text.trim().split(RegExp(r'\r?\n')))
|
|
line.trim().isEmpty
|
|
? {'type': 'paragraph'}
|
|
: {'type': 'paragraph', 'content': inline(line)},
|
|
],
|
|
};
|
|
}
|
|
|
|
/// A title for shared text: the sender's subject, else the first line.
|
|
String sharedTitle(SharedText s) {
|
|
if (s.subject.trim().isNotEmpty) return s.subject.trim();
|
|
final first = s.text.trim().split('\n').first.trim();
|
|
return first.length > 80 ? '${first.substring(0, 79)}…' : first;
|
|
}
|
|
|
|
/// "Save to Docwell": makes a page from text or a link shared by another app.
|
|
class ShareScreen extends StatefulWidget {
|
|
const ShareScreen({super.key, required this.session, required this.shared});
|
|
|
|
final AppSession session;
|
|
final SharedText shared;
|
|
|
|
@override
|
|
State<ShareScreen> createState() => _ShareScreenState();
|
|
}
|
|
|
|
class _ShareScreenState extends State<ShareScreen> {
|
|
DocwellApi get _api => widget.session.api;
|
|
late final _title = TextEditingController(text: sharedTitle(widget.shared));
|
|
List<(Workspace, Space)>? _targets;
|
|
(Workspace, Space)? _target;
|
|
String? _error;
|
|
bool _busy = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_load();
|
|
}
|
|
|
|
/// Every space, in every workspace, the user can add pages to.
|
|
Future<void> _load() async {
|
|
try {
|
|
final targets = <(Workspace, Space)>[];
|
|
for (final ws in await _api.workspaces()) {
|
|
for (final s in await _api.spaces(ws.id)) {
|
|
if (s.role == SpaceCallerRole.admin ||
|
|
s.role == SpaceCallerRole.editor) {
|
|
targets.add((ws, s));
|
|
}
|
|
}
|
|
}
|
|
if (mounted) {
|
|
setState(() {
|
|
_targets = targets;
|
|
_target = targets.firstOrNull;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
if (mounted) setState(() => _error = describeError(e));
|
|
}
|
|
}
|
|
|
|
Future<void> _save() async {
|
|
final target = _target;
|
|
if (target == null) return;
|
|
setState(() => _busy = true);
|
|
try {
|
|
final page = await _api.createPage(
|
|
target.$2.id,
|
|
title: _title.text.trim(),
|
|
);
|
|
await _api.saveContent(page.id, sharedDoc(widget.shared.text));
|
|
if (!mounted) return;
|
|
Navigator.of(context).pushReplacement(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => PageScreen(session: widget.session, pageId: page.id),
|
|
),
|
|
);
|
|
} catch (e) {
|
|
if (mounted) {
|
|
setState(() {
|
|
_busy = false;
|
|
_error = describeError(e);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_title.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final targets = _targets;
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Save to Docwell')),
|
|
body: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
TextField(
|
|
key: const Key('share-title'),
|
|
controller: _title,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Page title',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
if (targets == null && _error == null)
|
|
const Center(child: CircularProgressIndicator())
|
|
else if (targets != null && targets.isEmpty)
|
|
const Text("There's no space you can add pages to.")
|
|
else if (targets != null)
|
|
DropdownButtonFormField<(Workspace, Space)>(
|
|
initialValue: _target,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Space',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
items: [
|
|
for (final t in targets)
|
|
DropdownMenuItem(
|
|
value: t,
|
|
child: Text(
|
|
'${t.$2.name} · ${t.$1.name}',
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
onChanged: (t) => setState(() => _target = t),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text('Text', style: Theme.of(context).textTheme.labelLarge),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
widget.shared.text,
|
|
maxLines: 12,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
if (_error != null) ...[
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
_error!,
|
|
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
|
),
|
|
],
|
|
const SizedBox(height: 20),
|
|
FilledButton(
|
|
key: const Key('share-save'),
|
|
onPressed: _busy || _target == null ? null : _save,
|
|
child: const Text('Save as a new page'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|