CI / go (Server) (push) Failing after 4m38s
CI / go (Web-App) (push) Successful in 12m18s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / frontend (push) Failing after 7m49s
CI / desktop (ubuntu-latest) (push) Successful in 1h25m30s
CI / mobile (push) Failing after 5m14s
CI / docker (push) Successful in 39m26s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Databases (ADR-13 follow-ups):
- Relation properties link records to another database, on the same page
or on any page the reader can open (read live and read-only, like synced
pages). Cells list the linked titles; clicking one opens the record.
- Rollup properties work out counts, sums, averages, medians, min/max,
ranges, earliest/latest dates and checked counts over related records.
Neither is stored: views compute them before drawing (linked.ts), so they
follow both databases live, and rollups sort and filter as numbers.
- Exports (Markdown, HTML, PDF, Word) resolve them for same-page databases.
- A record opens as a full page at /p/<page>/r/<database>/<record>, with
"Open as full page" on the side panel and "Back to the page".
Edgeless mode (ADR-14 follow-ups):
- History previews show a version's canvas and count canvas changes.
- Comments can be anchored to canvas elements (anchor {element}); elements
with open threads show a badge that opens the thread.
- Workspaces choose how new pages open (workspaces.default_page_mode); the
per-device choice now defaults to following the workspace.
- Phones edit the canvas once a page is opened for editing; the page note
shows the page title.
Languages:
- The admin panel speaks English, Polish, German, French and Spanish, with
a picker sharing the web app's setting and a key parity test.
- The phone app speaks the same five, follows the phone's language (and
Android's per-app language setting), and has its own parity test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
192 lines
5.4 KiB
Dart
192 lines
5.4 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'api/docwell_api.dart';
|
|
import 'push.dart';
|
|
import 'screens/home_screen.dart';
|
|
import 'screens/login_screen.dart';
|
|
import 'screens/page_screen.dart';
|
|
import 'screens/share_screen.dart';
|
|
import 'session.dart';
|
|
import 'share.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'l10n.dart';
|
|
|
|
/// Makes a client for a server address (with its offline cache).
|
|
typedef ApiFactory = DocwellApi Function(String server);
|
|
|
|
/// What the signed-in screens share.
|
|
class AppSession {
|
|
AppSession({required this.api, required this.user, this.push});
|
|
|
|
final DocwellApi api;
|
|
final User user;
|
|
final PushService? push;
|
|
}
|
|
|
|
class DocwellApp extends StatefulWidget {
|
|
const DocwellApp({
|
|
super.key,
|
|
required this.sessions,
|
|
required this.apiFor,
|
|
this.push,
|
|
this.shares,
|
|
this.defaultServer = '',
|
|
});
|
|
|
|
final SessionStore sessions;
|
|
final ApiFactory apiFor;
|
|
final PushService? push;
|
|
final ShareReceiver? shares;
|
|
|
|
/// Pre-filled on the sign-in screen the first time.
|
|
final String defaultServer;
|
|
|
|
@override
|
|
State<DocwellApp> createState() => _DocwellAppState();
|
|
}
|
|
|
|
class _DocwellAppState extends State<DocwellApp> {
|
|
final _navigator = GlobalKey<NavigatorState>();
|
|
AppSession? _session;
|
|
bool _restoring = true;
|
|
String _server = '';
|
|
|
|
// A route or share that arrived before sign-in finished.
|
|
String? _pendingRoute;
|
|
SharedText? _pendingShare;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
unawaited(_restore());
|
|
unawaited(widget.push?.init(_openRoute));
|
|
unawaited(widget.shares?.listen(_openShare));
|
|
}
|
|
|
|
/// Signs back in with the saved token. Only the server rejecting it signs
|
|
/// out; without a connection the app starts offline with cached pages.
|
|
Future<void> _restore() async {
|
|
_server = await widget.sessions.lastServer() ?? widget.defaultServer;
|
|
final saved = await widget.sessions.load();
|
|
if (saved != null) {
|
|
final api = widget.apiFor(saved.server)..token = saved.token;
|
|
try {
|
|
final user = await api.refresh();
|
|
await widget.sessions.save(saved.server, api.token!);
|
|
_signedIn(api, user);
|
|
} on DocwellApiException {
|
|
await widget.sessions.clearToken();
|
|
} catch (_) {
|
|
try {
|
|
// Offline: the last /auth/me answer is in the cache.
|
|
_signedIn(api, await api.me());
|
|
} catch (_) {}
|
|
}
|
|
}
|
|
if (mounted) setState(() => _restoring = false);
|
|
}
|
|
|
|
void _signedIn(DocwellApi api, User user) {
|
|
api.onUnauthorized = _signOut;
|
|
widget.push?.api = api;
|
|
setState(
|
|
() => _session = AppSession(api: api, user: user, push: widget.push),
|
|
);
|
|
final route = _pendingRoute;
|
|
final share = _pendingShare;
|
|
_pendingRoute = null;
|
|
_pendingShare = null;
|
|
if (route != null) _openRoute(route);
|
|
if (share != null) _openShare(share);
|
|
}
|
|
|
|
Future<void> _onLogin(DocwellApi api, User user) async {
|
|
await widget.sessions.save(api.baseUrl, api.token!);
|
|
_server = api.baseUrl;
|
|
_signedIn(api, user);
|
|
}
|
|
|
|
Future<void> _signOut() async {
|
|
final s = _session;
|
|
if (s == null) return;
|
|
await widget.push?.disable();
|
|
widget.push?.api = null;
|
|
s.api.logout();
|
|
await s.api.cache.clear();
|
|
await widget.sessions.clearToken();
|
|
_navigator.currentState?.popUntil((r) => r.isFirst);
|
|
if (mounted) setState(() => _session = null);
|
|
}
|
|
|
|
/// Opens an app route from a notification: `/p/<id>` (with `?comment=…`).
|
|
void _openRoute(String route) {
|
|
final s = _session;
|
|
if (s == null) {
|
|
_pendingRoute = route;
|
|
return;
|
|
}
|
|
final uri = Uri.parse(route);
|
|
if (uri.pathSegments.length == 2 && uri.pathSegments[0] == 'p') {
|
|
_navigator.currentState?.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => PageScreen(
|
|
session: s,
|
|
pageId: uri.pathSegments[1],
|
|
openComment: uri.queryParameters['comment'],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
void _openShare(SharedText shared) {
|
|
final s = _session;
|
|
if (s == null) {
|
|
_pendingShare = shared;
|
|
return;
|
|
}
|
|
_navigator.currentState?.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => ShareScreen(session: s, shared: shared),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
const brand = Color(0xFF2F7D6D);
|
|
final s = _session;
|
|
return MaterialApp(
|
|
title: 'Docwell',
|
|
// The phone's language where the app has it (lib/l10n.dart), else English.
|
|
supportedLocales: [for (final l in appLanguages) Locale(l)],
|
|
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
localeListResolutionCallback: (phone, _) {
|
|
final lang = pickLanguage(phone ?? const []);
|
|
setAppLanguage(lang);
|
|
return Locale(lang);
|
|
},
|
|
navigatorKey: _navigator,
|
|
theme: ThemeData(colorSchemeSeed: brand, useMaterial3: true),
|
|
darkTheme: ThemeData(
|
|
colorSchemeSeed: brand,
|
|
brightness: Brightness.dark,
|
|
useMaterial3: true,
|
|
),
|
|
home: _restoring
|
|
? const Scaffold(body: Center(child: CircularProgressIndicator()))
|
|
: s == null
|
|
? LoginScreen(
|
|
server: _server,
|
|
apiFor: widget.apiFor,
|
|
onSignedIn: _onLogin,
|
|
)
|
|
: HomeScreen(session: s, onSignOut: _signOut),
|
|
);
|
|
}
|
|
}
|