mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-23 14:26:23 +01:00
Compare commits
36 Commits
v1.0.70-bu
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7153630a2e | |||
| f20e2ab16f | |||
| a96babd8f8 | |||
| 5d83ff561e | |||
| d5764fce7b | |||
| 660d82282c | |||
| 300d50ab11 | |||
| ea216d4a59 | |||
| fafefabab6 | |||
| 5acd9d4863 | |||
| 9d2a5a0bd3 | |||
| 3a747c2e51 | |||
| 1f7c31357b | |||
| b350b3e8c1 | |||
| e885465f55 | |||
| be6bf6fc48 | |||
| b2ffc346c3 | |||
| 0ce9c42ff6 | |||
| de5ad7d2dd | |||
| cd50fd0ae2 | |||
| 19f930a93a | |||
| f7e24bbb1a | |||
| 4423937f5c | |||
| f4913daaa8 | |||
| c9eb4d6cff | |||
| 1010d96426 | |||
| 319f18d33a | |||
| c3ac6ec05d | |||
| 0e56cddd47 | |||
| 203e61d6ac | |||
| edf6969949 | |||
| 5ea7ba7b73 | |||
| 091e68a2d9 | |||
| a30e7b34a9 | |||
| 17d6d2a533 | |||
| 4e8ccd6bfd |
5
.claude/settings.json
Normal file
5
.claude/settings.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"enabledPlugins": {
|
||||||
|
"dart-flutter@dart-flutter": true
|
||||||
|
}
|
||||||
|
}
|
||||||
2
.dep-freshness-no-workflow
Normal file
2
.dep-freshness-no-workflow
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Dependency freshness runs locally only (pre-commit hook); no GitHub Actions
|
||||||
|
# workflow. This marker stops the fleet installer from re-adding it.
|
||||||
62
.github/workflows/dependency-freshness.yml
vendored
62
.github/workflows/dependency-freshness.yml
vendored
@ -1,62 +0,0 @@
|
|||||||
name: dependency freshness
|
|
||||||
|
|
||||||
# Every dependency on its ecosystem's newest STABLE release, enforced on push
|
|
||||||
# as well as at commit time. The local pre-commit hook only sees the manifests
|
|
||||||
# in a commit and can be skipped entirely by a fresh clone that never ran
|
|
||||||
# `pre-commit install`; this runs `--all` over the whole repo.
|
|
||||||
#
|
|
||||||
# `--strict` is CI-only. Offline the gate degrades to its cached answer and
|
|
||||||
# passes, because `--no-verify` is banned locally and a hook that hard-failed
|
|
||||||
# on a flaky connection would leave no way to commit. A runner is always
|
|
||||||
# online, so here an undeterminable answer is a real failure.
|
|
||||||
#
|
|
||||||
# Expect this to go red for reasons this repo's commit did not cause: an
|
|
||||||
# upstream release overnight is enough. That is the chosen behaviour -- the
|
|
||||||
# alternative is a gate that only notices staleness when someone remembers to
|
|
||||||
# look.
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
dependency-freshness:
|
|
||||||
name: dependencies on newest stable
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# The gate lives in the shared utils repo so every repo resolves the
|
|
||||||
# same "latest stable" the same way. Checking it out beats vendoring a
|
|
||||||
# copy, which is exactly how a gate and its survey start disagreeing.
|
|
||||||
- name: Check out the shared gate
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
repository: kuhyx/utils
|
|
||||||
path: .utils
|
|
||||||
|
|
||||||
# "3.x", never a pinned minor: the Python target IS the interpreter the
|
|
||||||
# gate runs under (registries/toolchain.python_installed), so a runner
|
|
||||||
# held a release behind this machine reports a repo's `requires-python`
|
|
||||||
# as excluding "latest" while the same check passes locally. flax-docs-mcp
|
|
||||||
# hit exactly that -- `>=3.14` green here, red on a 3.13 runner.
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.x"
|
|
||||||
|
|
||||||
- name: Install the gate's two runtime dependencies
|
|
||||||
run: python -m pip install --upgrade pyyaml packaging
|
|
||||||
|
|
||||||
- name: Cache registry lookups
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: ~/.cache/dep-freshness
|
|
||||||
key: dep-freshness-${{ hashFiles('**/pubspec.yaml', '**/pyproject.toml',
|
|
||||||
'**/requirements*.txt', '**/package.json', '**/Cargo.toml', '**/go.mod') }}
|
|
||||||
restore-keys: dep-freshness-
|
|
||||||
|
|
||||||
- name: Every dependency is on newest stable
|
|
||||||
run: bash .utils/scripts/check_dependency_freshness.sh --all --strict
|
|
||||||
6
.github/workflows/release-apk.yml
vendored
6
.github/workflows/release-apk.yml
vendored
@ -47,7 +47,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: subosito/flutter-action@v2
|
- uses: subosito/flutter-action@v2
|
||||||
with:
|
with:
|
||||||
flutter-version: 3.47.9
|
flutter-version: 3.50.1
|
||||||
channel: stable
|
channel: stable
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
@ -110,7 +110,9 @@ jobs:
|
|||||||
flutter build apk --release \
|
flutter build apk --release \
|
||||||
--target-platform android-arm64 \
|
--target-platform android-arm64 \
|
||||||
--build-name="${{ steps.ver.outputs.semver }}" \
|
--build-name="${{ steps.ver.outputs.semver }}" \
|
||||||
--build-number="${{ steps.vc.outputs.code }}"
|
--build-number="${{ steps.vc.outputs.code }}" \
|
||||||
|
--dart-define=APP_BUILD="${{ steps.vc.outputs.code }}" \
|
||||||
|
--dart-define=APP_VERSION="${{ steps.ver.outputs.semver }}"
|
||||||
|
|
||||||
# Fail closed. `findByName("release") ?: debug` silently falls back to
|
# Fail closed. `findByName("release") ?: debug` silently falls back to
|
||||||
# the debug key if key.properties is misplaced, producing a green build
|
# the debug key if key.properties is misplaced, producing a green build
|
||||||
|
|||||||
@ -106,7 +106,7 @@ repos:
|
|||||||
# Runs WITHOUT --strict on purpose. Offline it degrades to the cached
|
# Runs WITHOUT --strict on purpose. Offline it degrades to the cached
|
||||||
# answer and passes with a loud banner; `--no-verify` is banned here, so
|
# answer and passes with a loud banner; `--no-verify` is banned here, so
|
||||||
# a hook that hard-failed on a flaky connection would leave no way to
|
# a hook that hard-failed on a flaky connection would leave no way to
|
||||||
# commit at all. CI, always online, is the strict authority.
|
# commit at all. Local only: no CI workflow runs this.
|
||||||
- id: dependency-freshness
|
- id: dependency-freshness
|
||||||
name: dependencies on newest stable
|
name: dependencies on newest stable
|
||||||
entry: scripts/check_dependency_freshness.sh
|
entry: scripts/check_dependency_freshness.sh
|
||||||
|
|||||||
16
AGENTS.md
16
AGENTS.md
@ -50,6 +50,7 @@ and sync peer-to-peer through a GitHub repo used as dumb storage.
|
|||||||
- lint: `flutter analyze`
|
- lint: `flutter analyze`
|
||||||
- coverage: `flutter test --coverage --reporter=compact`
|
- coverage: `flutter test --coverage --reporter=compact`
|
||||||
- coverage-gaps: `coverage-gaps coverage/lcov.info`
|
- coverage-gaps: `coverage-gaps coverage/lcov.info`
|
||||||
|
- deploy: `scripts/deploy.sh` (MCP service, desktop pacman package, phone release; exits non-zero unless every health check passes)
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
@ -217,3 +218,18 @@ about *this repo*:
|
|||||||
|
|
||||||
Sourced from [flutter/flutter docs/rules/rules.md](https://github.com/flutter/flutter/blob/main/docs/rules/rules.md)
|
Sourced from [flutter/flutter docs/rules/rules.md](https://github.com/flutter/flutter/blob/main/docs/rules/rules.md)
|
||||||
via `~/.claude/CLAUDE.md`'s Flutter AI tooling setup. Re-fetch periodically.
|
via `~/.claude/CLAUDE.md`'s Flutter AI tooling setup. Re-fetch periodically.
|
||||||
|
|
||||||
|
## Driving the app on the phone
|
||||||
|
|
||||||
|
Tap and type by label, never by coordinate, with `android_ui` from
|
||||||
|
`~/src/testsAndMisc` (not copied here):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/src/testsAndMisc && .venv/bin/python -m python_pkg.android_ui \
|
||||||
|
-s 23181JEGR08034 --display self dump
|
||||||
|
```
|
||||||
|
|
||||||
|
The same driver is the `android-ui` MCP server
|
||||||
|
(`.venv/bin/python -m python_pkg.android_ui.mcp_server`, in that repo's
|
||||||
|
`.mcp.json`). Tools and error contract:
|
||||||
|
`~/src/testsAndMisc/python_pkg/android_ui/README.md`.
|
||||||
|
|||||||
15
README.md
15
README.md
@ -37,3 +37,18 @@ dart run bin/todo_note.dart --delete <id>
|
|||||||
`--list` and `--get` never push; `--data-dir <dir>` selects a throwaway node.
|
`--list` and `--get` never push; `--data-dir <dir>` selects a throwaway node.
|
||||||
Exit codes: 0 ok, 1 sync/auth failure or note not found, 2 bad arguments.
|
Exit codes: 0 ok, 1 sync/auth failure or note not found, 2 bad arguments.
|
||||||
All logic is in `lib/cli/` (tested in `test/cli/`); `--help` lists every flag.
|
All logic is in `lib/cli/` (tested in `test/cli/`); `--help` lists every flag.
|
||||||
|
|
||||||
|
## Driving the app on the phone
|
||||||
|
|
||||||
|
Tap and type by label, never by coordinate, with `android_ui` from
|
||||||
|
`~/src/testsAndMisc` (not copied here):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/src/testsAndMisc && .venv/bin/python -m python_pkg.android_ui \
|
||||||
|
-s 23181JEGR08034 --display self dump
|
||||||
|
```
|
||||||
|
|
||||||
|
The same driver is the `android-ui` MCP server
|
||||||
|
(`.venv/bin/python -m python_pkg.android_ui.mcp_server`, in that repo's
|
||||||
|
`.mcp.json`). Tools and error contract:
|
||||||
|
`~/src/testsAndMisc/python_pkg/android_ui/README.md`.
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
|
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=1G -XX:ReservedCodeCacheSize=256m -XX:+UseSerialGC -XX:TieredStopAtLevel=1
|
||||||
|
org.gradle.caching=true
|
||||||
|
org.gradle.parallel=true
|
||||||
|
kotlin.compiler.execution.strategy=in-process
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
# This newDsl flag was added by the Flutter template
|
# This newDsl flag was added by the Flutter template
|
||||||
android.newDsl=false
|
android.newDsl=false
|
||||||
|
|||||||
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.0-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-all.zip
|
||||||
|
|||||||
4
dependency-freshness.allowlist.yaml
Normal file
4
dependency-freshness.allowlist.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# todo's own additions to the fleet-wide allowlist
|
||||||
|
# (~/src/utils/dependency-freshness.allowlist.yaml).
|
||||||
|
|
||||||
|
exceptions: []
|
||||||
@ -63,6 +63,9 @@ class CliArgs {
|
|||||||
case '--get' || '--delete' || '--close':
|
case '--get' || '--delete' || '--close':
|
||||||
modes.add(CliMode.values.byName(arg.substring(2)));
|
modes.add(CliMode.values.byName(arg.substring(2)));
|
||||||
id = value();
|
id = value();
|
||||||
|
case '--set-text':
|
||||||
|
modes.add(CliMode.setText);
|
||||||
|
id = value();
|
||||||
case '--set-status':
|
case '--set-status':
|
||||||
modes.add(CliMode.setStatus);
|
modes.add(CliMode.setStatus);
|
||||||
id = value();
|
id = value();
|
||||||
@ -74,7 +77,8 @@ class CliArgs {
|
|||||||
if (modes.contains(CliMode.help)) return const CliArgs(mode: CliMode.help);
|
if (modes.contains(CliMode.help)) return const CliArgs(mode: CliMode.help);
|
||||||
if (modes.length > 1) {
|
if (modes.length > 1) {
|
||||||
throw UsageError(
|
throw UsageError(
|
||||||
'--list, --search, --get, --delete, --set-status, --close and '
|
'--list, --search, --get, --delete, --set-status, --set-text, '
|
||||||
|
'--close and '
|
||||||
'--backfill-created-by are mutually exclusive',
|
'--backfill-created-by are mutually exclusive',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -110,7 +114,8 @@ class CliArgs {
|
|||||||
/// The selected mode.
|
/// The selected mode.
|
||||||
final CliMode mode;
|
final CliMode mode;
|
||||||
|
|
||||||
/// Note text from `--text`; null means "read stdin" in [CliMode.add].
|
/// Note text from `--text`; null means "read stdin" in [CliMode.add] and
|
||||||
|
/// [CliMode.setText].
|
||||||
final String? text;
|
final String? text;
|
||||||
|
|
||||||
/// Full id or 8+ character prefix of the note an id mode acts on.
|
/// Full id or 8+ character prefix of the note an id mode acts on.
|
||||||
@ -146,7 +151,7 @@ class CliArgs {
|
|||||||
|
|
||||||
static const _adding = 'when adding a note';
|
static const _adding = 'when adding a note';
|
||||||
static const Map<String, (String, Set<CliMode>)> _scopes = {
|
static const Map<String, (String, Set<CliMode>)> _scopes = {
|
||||||
'--text': (_adding, {CliMode.add}),
|
'--text': ('$_adding or to --set-text', {CliMode.add, CliMode.setText}),
|
||||||
'--done-check': (_adding, {CliMode.add}),
|
'--done-check': (_adding, {CliMode.add}),
|
||||||
'--by': (_adding, {CliMode.add}),
|
'--by': (_adding, {CliMode.add}),
|
||||||
'--repo': (
|
'--repo': (
|
||||||
|
|||||||
@ -136,6 +136,15 @@ class CliCommands {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replaces a note's whole text (title is its first line) and pushes it.
|
||||||
|
Future<int> setText(String ref, String text) async {
|
||||||
|
final note = await _pullAndFind(ref);
|
||||||
|
await _save(note.copyWith(text: text));
|
||||||
|
if (!await _push('text change')) return 1;
|
||||||
|
_out.writeln('${note.id}\ttext');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Marks a note done with [evidence], keeping it, and pushes it.
|
/// Marks a note done with [evidence], keeping it, and pushes it.
|
||||||
Future<int> close(String ref, String evidence) async {
|
Future<int> close(String ref, String evidence) async {
|
||||||
final note = await _pullAndFind(ref);
|
final note = await _pullAndFind(ref);
|
||||||
|
|||||||
@ -18,6 +18,9 @@ enum CliMode {
|
|||||||
/// Change one note's status and push it.
|
/// Change one note's status and push it.
|
||||||
setStatus,
|
setStatus,
|
||||||
|
|
||||||
|
/// Replace one note's whole text and push it.
|
||||||
|
setText,
|
||||||
|
|
||||||
/// Set a task done with evidence and push it.
|
/// Set a task done with evidence and push it.
|
||||||
close,
|
close,
|
||||||
|
|
||||||
|
|||||||
26
lib/cli/cli_paths.dart
Normal file
26
lib/cli/cli_paths.dart
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:todo/cli/cli_session.dart' show CliSession;
|
||||||
|
|
||||||
|
/// Default data dir: `$XDG_DATA_HOME/todo-cli`, else `~/.local/share/todo-cli`.
|
||||||
|
String defaultDataDir(Map<String, String> env) {
|
||||||
|
final xdg = env['XDG_DATA_HOME'] ?? '';
|
||||||
|
final base = xdg.isNotEmpty
|
||||||
|
? xdg
|
||||||
|
: p.join(env['HOME'] ?? '', '.local', 'share');
|
||||||
|
return p.join(base, 'todo-cli');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Node ids of the installs Claude files notes through: the MCP server and
|
||||||
|
/// the CLI under the same data root as [defaultDataDir]. Missing ones are
|
||||||
|
/// skipped.
|
||||||
|
Set<String> claudeNodeIds(Map<String, String> env) {
|
||||||
|
final cli = defaultDataDir(env);
|
||||||
|
return {
|
||||||
|
for (final dir in [cli, p.join(p.dirname(cli), 'todo-mcp')])
|
||||||
|
if (File(p.join(dir, CliSession.nodeIdFileName)) case final f
|
||||||
|
when f.existsSync())
|
||||||
|
f.readAsStringSync().trim(),
|
||||||
|
}..remove('');
|
||||||
|
}
|
||||||
@ -54,7 +54,7 @@ Future<int> runCli(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
String? text;
|
String? text;
|
||||||
if (args.mode == CliMode.add) {
|
if (args.mode == CliMode.add || args.mode == CliMode.setText) {
|
||||||
text = args.text ?? await readStdin();
|
text = args.text ?? await readStdin();
|
||||||
if (text.trim().isEmpty) {
|
if (text.trim().isEmpty) {
|
||||||
err.writeln('error: empty note (pass --text or pipe text on stdin)');
|
err.writeln('error: empty note (pass --text or pipe text on stdin)');
|
||||||
@ -79,6 +79,7 @@ Future<int> runCli(
|
|||||||
CliMode.list || CliMode.search => await cli.list(args),
|
CliMode.list || CliMode.search => await cli.list(args),
|
||||||
CliMode.get => await cli.get(args.id!),
|
CliMode.get => await cli.get(args.id!),
|
||||||
CliMode.setStatus => await cli.setStatus(args.id!, args.status!),
|
CliMode.setStatus => await cli.setStatus(args.id!, args.status!),
|
||||||
|
CliMode.setText => await cli.setText(args.id!, text!),
|
||||||
CliMode.close => await cli.close(args.id!, args.opts.evidence!),
|
CliMode.close => await cli.close(args.id!, args.opts.evidence!),
|
||||||
CliMode.backfill => await cli.backfillCreatedBy(
|
CliMode.backfill => await cli.backfillCreatedBy(
|
||||||
claudeNodeIds(env),
|
claudeNodeIds(env),
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
/// records hand-written into RTDB.
|
/// records hand-written into RTDB.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
@ -15,38 +16,33 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:todo/cli/file_credential_store.dart';
|
import 'package:todo/cli/file_credential_store.dart';
|
||||||
import 'package:todo/cli/pull_only_store.dart';
|
import 'package:todo/cli/pull_only_store.dart';
|
||||||
|
import 'package:todo/cli/timeout_client.dart';
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
import 'package:todo/sync/firebase_project.dart';
|
import 'package:todo/sync/firebase_project.dart';
|
||||||
import 'package:todo/sync/sync_service.dart';
|
import 'package:todo/sync/sync_service.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
/// Default data dir: `$XDG_DATA_HOME/todo-cli`, else `~/.local/share/todo-cli`.
|
export 'package:todo/cli/cli_paths.dart';
|
||||||
String defaultDataDir(Map<String, String> env) {
|
|
||||||
final xdg = env['XDG_DATA_HOME'] ?? '';
|
|
||||||
final base = xdg.isNotEmpty
|
|
||||||
? xdg
|
|
||||||
: p.join(env['HOME'] ?? '', '.local', 'share');
|
|
||||||
return p.join(base, 'todo-cli');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Node ids of the installs Claude files notes through: the MCP server and
|
|
||||||
/// the CLI under the same data root as [defaultDataDir]. Missing ones are
|
|
||||||
/// skipped.
|
|
||||||
Set<String> claudeNodeIds(Map<String, String> env) {
|
|
||||||
final cli = defaultDataDir(env);
|
|
||||||
return {
|
|
||||||
for (final dir in [cli, p.join(p.dirname(cli), 'todo-mcp')])
|
|
||||||
if (File(p.join(dir, CliSession.nodeIdFileName)) case final f
|
|
||||||
when f.existsSync())
|
|
||||||
f.readAsStringSync().trim(),
|
|
||||||
}..remove('');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The open state of one CLI invocation. Call [close] when done.
|
/// The open state of one CLI invocation. Call [close] when done.
|
||||||
class CliSession {
|
class CliSession {
|
||||||
/// Wraps already-open parts; [open] is the normal way in. Public so a test
|
/// Wraps already-open parts; [open] is the normal way in. Public so a test
|
||||||
/// can subclass the session and script [sync]'s outcome.
|
/// can subclass the session and script [sync]'s outcome.
|
||||||
CliSession(this.dataDir, this.repository, this._firebase);
|
CliSession(
|
||||||
|
this.dataDir,
|
||||||
|
this.repository,
|
||||||
|
this._firebase, {
|
||||||
|
this.passphraseFile,
|
||||||
|
this.sharedPasswordFile,
|
||||||
|
});
|
||||||
|
|
||||||
|
/// The fleet-wide crdt-sync password the Python daemons read too
|
||||||
|
/// (`~/.config/crdt-sync/password`), found from the seed's config root.
|
||||||
|
final File? sharedPasswordFile;
|
||||||
|
|
||||||
|
/// Where the passphrase is read from besides the environment: next to the
|
||||||
|
/// seeded Firebase session, e.g. `~/.config/todo/e2e_passphrase`.
|
||||||
|
final File? passphraseFile;
|
||||||
|
|
||||||
/// File holding this install's persisted CRDT node id.
|
/// File holding this install's persisted CRDT node id.
|
||||||
static const nodeIdFileName = 'node_id';
|
static const nodeIdFileName = 'node_id';
|
||||||
@ -68,13 +64,19 @@ class CliSession {
|
|||||||
/// Opens (creating on first use) the session rooted at [dataDir].
|
/// Opens (creating on first use) the session rooted at [dataDir].
|
||||||
///
|
///
|
||||||
/// [seedCredentials] is todo's desktop session, read once and never written.
|
/// [seedCredentials] is todo's desktop session, read once and never written.
|
||||||
/// [httpClient] replaces the real network client (tests only).
|
/// [httpClient] replaces the real network client (tests only). Either way
|
||||||
|
/// every request is bounded by [requestTimeout] (see [TimeoutClient]).
|
||||||
static Future<CliSession> open(
|
static Future<CliSession> open(
|
||||||
String dataDir, {
|
String dataDir, {
|
||||||
required String seedCredentials,
|
required String seedCredentials,
|
||||||
String seedApp = 'todo',
|
String seedApp = 'todo',
|
||||||
http.Client? httpClient,
|
http.Client? httpClient,
|
||||||
|
Duration requestTimeout = const Duration(seconds: 30),
|
||||||
}) async {
|
}) async {
|
||||||
|
final network = TimeoutClient(
|
||||||
|
httpClient ?? http.Client(),
|
||||||
|
timeout: requestTimeout,
|
||||||
|
);
|
||||||
final dir = Directory(dataDir);
|
final dir = Directory(dataDir);
|
||||||
await dir.create(recursive: true);
|
await dir.create(recursive: true);
|
||||||
// Holds a database-write credential: owner-only, like ~/.config/todo.
|
// Holds a database-write credential: owner-only, like ~/.config/todo.
|
||||||
@ -87,7 +89,7 @@ class CliSession {
|
|||||||
);
|
);
|
||||||
final auth = FirebaseTokenProvider(
|
final auth = FirebaseTokenProvider(
|
||||||
apiKey: kProject.apiKey,
|
apiKey: kProject.apiKey,
|
||||||
httpClient: httpClient,
|
httpClient: network,
|
||||||
store: FileCredentialStore(
|
store: FileCredentialStore(
|
||||||
file: File(p.join(dataDir, credentialsFileName)),
|
file: File(p.join(dataDir, credentialsFileName)),
|
||||||
seedFile: File(seedCredentials),
|
seedFile: File(seedCredentials),
|
||||||
@ -103,9 +105,19 @@ class CliSession {
|
|||||||
final firebase = FirebaseRestClient(
|
final firebase = FirebaseRestClient(
|
||||||
databaseUrl: kProject.databaseUrl,
|
databaseUrl: kProject.databaseUrl,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
httpClient: httpClient,
|
httpClient: network,
|
||||||
|
);
|
||||||
|
return CliSession(
|
||||||
|
dataDir,
|
||||||
|
repository,
|
||||||
|
firebase,
|
||||||
|
passphraseFile: File(
|
||||||
|
p.join(p.dirname(seedCredentials), e2ePassphraseFileName),
|
||||||
|
),
|
||||||
|
sharedPasswordFile: File(
|
||||||
|
p.join(p.dirname(p.dirname(seedCredentials)), 'crdt-sync', 'password'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return CliSession(dataDir, repository, firebase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pull every peer's log and merge it; with [push], also publish this
|
/// Pull every peer's log and merge it; with [push], also publish this
|
||||||
@ -113,15 +125,91 @@ class CliSession {
|
|||||||
///
|
///
|
||||||
/// Without [push] nothing is written anywhere remote, and the revision cache
|
/// Without [push] nothing is written anywhere remote, and the revision cache
|
||||||
/// is bypassed so a read always sees every peer's current log.
|
/// is bypassed so a read always sees every peer's current log.
|
||||||
Future<SyncResult> sync({required bool push}) {
|
Future<SyncResult> sync({required bool push}) async {
|
||||||
|
final plainService = SyncService(
|
||||||
|
stateStore: push
|
||||||
|
? PersistedSyncStateStore(
|
||||||
|
FileLogPersistence(File(p.join(dataDir, syncStateFileName))),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
final e2e = await openEncryptedStore(
|
||||||
|
store: _remote(push: push),
|
||||||
|
oldPrefix: plainService.notesDir,
|
||||||
|
readPassphrase: _readPassphrase,
|
||||||
|
// Argon2id once per install, not on every CLI/MCP call.
|
||||||
|
keyCache: E2eKeyCache(read: _readCachedKey, write: _writeCachedKey),
|
||||||
|
);
|
||||||
if (!push) {
|
if (!push) {
|
||||||
return const SyncService().sync(repository, PullOnlyStore(_firebase));
|
// Read-only during the migration: old builds still write the plaintext
|
||||||
|
// prefix, so merge it, then the encrypted one when this host has a key.
|
||||||
|
final plain = await const SyncService().sync(
|
||||||
|
repository,
|
||||||
|
_remote(push: false),
|
||||||
|
);
|
||||||
|
if (e2e is! E2eReady) return plain;
|
||||||
|
final layout = E2eLayout.of(plainService.notesDir);
|
||||||
|
return await SyncService(
|
||||||
|
notesDir: layout.prefix,
|
||||||
|
revsPath: layout.revsPath,
|
||||||
|
).sync(repository, e2e.store);
|
||||||
}
|
}
|
||||||
return SyncService(
|
if (e2e is! E2eReady) {
|
||||||
stateStore: PersistedSyncStateStore(
|
throw StateError(
|
||||||
FileLogPersistence(File(p.join(dataDir, syncStateFileName))),
|
'sync is locked: put the crdt-sync passphrase in '
|
||||||
),
|
'$e2ePassphraseEnv or ${passphraseFile?.path ?? e2ePassphraseFileName}',
|
||||||
).sync(repository, _firebase);
|
);
|
||||||
|
}
|
||||||
|
final layout = E2eLayout.of(plainService.notesDir);
|
||||||
|
return await SyncService(
|
||||||
|
notesDir: layout.prefix,
|
||||||
|
revsPath: layout.revsPath,
|
||||||
|
stateStore: plainService.stateStore,
|
||||||
|
).sync(repository, e2e.store);
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteStore _remote({required bool push}) =>
|
||||||
|
push ? _firebase : PullOnlyStore(_firebase);
|
||||||
|
|
||||||
|
/// Owner-only file in the data dir caching the derived E2E key.
|
||||||
|
static const e2eKeyFileName = 'e2e_key';
|
||||||
|
|
||||||
|
File get _keyFile => File(p.join(dataDir, e2eKeyFileName));
|
||||||
|
|
||||||
|
Future<List<int>?> _readCachedKey() async {
|
||||||
|
final file = _keyFile;
|
||||||
|
if (!file.existsSync()) return null;
|
||||||
|
try {
|
||||||
|
return base64.decode((await file.readAsString()).trim());
|
||||||
|
} on FormatException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _writeCachedKey(List<int> bytes) async {
|
||||||
|
final file = _keyFile;
|
||||||
|
// Restrict before the key is written, never after.
|
||||||
|
await file.writeAsString('');
|
||||||
|
await Process.run('chmod', ['600', file.path]);
|
||||||
|
await file.writeAsString(base64.encode(bytes), flush: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Environment variable holding the shared crdt-sync passphrase.
|
||||||
|
static const e2ePassphraseEnv = 'TODO_E2E_PASSPHRASE';
|
||||||
|
|
||||||
|
/// File name of the passphrase, beside the seeded Firebase session.
|
||||||
|
static const e2ePassphraseFileName = 'e2e_passphrase';
|
||||||
|
|
||||||
|
Future<String?> _readPassphrase() async {
|
||||||
|
final fromEnv = Platform.environment[e2ePassphraseEnv];
|
||||||
|
if (fromEnv != null && fromEnv.isNotEmpty) return fromEnv;
|
||||||
|
for (final file in [passphraseFile, sharedPasswordFile]) {
|
||||||
|
if (file != null && file.existsSync()) {
|
||||||
|
final text = (await file.readAsString()).trim();
|
||||||
|
if (text.isNotEmpty) return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Releases the log and the HTTP client.
|
/// Releases the log and the HTTP client.
|
||||||
|
|||||||
@ -22,6 +22,8 @@ A note with --repo is a repo task; one without is a plain idea.
|
|||||||
--get <id> pull, then print one note in full (exit 1 if absent)
|
--get <id> pull, then print one note in full (exit 1 if absent)
|
||||||
--delete <id> pull, tombstone the note, push
|
--delete <id> pull, tombstone the note, push
|
||||||
--set-status <id> <s> pull, change the note's status (as --status), push
|
--set-status <id> <s> pull, change the note's status (as --status), push
|
||||||
|
--set-text <id> pull, replace the note's whole text with --text (or
|
||||||
|
stdin; first line = title), keep its other fields, push
|
||||||
--close <id> --evidence <s>
|
--close <id> --evidence <s>
|
||||||
pull, set status done + evidence (commit sha + done
|
pull, set status done + evidence (commit sha + done
|
||||||
check exit code), push; refused without --evidence
|
check exit code), push; refused without --evidence
|
||||||
|
|||||||
58
lib/cli/timeout_client.dart
Normal file
58
lib/cli/timeout_client.dart
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
/// An HTTP client whose every request is bounded.
|
||||||
|
///
|
||||||
|
/// `package:http` has no timeout of its own, and neither do the Firebase and
|
||||||
|
/// token clients built on it: one dead connection (after boot, a network
|
||||||
|
/// blip) made a sync wait forever and wedged the MCP server's serial queue.
|
||||||
|
/// [timeout] bounds the wait for the response headers and then each gap
|
||||||
|
/// between body chunks, so a large body that keeps moving is never cut off.
|
||||||
|
class TimeoutClient extends http.BaseClient {
|
||||||
|
/// Wraps [_inner]; each wait fails with a [TimeoutException] after [timeout].
|
||||||
|
TimeoutClient(this._inner, {this.timeout = const Duration(seconds: 30)});
|
||||||
|
|
||||||
|
final http.Client _inner;
|
||||||
|
|
||||||
|
/// Longest wait for the headers, and for the next body chunk.
|
||||||
|
final Duration timeout;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.StreamedResponse> send(http.BaseRequest request) async {
|
||||||
|
final response = await _inner
|
||||||
|
.send(request)
|
||||||
|
.timeout(
|
||||||
|
timeout,
|
||||||
|
onTimeout: () => throw TimeoutException(
|
||||||
|
'${request.method} ${request.url.host} got no response',
|
||||||
|
timeout,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return http.StreamedResponse(
|
||||||
|
response.stream.timeout(
|
||||||
|
timeout,
|
||||||
|
onTimeout: (sink) {
|
||||||
|
sink
|
||||||
|
..addError(
|
||||||
|
TimeoutException(
|
||||||
|
'${request.method} ${request.url.host} body stalled',
|
||||||
|
timeout,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
..close();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
response.statusCode,
|
||||||
|
contentLength: response.contentLength,
|
||||||
|
request: response.request,
|
||||||
|
headers: response.headers,
|
||||||
|
isRedirect: response.isRedirect,
|
||||||
|
persistentConnection: response.persistentConnection,
|
||||||
|
reasonPhrase: response.reasonPhrase,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void close() => _inner.close();
|
||||||
|
}
|
||||||
@ -73,11 +73,7 @@ class LegacySqliteMigration {
|
|||||||
}
|
}
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
static Future<void> _onUpgrade(
|
static Future<void> _onUpgrade(CrdtTableExecutor db, int from, int to) async {
|
||||||
CrdtTableExecutor db,
|
|
||||||
int from,
|
|
||||||
int to,
|
|
||||||
) async {
|
|
||||||
if (from < 2) {
|
if (from < 2) {
|
||||||
await db.execute(
|
await db.execute(
|
||||||
'ALTER TABLE notes ADD COLUMN status INTEGER NOT NULL DEFAULT 0',
|
'ALTER TABLE notes ADD COLUMN status INTEGER NOT NULL DEFAULT 0',
|
||||||
|
|||||||
@ -21,12 +21,21 @@ class LinuxSystemProbe implements SystemProbe {
|
|||||||
/// Creates the default host probe.
|
/// Creates the default host probe.
|
||||||
///
|
///
|
||||||
/// [ssExecutable] exists so a test can point at a missing binary and exercise
|
/// [ssExecutable] exists so a test can point at a missing binary and exercise
|
||||||
/// the "no `ss` on PATH" path.
|
/// the "no `ss` on PATH" path. [listProc] lets a test fail the `/proc`
|
||||||
const LinuxSystemProbe({this.ssExecutable = 'ss'});
|
/// listing on demand.
|
||||||
|
const LinuxSystemProbe({this.ssExecutable = 'ss', this.listProc = _listProc});
|
||||||
|
|
||||||
/// Name of the socket-listing tool used to find the port owner.
|
/// Name of the socket-listing tool used to find the port owner.
|
||||||
final String ssExecutable;
|
final String ssExecutable;
|
||||||
|
|
||||||
|
/// Lists `/proc`'s entries.
|
||||||
|
final List<FileSystemEntity> Function() listProc;
|
||||||
|
|
||||||
|
/// How many `/proc` listings a process exiting mid-listing may spoil.
|
||||||
|
static const _listAttempts = 3;
|
||||||
|
|
||||||
|
static List<FileSystemEntity> _listProc() => Directory('/proc').listSync();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int?> listenerPid(int port) async {
|
Future<int?> listenerPid(int port) async {
|
||||||
try {
|
try {
|
||||||
@ -56,7 +65,7 @@ class LinuxSystemProbe implements SystemProbe {
|
|||||||
@override
|
@override
|
||||||
Future<List<List<String>>> processCmdlines() async {
|
Future<List<List<String>>> processCmdlines() async {
|
||||||
final cmdlines = <List<String>>[];
|
final cmdlines = <List<String>>[];
|
||||||
for (final entry in Directory('/proc').listSync()) {
|
for (final entry in _listProcRetrying()) {
|
||||||
final pid = int.tryParse(p.basename(entry.path));
|
final pid = int.tryParse(p.basename(entry.path));
|
||||||
if (pid == null) continue;
|
if (pid == null) continue;
|
||||||
final cmdline = readCmdline(pid);
|
final cmdline = readCmdline(pid);
|
||||||
@ -65,6 +74,19 @@ class LinuxSystemProbe implements SystemProbe {
|
|||||||
return cmdlines;
|
return cmdlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dart's listing lstat()s some entries, so a pid that exits between
|
||||||
|
/// readdir and that lstat fails the whole listing. A fresh listing no
|
||||||
|
/// longer holds that pid; a few failures in a row mean a real error.
|
||||||
|
List<FileSystemEntity> _listProcRetrying() {
|
||||||
|
for (var attempt = 1; ; attempt++) {
|
||||||
|
try {
|
||||||
|
return listProc();
|
||||||
|
} on PathNotFoundException {
|
||||||
|
if (attempt >= _listAttempts) rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> portInUse(int port) async {
|
Future<bool> portInUse(int port) async {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -7,6 +7,9 @@ import 'package:path/path.dart' as p;
|
|||||||
|
|
||||||
import 'package:todo/desktop/static_content_type.dart';
|
import 'package:todo/desktop/static_content_type.dart';
|
||||||
import 'package:todo/desktop/wrapper_image_routes.dart';
|
import 'package:todo/desktop/wrapper_image_routes.dart';
|
||||||
|
import 'package:todo/sync/e2e_passphrase_path.dart';
|
||||||
|
|
||||||
|
export 'package:todo/sync/e2e_passphrase_path.dart';
|
||||||
|
|
||||||
export 'wrapper_paths.dart';
|
export 'wrapper_paths.dart';
|
||||||
|
|
||||||
@ -86,6 +89,9 @@ class WrapperServer {
|
|||||||
/// wrappers also serve, which stays opt-in.
|
/// wrappers also serve, which stays opt-in.
|
||||||
bool _todoCredentialsServed = false;
|
bool _todoCredentialsServed = false;
|
||||||
|
|
||||||
|
/// Whether [kSyncE2ePassphrasePath] has served the passphrase yet.
|
||||||
|
bool _e2ePassphraseServed = false;
|
||||||
|
|
||||||
/// `todo`'s own seeded Firebase session, written by
|
/// `todo`'s own seeded Firebase session, written by
|
||||||
/// `crdt-sync/tool/seed_session.py --app todo` in the same
|
/// `crdt-sync/tool/seed_session.py --app todo` in the same
|
||||||
/// `{id_token, refresh_token, expires_at}` shape every other app's
|
/// `{id_token, refresh_token, expires_at}` shape every other app's
|
||||||
@ -184,6 +190,9 @@ class WrapperServer {
|
|||||||
if (path == kSyncCredentialsPath) {
|
if (path == kSyncCredentialsPath) {
|
||||||
return await _syncCredentials(request);
|
return await _syncCredentials(request);
|
||||||
}
|
}
|
||||||
|
if (path == kSyncE2ePassphrasePath) {
|
||||||
|
return await _syncE2ePassphrase(request);
|
||||||
|
}
|
||||||
if (await images.handle(request)) return;
|
if (await images.handle(request)) return;
|
||||||
return await _static(request, path);
|
return await _static(request, path);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,4 +121,23 @@ extension _SyncRoutes on WrapperServer {
|
|||||||
// through must remain retryable rather than burning the one serve.
|
// through must remain retryable rather than burning the one serve.
|
||||||
_todoCredentialsServed = true;
|
_todoCredentialsServed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serves the shared crdt-sync password as the E2E passphrase, once per
|
||||||
|
/// wrapper process, like [_syncCredentials]: the web app stores it in its
|
||||||
|
/// keystore on first sync and never asks for it.
|
||||||
|
Future<void> _syncE2ePassphrase(HttpRequest request) async {
|
||||||
|
final passwordFile = File(p.join(syncConfigDir, 'password'));
|
||||||
|
if (_e2ePassphraseServed || !passwordFile.existsSync()) {
|
||||||
|
request.response.statusCode = HttpStatus.notFound;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final text = (await passwordFile.readAsString()).trim();
|
||||||
|
if (text.isEmpty) {
|
||||||
|
request.response.statusCode = HttpStatus.notFound;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
request.response.headers.contentType = ContentType.text;
|
||||||
|
request.response.write(text);
|
||||||
|
_e2ePassphraseServed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
// App bootstrap: opens the platform's note store and calls runApp. Exercised
|
// App bootstrap: opens the platform's note store and calls runApp. Exercised
|
||||||
// end-to-end by running the app, not unit tests.
|
// end-to-end by running the app, not unit tests.
|
||||||
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart'
|
||||||
|
show AppErrors, AppErrorsConfig, AppErrorsRouteObserver, installAppErrors;
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:todo/analytics/analytics_service.dart';
|
import 'package:todo/analytics/analytics_service.dart';
|
||||||
import 'package:todo/attachments/image_store.dart';
|
import 'package:todo/attachments/image_store.dart';
|
||||||
import 'package:todo/attachments/image_store_scope.dart';
|
import 'package:todo/attachments/image_store_scope.dart';
|
||||||
@ -10,16 +12,36 @@ import 'package:todo/data/app_settings.dart';
|
|||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
import 'package:todo/data/repository_factory.dart';
|
import 'package:todo/data/repository_factory.dart';
|
||||||
import 'package:todo/frame_stats.dart';
|
import 'package:todo/frame_stats.dart';
|
||||||
|
import 'package:todo/sync/firebase_client.dart' show openFirebase;
|
||||||
import 'package:todo/ui/capture_screen.dart';
|
import 'package:todo/ui/capture_screen.dart';
|
||||||
|
import 'package:todo/ui/text_free_localizations.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
// Every error and every wait over 1 s goes to the PC's app-errors ingest,
|
||||||
|
// which files a board ticket (kuhyx/utils DOCS-app-errors.md). The release
|
||||||
|
// build passes the versionCode and name as dart-defines (release-apk.yml).
|
||||||
|
final errors = await installAppErrors(
|
||||||
|
const AppErrorsConfig(
|
||||||
|
app: 'todo',
|
||||||
|
repo: 'kuhyx/todo-app',
|
||||||
|
package: 'todo',
|
||||||
|
// 0 unless the build passes --dart-define=APP_BUILD.
|
||||||
|
// ignore: avoid_redundant_argument_values
|
||||||
|
build: int.fromEnvironment('APP_BUILD'),
|
||||||
|
version: String.fromEnvironment('APP_VERSION'),
|
||||||
|
),
|
||||||
|
);
|
||||||
installFrameStats();
|
installFrameStats();
|
||||||
|
|
||||||
// Where the log lives, and whether a legacy sqlite DB needs importing, is
|
// Where the log lives, and whether a legacy sqlite DB needs importing, is
|
||||||
// platform-specific and resolved by a conditional import: `dart:io` cannot be
|
// platform-specific and resolved by a conditional import: `dart:io` cannot be
|
||||||
// imported at all in a web compile, and the desktop app is now a web build.
|
// imported at all in a web compile, and the desktop app is now a web build.
|
||||||
final repository = await openRepository();
|
final repository = await openRepository();
|
||||||
|
errors.connect(
|
||||||
|
sink: () async => (await openFirebase())?.patchValues,
|
||||||
|
deviceId: () async => repository.nodeId,
|
||||||
|
);
|
||||||
final appSettings = ValueNotifier(await AppSettings.load());
|
final appSettings = ValueNotifier(await AppSettings.load());
|
||||||
final analytics = AnalyticsService(nodeId: repository.nodeId);
|
final analytics = AnalyticsService(nodeId: repository.nodeId);
|
||||||
// App storage + direct dufs on Android; the wrapper's /images on desktop.
|
// App storage + direct dufs on Android; the wrapper's /images on desktop.
|
||||||
@ -31,6 +53,7 @@ Future<void> main() async {
|
|||||||
appSettings: appSettings,
|
appSettings: appSettings,
|
||||||
analytics: analytics,
|
analytics: analytics,
|
||||||
imageStore: imageStore,
|
imageStore: imageStore,
|
||||||
|
errors: errors,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -45,6 +68,7 @@ class TodoApp extends StatelessWidget {
|
|||||||
required this.appSettings,
|
required this.appSettings,
|
||||||
required this.analytics,
|
required this.analytics,
|
||||||
required this.imageStore,
|
required this.imageStore,
|
||||||
|
this.errors,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,6 +86,9 @@ class TodoApp extends StatelessWidget {
|
|||||||
/// The single, app-wide store for attached images.
|
/// The single, app-wide store for attached images.
|
||||||
final ImageStore imageStore;
|
final ImageStore imageStore;
|
||||||
|
|
||||||
|
/// App-wide error reporting; null in widget tests.
|
||||||
|
final AppErrors? errors;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Above MaterialApp so pushed routes (note detail) see it too.
|
// Above MaterialApp so pushed routes (note detail) see it too.
|
||||||
@ -69,8 +96,12 @@ class TodoApp extends StatelessWidget {
|
|||||||
store: imageStore,
|
store: imageStore,
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
title: 'todo',
|
title: 'todo',
|
||||||
|
localizationsDelegates: kTextFreeLocalizations,
|
||||||
theme: buildLightTheme(),
|
theme: buildLightTheme(),
|
||||||
darkTheme: buildDarkTheme(),
|
darkTheme: buildDarkTheme(),
|
||||||
|
navigatorObservers: [
|
||||||
|
if (errors case final errors?) AppErrorsRouteObserver(errors),
|
||||||
|
],
|
||||||
home: CaptureScreen(
|
home: CaptureScreen(
|
||||||
repository: repository,
|
repository: repository,
|
||||||
appSettings: appSettings,
|
appSettings: appSettings,
|
||||||
|
|||||||
40
lib/mcp/request_guard.dart
Normal file
40
lib/mcp/request_guard.dart
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
/// Answers 503 here because the library can only say 403 for a refusal; it
|
||||||
|
/// then fails to write its own 403 ("Header already sent", swallowed by the
|
||||||
|
/// zone guard in `TodoMcpServer.start`) and the request stays refused.
|
||||||
|
bool answerUnavailable(HttpRequest request) {
|
||||||
|
request.response
|
||||||
|
..statusCode = HttpStatus.serviceUnavailable
|
||||||
|
..write('Service Unavailable')
|
||||||
|
..close().ignore();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Closes [request]'s response with 503 once [deadline] passes, unless it was
|
||||||
|
/// answered first. Safe on any state: a response already closed or a dead
|
||||||
|
/// socket is ignored.
|
||||||
|
void guardDeadline(HttpRequest request, Duration deadline) {
|
||||||
|
if (request.method == 'GET') return;
|
||||||
|
final response = request.response;
|
||||||
|
final timer = Timer(deadline, () async {
|
||||||
|
try {
|
||||||
|
response
|
||||||
|
..statusCode = HttpStatus.serviceUnavailable
|
||||||
|
..write('Request timed out');
|
||||||
|
} on Object {
|
||||||
|
// Headers already sent: just end the stream.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await response.close();
|
||||||
|
} on Object {
|
||||||
|
// The peer is gone; the socket is released either way.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
unawaited(
|
||||||
|
response.done
|
||||||
|
.then<void>((_) {}, onError: (_) {})
|
||||||
|
.whenComplete(timer.cancel),
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:todo/cli/cli_args.dart';
|
import 'package:todo/cli/cli_args.dart';
|
||||||
import 'package:todo/cli/cli_session.dart';
|
import 'package:todo/cli/cli_session.dart';
|
||||||
import 'package:todo/cli/note_lookup.dart';
|
import 'package:todo/cli/note_lookup.dart';
|
||||||
@ -6,39 +8,71 @@ import 'package:todo/data/note_repository.dart';
|
|||||||
import 'package:todo/data/repo_note.dart';
|
import 'package:todo/data/repo_note.dart';
|
||||||
import 'package:todo/mcp/board_client.dart';
|
import 'package:todo/mcp/board_client.dart';
|
||||||
import 'package:todo/mcp/task_split.dart';
|
import 'package:todo/mcp/task_split.dart';
|
||||||
|
import 'package:todo/sync/sync_service.dart';
|
||||||
|
|
||||||
/// The six task tools over one persistent sync node; calls run one at a time.
|
/// The six task tools over one persistent sync node; calls run one at a time.
|
||||||
class TaskService {
|
class TaskService {
|
||||||
/// Serves [_session]'s notes; every call pulls first, writes then push.
|
/// Serves [_session]'s notes; every call pulls first, writes then push.
|
||||||
/// [board] is the todoImplementer board `new_note` checks and starts on.
|
/// [board] is the todoImplementer board `new_note` checks and starts on.
|
||||||
TaskService(this._session, {this._board});
|
///
|
||||||
|
/// A call that outlives [callTimeout] (a sync stuck on a dead connection)
|
||||||
|
/// fails with a TimeoutException instead of holding every later call, so
|
||||||
|
/// the queue never wedges and abandoned requests do not pile up sockets.
|
||||||
|
TaskService(
|
||||||
|
this._session, {
|
||||||
|
this._board,
|
||||||
|
this.callTimeout = const Duration(seconds: 60),
|
||||||
|
this.readFreshness = const Duration(seconds: 2),
|
||||||
|
});
|
||||||
|
|
||||||
final CliSession _session;
|
final CliSession _session;
|
||||||
final BoardClient? _board;
|
final BoardClient? _board;
|
||||||
|
|
||||||
|
/// Longest one call may run before it fails with a TimeoutException.
|
||||||
|
final Duration callTimeout;
|
||||||
|
|
||||||
|
/// How long a finished sync still counts for the read calls (list, search,
|
||||||
|
/// get). The board reads 15 times per fetch and each sync is a Firebase
|
||||||
|
/// round trip of 0.5-1 s, so reads inside the window skip it; every write
|
||||||
|
/// still pulls and pushes. [Duration.zero] syncs on every read.
|
||||||
|
final Duration readFreshness;
|
||||||
|
final Stopwatch _since = Stopwatch();
|
||||||
Future<void> _tail = Future.value();
|
Future<void> _tail = Future.value();
|
||||||
|
|
||||||
Future<T> _serial<T>(Future<T> Function() body) {
|
Future<T> _serial<T>(Future<T> Function() body) {
|
||||||
final run = _tail.then((_) => body());
|
final run = _tail.then((_) => body()).timeout(callTimeout);
|
||||||
_tail = run.then((_) {}, onError: (_) {});
|
_tail = run.then((_) {}, onError: (_) {});
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Note>> _pull() async {
|
Future<SyncResult> _sync() async {
|
||||||
final skipped = (await _session.sync(push: true)).skippedFiles;
|
final result = await _session.sync(push: true);
|
||||||
if (skipped.isNotEmpty) throw StateError('sync: unmergeable $skipped');
|
_since
|
||||||
|
..reset()
|
||||||
|
..start();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pulls every peer, unless [read] and a sync ended within [readFreshness].
|
||||||
|
Future<List<Note>> _pull({bool read = false}) async {
|
||||||
|
final fresh = _since.isRunning && _since.elapsed < readFreshness;
|
||||||
|
if (!read || !fresh) {
|
||||||
|
final skipped = (await _sync()).skippedFiles;
|
||||||
|
if (skipped.isNotEmpty) throw StateError('sync: unmergeable $skipped');
|
||||||
|
}
|
||||||
return await _session.repository.listNotes();
|
return await _session.repository.listNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _save(Note note, String verb) async {
|
Future<String> _save(Note note, String verb) async {
|
||||||
await _session.repository.upsert(note.copyWith(updatedAt: DateTime.now()));
|
await _session.repository.upsert(note.copyWith(updatedAt: DateTime.now()));
|
||||||
await _session.sync(push: true);
|
await _sync();
|
||||||
return '$verb ${note.id}\n${listLine(note)}';
|
return '$verb ${note.id}\n${listLine(note)}';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Note> _find(_Args a) async {
|
Future<Note> _find(_Args a, {bool read = false}) async {
|
||||||
final id = a.required('id');
|
final id = a.required('id');
|
||||||
try {
|
try {
|
||||||
return findNote(await _pull(), id);
|
return findNote(await _pull(read: read), id);
|
||||||
} on NoteLookupError catch (e) {
|
} on NoteLookupError catch (e) {
|
||||||
throw FormatException('id: $e');
|
throw FormatException('id: $e');
|
||||||
}
|
}
|
||||||
@ -82,23 +116,24 @@ class TaskService {
|
|||||||
return (reply: await _save(added.note, verb), start: null);
|
return (reply: await _save(added.note, verb), start: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `list_tasks`: repo tasks, open ones unless `status` says otherwise.
|
/// `list_tasks`: repo tasks, open ones unless `status` says otherwise;
|
||||||
|
/// `no_repo: true` lists the repo-less notes (ideas) instead.
|
||||||
Future<String> list(Map<String, dynamic> args) => _serial(() async {
|
Future<String> list(Map<String, dynamic> args) => _serial(() async {
|
||||||
final a = _Args(args);
|
final a = _Args(args);
|
||||||
final repo = a.repo();
|
final repo = a.repo();
|
||||||
final statuses = a.statuses();
|
final statuses = a.statuses();
|
||||||
await _pull();
|
final ideas = a.flag('no_repo');
|
||||||
return _lines(
|
await _pull(read: true);
|
||||||
await _session.repository.listNotes(
|
final notes = await _session.repository.listNotes(
|
||||||
filter: NoteFilter(statuses: statuses, repo: repo, repoTasksOnly: true),
|
filter: NoteFilter(statuses: statuses, repo: repo, repoTasksOnly: !ideas),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
return _lines(ideas ? notes.where((n) => n.repo == null).toList() : notes);
|
||||||
});
|
});
|
||||||
|
|
||||||
/// `search_tasks`: repo tasks of any status whose text or repo matches.
|
/// `search_tasks`: repo tasks of any status whose text or repo matches.
|
||||||
Future<String> search(Map<String, dynamic> args) => _serial(() async {
|
Future<String> search(Map<String, dynamic> args) => _serial(() async {
|
||||||
final query = _Args(args).required('query');
|
final query = _Args(args).required('query');
|
||||||
await _pull();
|
await _pull(read: true);
|
||||||
return _lines(
|
return _lines(
|
||||||
await _session.repository.listNotes(
|
await _session.repository.listNotes(
|
||||||
filter: NoteFilter(query: query, repoTasksOnly: true),
|
filter: NoteFilter(query: query, repoTasksOnly: true),
|
||||||
@ -108,7 +143,7 @@ class TaskService {
|
|||||||
|
|
||||||
/// `get_task`: one note in full.
|
/// `get_task`: one note in full.
|
||||||
Future<String> get(Map<String, dynamic> args) =>
|
Future<String> get(Map<String, dynamic> args) =>
|
||||||
_serial(() async => noteDetail(await _find(_Args(args))));
|
_serial(() async => noteDetail(await _find(_Args(args), read: true)));
|
||||||
|
|
||||||
/// `update_task`: changes only the keys given; `done_check: ""` clears it.
|
/// `update_task`: changes only the keys given; `done_check: ""` clears it.
|
||||||
Future<String> update(Map<String, dynamic> args) => _serial(() async {
|
Future<String> update(Map<String, dynamic> args) => _serial(() async {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:mcp_dart/mcp_dart.dart';
|
import 'package:mcp_dart/mcp_dart.dart';
|
||||||
|
import 'package:todo/mcp/request_guard.dart';
|
||||||
import 'package:todo/mcp/task_service.dart';
|
import 'package:todo/mcp/task_service.dart';
|
||||||
import 'package:todo/mcp/token_file.dart';
|
import 'package:todo/mcp/token_file.dart';
|
||||||
|
|
||||||
@ -34,26 +36,50 @@ class TodoMcpServer {
|
|||||||
/// `http://<host>:<bound port>/mcp`.
|
/// `http://<host>:<bound port>/mcp`.
|
||||||
Uri get uri => Uri.parse('http://${_http.host}:${_http.boundPort}/mcp');
|
Uri get uri => Uri.parse('http://${_http.host}:${_http.boundPort}/mcp');
|
||||||
|
|
||||||
/// Binds [host]:[port] (0 = any free port); [tokens] is read per request.
|
/// Binds [host]:[port] (0 = any free port); [tokens] is loaded once and
|
||||||
|
/// re-read when its mtime changes, errors going to [log] (default stderr).
|
||||||
|
///
|
||||||
|
/// A POST or DELETE that has no answer after [requestDeadline] is closed
|
||||||
|
/// with 503, which also frees its socket when the client already gave up
|
||||||
|
/// (Dart's HttpServer never notices a half-closed idle request). Keep it
|
||||||
|
/// above [TaskService.callTimeout] so a stuck tool call reports its own
|
||||||
|
/// error first. GET streams are long-lived by design and exempt.
|
||||||
static Future<TodoMcpServer> start({
|
static Future<TodoMcpServer> start({
|
||||||
required TaskService tasks,
|
required TaskService tasks,
|
||||||
required File tokens,
|
required File tokens,
|
||||||
String host = '127.0.0.1',
|
String host = '127.0.0.1',
|
||||||
int port = kTodoMcpPort,
|
int port = kTodoMcpPort,
|
||||||
|
Duration requestDeadline = const Duration(seconds: 90),
|
||||||
|
void Function(String)? log,
|
||||||
}) async {
|
}) async {
|
||||||
|
final out = log ?? (String line) => stderr.writeln(line);
|
||||||
|
final store = TokenStore(tokens, log: out);
|
||||||
final http = StreamableMcpServer(
|
final http = StreamableMcpServer(
|
||||||
serverFactory: (_) => _server(tasks),
|
serverFactory: (_) => _server(tasks),
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
authenticator: (request) => tokenAccepted(
|
authenticator: (request) {
|
||||||
tokens,
|
if (request is! HttpRequest) return false;
|
||||||
request is HttpRequest
|
guardDeadline(request, requestDeadline);
|
||||||
? request.headers.value(HttpHeaders.authorizationHeader)
|
return switch (store.verdict(
|
||||||
: null,
|
request.headers.value(HttpHeaders.authorizationHeader),
|
||||||
),
|
)) {
|
||||||
|
TokenVerdict.accepted => true,
|
||||||
|
TokenVerdict.rejected => false,
|
||||||
|
TokenVerdict.unavailable => answerUnavailable(request),
|
||||||
|
};
|
||||||
|
},
|
||||||
allowedHosts: const {'localhost', '127.0.0.1', '::1', _publicHost},
|
allowedHosts: const {'localhost', '127.0.0.1', '::1', _publicHost},
|
||||||
);
|
);
|
||||||
await http.start();
|
// The library runs each request as an unawaited future in the zone that
|
||||||
|
// called start(): without a guard, one failed write (a response we closed
|
||||||
|
// first) would be an uncaught error and kill the process.
|
||||||
|
await runZonedGuarded(http.start, (error, stack) {
|
||||||
|
if (error is StateError && '$error'.contains('Header already sent')) {
|
||||||
|
return; // the library answering a request we already answered
|
||||||
|
}
|
||||||
|
out('todo-mcp: request error: $error');
|
||||||
|
});
|
||||||
return TodoMcpServer._(http);
|
return TodoMcpServer._(http);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,9 +143,13 @@ McpServer _server(TaskService tasks) {
|
|||||||
'list_tasks',
|
'list_tasks',
|
||||||
'List repo tasks, one line each: 8-char id, status, priority, repo, '
|
'List repo tasks, one line each: 8-char id, status, priority, repo, '
|
||||||
'title, created_by (kuhy|claude). Default status "open" '
|
'title, created_by (kuhy|claude). Default status "open" '
|
||||||
'(todo + in_progress).',
|
'(todo + in_progress). no_repo: true lists the notes WITHOUT a repo '
|
||||||
|
'(ideas) instead.',
|
||||||
{
|
{
|
||||||
'repo': repo,
|
'repo': repo,
|
||||||
|
'no_repo': JsonSchema.boolean(
|
||||||
|
description: 'List only notes that have no repo (repo shows as -).',
|
||||||
|
),
|
||||||
'status': JsonSchema.string(
|
'status': JsonSchema.string(
|
||||||
description: 'open | all | todo | in_progress | done | abandoned.',
|
description: 'open | all | todo | in_progress | done | abandoned.',
|
||||||
),
|
),
|
||||||
|
|||||||
@ -5,27 +5,78 @@ import 'package:crdt_sync/crdt_sync.dart';
|
|||||||
/// sha256 hex of [token] (crdt_sync's `revisionOf` is exactly that).
|
/// sha256 hex of [token] (crdt_sync's `revisionOf` is exactly that).
|
||||||
String tokenHash(String token) => revisionOf(token);
|
String tokenHash(String token) => revisionOf(token);
|
||||||
|
|
||||||
Set<String> _hashes(File tokens) {
|
/// What the tokens file says about one `Authorization` header.
|
||||||
final String text;
|
enum TokenVerdict {
|
||||||
try {
|
/// A listed token: let the request in.
|
||||||
text = tokens.readAsStringSync();
|
accepted,
|
||||||
} on FileSystemException {
|
|
||||||
return const {};
|
/// Missing, malformed or unlisted: HTTP 403.
|
||||||
|
rejected,
|
||||||
|
|
||||||
|
/// No token set has ever loaded, so nothing can be judged: HTTP 503.
|
||||||
|
unavailable,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The sha256-hashed bearer tokens of [file], loaded once.
|
||||||
|
///
|
||||||
|
/// A request costs one `stat`; the file is re-read only when its mtime or
|
||||||
|
/// size changed. A failed read keeps the last good set (an exhausted fd table
|
||||||
|
/// once made every valid token read as "no tokens", i.e. 403) and is logged
|
||||||
|
/// once per distinct error. Until a first good load every well-formed bearer
|
||||||
|
/// is [TokenVerdict.unavailable], never a refusal.
|
||||||
|
class TokenStore {
|
||||||
|
/// Watches [file]; [log] gets read errors.
|
||||||
|
TokenStore(this.file, {required this.log});
|
||||||
|
|
||||||
|
/// The `<sha256> <name>` lines, `#` comments allowed.
|
||||||
|
final File file;
|
||||||
|
|
||||||
|
/// Receives read errors, one line each.
|
||||||
|
final void Function(String) log;
|
||||||
|
|
||||||
|
Set<String>? _hashes;
|
||||||
|
(DateTime, int)? _seen;
|
||||||
|
String? _lastError;
|
||||||
|
|
||||||
|
/// Judges [authorization] (an `Authorization` header value or null).
|
||||||
|
TokenVerdict verdict(String? authorization) {
|
||||||
|
const scheme = 'bearer ';
|
||||||
|
if (authorization == null ||
|
||||||
|
!authorization.toLowerCase().startsWith(scheme)) {
|
||||||
|
return TokenVerdict.rejected;
|
||||||
|
}
|
||||||
|
final token = authorization.substring(scheme.length).trim();
|
||||||
|
if (token.isEmpty) return TokenVerdict.rejected;
|
||||||
|
_refresh();
|
||||||
|
final hashes = _hashes;
|
||||||
|
if (hashes == null) return TokenVerdict.unavailable;
|
||||||
|
return hashes.contains(tokenHash(token))
|
||||||
|
? TokenVerdict.accepted
|
||||||
|
: TokenVerdict.rejected;
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
|
void _refresh() {
|
||||||
|
try {
|
||||||
|
final stat = file.statSync();
|
||||||
|
if (stat.type == FileSystemEntityType.notFound) {
|
||||||
|
throw FileSystemException('no such file', file.path);
|
||||||
|
}
|
||||||
|
final key = (stat.modified, stat.size);
|
||||||
|
if (key == _seen) return;
|
||||||
|
_hashes = _parse(file.readAsStringSync());
|
||||||
|
_seen = key;
|
||||||
|
_lastError = null;
|
||||||
|
} on FileSystemException catch (e) {
|
||||||
|
// Keep the last good set; `_seen` stays, so the next request retries.
|
||||||
|
final message = '${e.message} ${e.path} ${e.osError?.errorCode}';
|
||||||
|
if (message != _lastError) log('tokens: keeping last set: $message');
|
||||||
|
_lastError = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Set<String> _parse(String text) => {
|
||||||
for (final line in text.split('\n'))
|
for (final line in text.split('\n'))
|
||||||
if (line.trim() case final t when t.isNotEmpty && !t.startsWith('#'))
|
if (line.trim() case final t when t.isNotEmpty && !t.startsWith('#'))
|
||||||
t.split(RegExp(r'\s+')).first.toLowerCase(),
|
t.split(RegExp(r'\s+')).first.toLowerCase(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether [authorization] bears a token hashed in [tokens], read per call.
|
|
||||||
bool tokenAccepted(File tokens, String? authorization) {
|
|
||||||
const scheme = 'bearer ';
|
|
||||||
if (authorization == null ||
|
|
||||||
!authorization.toLowerCase().startsWith(scheme)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final token = authorization.substring(scheme.length).trim();
|
|
||||||
return token.isNotEmpty && _hashes(tokens).contains(tokenHash(token));
|
|
||||||
}
|
|
||||||
|
|||||||
9
lib/sync/e2e_passphrase_path.dart
Normal file
9
lib/sync/e2e_passphrase_path.dart
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/// Path of the wrapper's one-shot passphrase route.
|
||||||
|
///
|
||||||
|
/// Kept apart from `e2e_passphrase_source.dart` (which needs Flutter) so the
|
||||||
|
/// dart-only desktop wrapper can import it; `dart build cli` fails on any
|
||||||
|
/// transitive `dart:ui`.
|
||||||
|
library;
|
||||||
|
|
||||||
|
/// The route the wrapper serves the passphrase on, once.
|
||||||
|
const kSyncE2ePassphrasePath = '/sync-e2e-passphrase';
|
||||||
38
lib/sync/e2e_passphrase_source.dart
Normal file
38
lib/sync/e2e_passphrase_source.dart
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/// Where todo gets the shared crdt-sync passphrase its E2E key comes from.
|
||||||
|
///
|
||||||
|
/// The keystore first. On the desktop (a web build behind the local
|
||||||
|
/// wrapper) an empty keystore adopts the wrapper's one-shot
|
||||||
|
/// `/sync-e2e-passphrase` route, which serves `~/.config/crdt-sync/password`,
|
||||||
|
/// so the desktop app never asks. Android has no wrapper (`Uri.base` is
|
||||||
|
/// `file:///`) and is unlocked through the settings lock tile instead.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart'
|
||||||
|
show kE2ePassphraseKey, kSecureStorage, saveE2ePassphrase;
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:todo/sync/e2e_passphrase_path.dart';
|
||||||
|
|
||||||
|
export 'package:todo/sync/e2e_passphrase_path.dart';
|
||||||
|
|
||||||
|
/// Returns the passphrase, adopting the wrapper's once; null when none.
|
||||||
|
Future<String?> readE2ePassphrase({Uri? base, http.Client? client}) async {
|
||||||
|
final stored = await kSecureStorage.read(key: kE2ePassphraseKey);
|
||||||
|
if (stored != null && stored.isNotEmpty) return stored;
|
||||||
|
final origin = base ?? Uri.base;
|
||||||
|
if (origin.scheme != 'http' && origin.scheme != 'https') return null;
|
||||||
|
final httpClient = client ?? http.Client();
|
||||||
|
try {
|
||||||
|
final response = await httpClient.get(
|
||||||
|
origin.resolve(kSyncE2ePassphrasePath),
|
||||||
|
);
|
||||||
|
final text = response.body.trim();
|
||||||
|
if (response.statusCode != 200 || text.isEmpty) return null;
|
||||||
|
await saveE2ePassphrase(text);
|
||||||
|
return text;
|
||||||
|
} on Object {
|
||||||
|
// No wrapper, or it already served: this device is simply locked.
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (client == null) httpClient.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
7
lib/sync/off_thread.dart
Normal file
7
lib/sync/off_thread.dart
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/// Runs CPU-heavy, pure work away from the UI thread where the platform can.
|
||||||
|
///
|
||||||
|
/// Conditional export because `dart:isolate` does not run in a browser: the
|
||||||
|
/// web desktop build runs the work inline, everything else on a fresh isolate.
|
||||||
|
library;
|
||||||
|
|
||||||
|
export 'off_thread_io.dart' if (dart.library.js_interop) 'off_thread_web.dart';
|
||||||
7
lib/sync/off_thread_io.dart
Normal file
7
lib/sync/off_thread_io.dart
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
|
/// Runs [work] on a short-lived isolate and returns its result.
|
||||||
|
///
|
||||||
|
/// The result comes back through `Isolate.exit`, so a large parsed log is
|
||||||
|
/// handed over rather than copied.
|
||||||
|
Future<R> offThread<R>(R Function() work) => Isolate.run(work);
|
||||||
2
lib/sync/off_thread_web.dart
Normal file
2
lib/sync/off_thread_web.dart
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/// Runs [work] inline: a browser has no isolates for it.
|
||||||
|
Future<R> offThread<R>(R Function() work) async => work();
|
||||||
78
lib/sync/peer_pull.dart
Normal file
78
lib/sync/peer_pull.dart
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/// Pulls the peers whose logs changed, all at once and off the UI thread.
|
||||||
|
///
|
||||||
|
/// Split out of `sync_service.dart` for file size. A peer's log is about
|
||||||
|
/// 2 MB; pulling eight of them one after another, each parsed on the UI
|
||||||
|
/// isolate, kept the phone's sync spinner up for 3.9 s (todo:0c575b891b).
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
|
import 'package:todo/sync/off_thread.dart';
|
||||||
|
|
||||||
|
/// One peer file's pull result: its decoded [log] and revision, or a null
|
||||||
|
/// [log] when the file vanished, failed decryption or did not parse.
|
||||||
|
typedef PulledPeer = ({String name, String peer, Log? log, String? rev});
|
||||||
|
|
||||||
|
/// Fetches [names] (file names under [dir]) concurrently.
|
||||||
|
///
|
||||||
|
/// [knownRevs] holds each peer's published revision; a peer without one gets
|
||||||
|
/// its revision computed from the downloaded text. Any failure other than an
|
||||||
|
/// [E2eDecryptError] fails the pull, exactly as a sequential loop would.
|
||||||
|
Future<List<PulledPeer>> pullPeers(
|
||||||
|
RemoteStore remote,
|
||||||
|
String dir,
|
||||||
|
List<String> names,
|
||||||
|
Map<String, String> knownRevs,
|
||||||
|
) => Future.wait([
|
||||||
|
for (final name in names) _pull(remote, dir, name, knownRevs[peerOf(name)]),
|
||||||
|
], eagerError: true);
|
||||||
|
|
||||||
|
/// Peer id of a `<peer>.json` file name.
|
||||||
|
String peerOf(String name) =>
|
||||||
|
name.endsWith('.json') ? name.substring(0, name.length - 5) : name;
|
||||||
|
|
||||||
|
Future<PulledPeer> _pull(
|
||||||
|
RemoteStore remote,
|
||||||
|
String dir,
|
||||||
|
String name,
|
||||||
|
String? knownRev,
|
||||||
|
) async {
|
||||||
|
final peer = peerOf(name);
|
||||||
|
final String? text;
|
||||||
|
try {
|
||||||
|
text = await remote.getFileText('$dir/$name');
|
||||||
|
} on E2eDecryptError {
|
||||||
|
// Wrong key, tampered blob or a newer format: skipped and reported,
|
||||||
|
// never merged and never fatal.
|
||||||
|
return (name: name, peer: peer, log: null, rev: null);
|
||||||
|
}
|
||||||
|
if (text == null) return (name: name, peer: peer, log: null, rev: null);
|
||||||
|
final (log, rev) = await _decodeOffThread(text, knownRev);
|
||||||
|
return (name: name, peer: peer, log: log, rev: rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Below this many characters a log parses faster than an isolate starts.
|
||||||
|
const int _offThreadMinLength = 64 * 1024;
|
||||||
|
|
||||||
|
/// Kept separate so the isolate closure captures only [text] and [knownRev].
|
||||||
|
Future<(Log?, String)> _decodeOffThread(String text, String? knownRev) async {
|
||||||
|
(Log?, String) decode() => (decodeLog(text), knownRev ?? revisionOf(text));
|
||||||
|
return text.length < _offThreadMinLength ? decode() : await offThread(decode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a remote note log, returning `null` for a corrupt or wrong-shape
|
||||||
|
/// payload so one bad device file never aborts the whole sync.
|
||||||
|
Log? decodeLog(String text) {
|
||||||
|
try {
|
||||||
|
return logFromJson(text);
|
||||||
|
} on FormatException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// crdt_sync's logFromJson throws a raw TypeError (not a custom
|
||||||
|
// exception) for a wrong-shape JSON payload from an untrusted peer
|
||||||
|
// file; must be caught too so one bad device file never aborts the
|
||||||
|
// whole sync (see doc comment above).
|
||||||
|
// ignore: avoid_catching_errors
|
||||||
|
on TypeError {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,15 +7,26 @@
|
|||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show keystoreKeyCache;
|
||||||
|
import 'package:flutter/foundation.dart' show ValueNotifier, visibleForTesting;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:todo/analytics/analytics_service.dart';
|
import 'package:todo/analytics/analytics_service.dart';
|
||||||
import 'package:todo/data/app_settings.dart';
|
import 'package:todo/data/app_settings.dart';
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
|
import 'package:todo/sync/e2e_passphrase_source.dart';
|
||||||
import 'package:todo/sync/firebase_backend.dart';
|
import 'package:todo/sync/firebase_backend.dart';
|
||||||
import 'package:todo/sync/sync_service.dart';
|
import 'package:todo/sync/sync_service.dart';
|
||||||
import 'package:todo/sync/sync_settings.dart';
|
import 'package:todo/sync/sync_settings.dart';
|
||||||
import 'package:todo/sync/sync_state_factory.dart';
|
import 'package:todo/sync/sync_state_factory.dart';
|
||||||
|
|
||||||
|
/// Argon2id cost for new headers; only tests lower it.
|
||||||
|
@visibleForTesting
|
||||||
|
Argon2Params e2eArgon2Params = Argon2Params.recommended;
|
||||||
|
|
||||||
|
/// Whether the last sync found no usable end-to-end key; drives the lock
|
||||||
|
/// tile in settings.
|
||||||
|
final ValueNotifier<bool> e2eLocked = ValueNotifier<bool>(false);
|
||||||
|
|
||||||
/// Bundles a [SyncResult] with the [AppSettings] as reconciled against the
|
/// Bundles a [SyncResult] with the [AppSettings] as reconciled against the
|
||||||
/// same Firebase session — so a settings change made on another device is
|
/// same Firebase session — so a settings change made on another device is
|
||||||
/// picked up without a second authenticated round trip.
|
/// picked up without a second authenticated round trip.
|
||||||
@ -44,8 +55,12 @@ class SyncRunResult {
|
|||||||
/// rather than each concern (notes, settings, analytics) opening and
|
/// rather than each concern (notes, settings, analytics) opening and
|
||||||
/// closing its own.
|
/// closing its own.
|
||||||
///
|
///
|
||||||
/// [firebaseFactory] and [stateStore] exist for tests, which must not reach
|
/// [firebaseFactory], [stateStore] and [readPassphrase] exist for tests, which
|
||||||
/// the OS keystore or an application-support directory.
|
/// must not reach the OS keystore or an application-support directory.
|
||||||
|
///
|
||||||
|
/// Everything pushed is end-to-end encrypted under the shared crdt-sync
|
||||||
|
/// passphrase; without a usable key the run is a no-op flagged
|
||||||
|
/// [SyncResult.locked] rather than a plaintext sync.
|
||||||
Future<SyncRunResult> runSync(
|
Future<SyncRunResult> runSync(
|
||||||
NoteRepository repository,
|
NoteRepository repository,
|
||||||
SyncSettings settings, {
|
SyncSettings settings, {
|
||||||
@ -54,6 +69,7 @@ Future<SyncRunResult> runSync(
|
|||||||
http.Client? httpClient,
|
http.Client? httpClient,
|
||||||
Future<FirebaseRestClient?> Function()? firebaseFactory,
|
Future<FirebaseRestClient?> Function()? firebaseFactory,
|
||||||
SyncStateStore? stateStore,
|
SyncStateStore? stateStore,
|
||||||
|
Future<String?> Function()? readPassphrase,
|
||||||
}) async {
|
}) async {
|
||||||
final github = GitHubClient(
|
final github = GitHubClient(
|
||||||
owner: settings.owner,
|
owner: settings.owner,
|
||||||
@ -72,16 +88,48 @@ Future<SyncRunResult> runSync(
|
|||||||
stateStore: stateStore ?? await openSyncStateStore(),
|
stateStore: stateStore ?? await openSyncStateStore(),
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
);
|
);
|
||||||
final result = await service.sync(
|
// No GitHub token means nothing to mirror: an unconfigured client still
|
||||||
repository,
|
// spends two round trips per call on 404s.
|
||||||
firebase == null
|
final backend = switch (firebase) {
|
||||||
? github
|
null => github,
|
||||||
: MirrorStore(primary: firebase, mirror: github),
|
_ when !settings.isConfigured => firebase,
|
||||||
|
_ => MirrorStore(primary: firebase, mirror: github),
|
||||||
|
};
|
||||||
|
final e2e = await openEncryptedStore(
|
||||||
|
store: backend,
|
||||||
|
oldPrefix: service.notesDir,
|
||||||
|
readPassphrase: readPassphrase ?? readE2ePassphrase,
|
||||||
|
params: e2eArgon2Params,
|
||||||
|
// Argon2id once per device, not once per tick.
|
||||||
|
keyCache: keystoreKeyCache(service.notesDir),
|
||||||
);
|
);
|
||||||
await analytics?.flush(firebase);
|
e2eLocked.value = e2e is! E2eReady;
|
||||||
|
if (e2e is! E2eReady) {
|
||||||
|
return const SyncRunResult(
|
||||||
|
syncResult: SyncResult(mergedDevices: 0, pushed: false, locked: true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final layout = E2eLayout.of(service.notesDir);
|
||||||
|
// Settings and analytics touch other Firebase paths than the notes, so
|
||||||
|
// they ride alongside the note sync instead of after it.
|
||||||
|
final reconciled = appSettings?.reconcileWithRemote(firebase);
|
||||||
|
final flushed = analytics?.flush(firebase);
|
||||||
|
final notes = SyncService(
|
||||||
|
notesDir: layout.prefix,
|
||||||
|
revsPath: layout.revsPath,
|
||||||
|
stateStore: service.stateStore,
|
||||||
|
).sync(repository, e2e.store);
|
||||||
|
final done = await Future.wait<Object?>([
|
||||||
|
notes,
|
||||||
|
?reconciled,
|
||||||
|
?flushed,
|
||||||
|
// Not eager: the clients are closed below, so nothing may still be in
|
||||||
|
// flight when this returns or throws.
|
||||||
|
]);
|
||||||
|
final result = done.first! as SyncResult;
|
||||||
return SyncRunResult(
|
return SyncRunResult(
|
||||||
syncResult: result.withFirebaseConnected(value: firebase != null),
|
syncResult: result.withFirebaseConnected(value: firebase != null),
|
||||||
appSettings: await appSettings?.reconcileWithRemote(firebase),
|
appSettings: await reconciled,
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
// Close both: unlike the long-lived desktop callers, each screen builds
|
// Close both: unlike the long-lived desktop callers, each screen builds
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
|
import 'package:todo/sync/peer_pull.dart';
|
||||||
|
|
||||||
/// Outcome of a sync run, for surfacing in the UI.
|
/// Outcome of a sync run, for surfacing in the UI.
|
||||||
class SyncResult {
|
class SyncResult {
|
||||||
@ -11,6 +12,7 @@ class SyncResult {
|
|||||||
this.skippedFiles = const [],
|
this.skippedFiles = const [],
|
||||||
this.skippedUnchanged = 0,
|
this.skippedUnchanged = 0,
|
||||||
this.firebaseConnected = false,
|
this.firebaseConnected = false,
|
||||||
|
this.locked = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// How many other devices' logs were pulled and merged.
|
/// How many other devices' logs were pulled and merged.
|
||||||
@ -41,6 +43,10 @@ class SyncResult {
|
|||||||
/// device dropping out.
|
/// device dropping out.
|
||||||
final int skippedUnchanged;
|
final int skippedUnchanged;
|
||||||
|
|
||||||
|
/// True when end-to-end encryption has no usable key on this device, so
|
||||||
|
/// nothing was pulled, merged or pushed.
|
||||||
|
final bool locked;
|
||||||
|
|
||||||
/// Returns a copy with [firebaseConnected] set. [SyncService] never sets
|
/// Returns a copy with [firebaseConnected] set. [SyncService] never sets
|
||||||
/// it -- only [runSync], which is the layer that knows which [RemoteStore]
|
/// it -- only [runSync], which is the layer that knows which [RemoteStore]
|
||||||
/// it built -- so this is the seam that lets it do that without
|
/// it built -- so this is the seam that lets it do that without
|
||||||
@ -51,6 +57,7 @@ class SyncResult {
|
|||||||
skippedFiles: skippedFiles,
|
skippedFiles: skippedFiles,
|
||||||
skippedUnchanged: skippedUnchanged,
|
skippedUnchanged: skippedUnchanged,
|
||||||
firebaseConnected: value,
|
firebaseConnected: value,
|
||||||
|
locked: locked,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -73,7 +80,11 @@ class SyncResult {
|
|||||||
/// two never share a path and an old client can't misread a new file.
|
/// two never share a path and an old client can't misread a new file.
|
||||||
class SyncService {
|
class SyncService {
|
||||||
/// Creates a [SyncService], optionally overriding [notesDir].
|
/// Creates a [SyncService], optionally overriding [notesDir].
|
||||||
const SyncService({this.notesDir = 'todo-sync/notes', this.stateStore});
|
const SyncService({
|
||||||
|
this.notesDir = 'todo-sync/notes',
|
||||||
|
this.stateStore,
|
||||||
|
this.revsPath,
|
||||||
|
});
|
||||||
|
|
||||||
/// Directory in the repo under which per-device note-log files live.
|
/// Directory in the repo under which per-device note-log files live.
|
||||||
final String notesDir;
|
final String notesDir;
|
||||||
@ -87,7 +98,11 @@ class SyncService {
|
|||||||
final SyncStateStore? stateStore;
|
final SyncStateStore? stateStore;
|
||||||
|
|
||||||
/// Where revisions live, as a sibling of [notesDir].
|
/// Where revisions live, as a sibling of [notesDir].
|
||||||
String get revsDir => defaultRevsPath(notesDir);
|
/// Revision cache directory; null derives it from [notesDir].
|
||||||
|
final String? revsPath;
|
||||||
|
|
||||||
|
/// Where peers publish their revisions.
|
||||||
|
String get revsDir => revsPath ?? defaultRevsPath(notesDir);
|
||||||
|
|
||||||
/// Runs a full pull-merge-push cycle. Safe to call repeatedly.
|
/// Runs a full pull-merge-push cycle. Safe to call repeatedly.
|
||||||
///
|
///
|
||||||
@ -99,45 +114,61 @@ class SyncService {
|
|||||||
final ownFileName = '$nodeId.json';
|
final ownFileName = '$nodeId.json';
|
||||||
|
|
||||||
final state = await stateStore?.load() ?? const SyncState();
|
final state = await stateStore?.load() ?? const SyncState();
|
||||||
final remoteRevs = stateStore == null
|
// Independent reads, so one round trip instead of two. eagerError keeps
|
||||||
? const <String, String>{}
|
// the first failure's own type, which callers catch.
|
||||||
: await _revisions(remote);
|
final reads = await Future.wait<Object>([
|
||||||
|
if (stateStore == null)
|
||||||
|
Future.value(const <String, String>{})
|
||||||
|
else
|
||||||
|
_revisions(remote),
|
||||||
|
remote.listDirectory(notesDir),
|
||||||
|
], eagerError: true);
|
||||||
|
final remoteRevs = reads[0] as Map<String, String>;
|
||||||
|
final names = reads[1] as List<String>;
|
||||||
final seenRevs = <String, String>{};
|
final seenRevs = <String, String>{};
|
||||||
|
|
||||||
// 1. Pull: list all device log files, merge everyone else's.
|
// 1. Pull: every other device's log that changed since we merged it.
|
||||||
final names = await remote.listDirectory(notesDir);
|
|
||||||
var merged = 0;
|
|
||||||
var skippedUnchanged = 0;
|
var skippedUnchanged = 0;
|
||||||
final skipped = <String>[];
|
final changed = <String>[];
|
||||||
for (final name in names) {
|
for (final name in names) {
|
||||||
if (name == ownFileName) continue; // our own file; skip it.
|
if (name == ownFileName) continue; // our own file; skip it.
|
||||||
final peer = name.endsWith('.json')
|
final peer = peerOf(name);
|
||||||
? name.substring(0, name.length - 5)
|
|
||||||
: name;
|
|
||||||
final remoteRev = remoteRevs[peer];
|
final remoteRev = remoteRevs[peer];
|
||||||
if (remoteRev != null && remoteRev == state.peerRevs[peer]) {
|
if (remoteRev != null && remoteRev == state.peerRevs[peer]) {
|
||||||
// Unchanged since we last merged it, and that merge is already in the
|
// Unchanged since we last merged it, and that merge is already in the
|
||||||
// local log — so the ~150 KB download is pure waste. Carry the
|
// local log -- so the download is pure waste. Carry the revision
|
||||||
// revision forward so it stays skipped next time.
|
// forward so it stays skipped next time.
|
||||||
seenRevs[peer] = remoteRev;
|
seenRevs[peer] = remoteRev;
|
||||||
skippedUnchanged++;
|
skippedUnchanged++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final text = await remote.getFileText('$notesDir/$name');
|
changed.add(name);
|
||||||
final remoteLog = text == null ? null : _decodeLog(text);
|
}
|
||||||
if (remoteLog == null) {
|
var merged = 0;
|
||||||
// A vanished or undecodable peer file must not abort the sync, but
|
final skipped = <String>[];
|
||||||
// it must not vanish silently either — that's how a device drops
|
Log? incoming;
|
||||||
// out of sync unnoticed. Report it in the result instead.
|
for (final pulled in await pullPeers(
|
||||||
// Deliberately not recorded as seen: a corrupt push must be retried
|
remote,
|
||||||
// next run, not remembered as merged.
|
notesDir,
|
||||||
skipped.add(name);
|
changed,
|
||||||
|
remoteRevs,
|
||||||
|
)) {
|
||||||
|
final log = pulled.log;
|
||||||
|
if (log == null) {
|
||||||
|
// A vanished, undecryptable or undecodable peer file must not abort
|
||||||
|
// the sync, but it must not vanish silently either -- that's how a
|
||||||
|
// device drops out of sync unnoticed. Reported, and deliberately not
|
||||||
|
// recorded as seen: a corrupt push must be retried next run.
|
||||||
|
skipped.add(pulled.name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await repo.importLog(remoteLog);
|
// Peers merge with each other first (commutative, idempotent), so the
|
||||||
seenRevs[peer] = remoteRev ?? revisionOf(text!);
|
// local store is rewritten once rather than once per peer.
|
||||||
|
incoming = incoming == null ? log : mergeLogs(incoming, log);
|
||||||
|
seenRevs[pulled.peer] = pulled.rev!;
|
||||||
merged++;
|
merged++;
|
||||||
}
|
}
|
||||||
|
if (incoming != null) await repo.importLog(incoming);
|
||||||
|
|
||||||
// 2. Push: upload our own (now-merged) log under our node id.
|
// 2. Push: upload our own (now-merged) log under our node id.
|
||||||
// putFileText resolves our file's current sha itself.
|
// putFileText resolves our file's current sha itself.
|
||||||
@ -184,22 +215,4 @@ class SyncService {
|
|||||||
if (remote is! BulkMapReader) return const {};
|
if (remote is! BulkMapReader) return const {};
|
||||||
return await (remote as BulkMapReader).getStringMap(revsDir);
|
return await (remote as BulkMapReader).getStringMap(revsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a remote note log, returning `null` for a corrupt or wrong-shape
|
|
||||||
/// payload so one bad device file never aborts the whole sync.
|
|
||||||
Log? _decodeLog(String text) {
|
|
||||||
try {
|
|
||||||
return logFromJson(text);
|
|
||||||
} on FormatException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// crdt_sync's logFromJson throws a raw TypeError (not a custom
|
|
||||||
// exception) for a wrong-shape JSON payload from an untrusted peer
|
|
||||||
// file; must be caught too so one bad device file never aborts the
|
|
||||||
// whole sync (see doc comment above).
|
|
||||||
// ignore: avoid_catching_errors
|
|
||||||
on TypeError {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/// The one page route every screen is pushed with.
|
/// The one page route every screen is pushed with.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
/// A route for [builder] that switches screens instantly: no fade, no slide.
|
/// A route for [builder] that switches screens instantly: no fade, no slide.
|
||||||
///
|
///
|
||||||
@ -10,11 +10,17 @@ import 'package:flutter/material.dart';
|
|||||||
/// thread and a 260-300 ms frame stall on every tab switch and note open.
|
/// thread and a 260-300 ms frame stall on every tab switch and note open.
|
||||||
/// The same instant switch applies on the phone. The context is unused but
|
/// The same instant switch applies on the phone. The context is unused but
|
||||||
/// kept so every call site stays as it was.
|
/// kept so every call site stays as it was.
|
||||||
Route<T> appRoute<T>(BuildContext _, WidgetBuilder builder) =>
|
///
|
||||||
_AppPageRoute<T>(builder: builder);
|
/// [name] is a route pattern (`/notes/detail`), never an id or a title: the
|
||||||
|
/// app-errors reporter stamps it on every report made on that screen.
|
||||||
|
Route<T> appRoute<T>(BuildContext _, WidgetBuilder builder, {String? name}) =>
|
||||||
|
_AppPageRoute<T>(
|
||||||
|
builder: builder,
|
||||||
|
settings: RouteSettings(name: name),
|
||||||
|
);
|
||||||
|
|
||||||
class _AppPageRoute<T> extends MaterialPageRoute<T> {
|
class _AppPageRoute<T> extends MaterialPageRoute<T> {
|
||||||
_AppPageRoute({required super.builder});
|
_AppPageRoute({required super.builder, super.settings});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Duration get transitionDuration => Duration.zero;
|
Duration get transitionDuration => Duration.zero;
|
||||||
|
|||||||
@ -5,8 +5,8 @@ library;
|
|||||||
import 'package:file_picker/file_picker.dart' show FilePicker;
|
import 'package:file_picker/file_picker.dart' show FilePicker;
|
||||||
import 'package:file_selector/file_selector.dart';
|
import 'package:file_selector/file_selector.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
export 'package:file_selector/file_selector.dart' show XFile;
|
export 'package:file_selector/file_selector.dart' show XFile;
|
||||||
|
|
||||||
@ -44,18 +44,24 @@ Future<List<XFile>> pickAttachments(
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.photo_camera_outlined),
|
leading: const Icon(
|
||||||
title: const Text('Camera'),
|
Icons.photo_camera_outlined,
|
||||||
|
semanticLabel: 'Camera',
|
||||||
|
),
|
||||||
onTap: () => Navigator.pop(context, AttachmentPickSource.camera),
|
onTap: () => Navigator.pop(context, AttachmentPickSource.camera),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.photo_library_outlined),
|
leading: const Icon(
|
||||||
title: const Text('Gallery'),
|
Icons.photo_library_outlined,
|
||||||
|
semanticLabel: 'Gallery',
|
||||||
|
),
|
||||||
onTap: () => Navigator.pop(context, AttachmentPickSource.gallery),
|
onTap: () => Navigator.pop(context, AttachmentPickSource.gallery),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.insert_drive_file_outlined),
|
leading: const Icon(
|
||||||
title: const Text('File'),
|
Icons.insert_drive_file_outlined,
|
||||||
|
semanticLabel: 'File',
|
||||||
|
),
|
||||||
onTap: () => Navigator.pop(context, AttachmentPickSource.file),
|
onTap: () => Navigator.pop(context, AttachmentPickSource.file),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -102,8 +108,8 @@ class AttachButton extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return IconButton(
|
return IconButton(
|
||||||
tooltip: 'Attach',
|
tooltip: 'attach',
|
||||||
icon: const Icon(Icons.attach_file),
|
icon: const Icon(Icons.attach_file, semanticLabel: 'Attach'),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final files = await (picking ?? pickAttachments)(context);
|
final files = await (picking ?? pickAttachments)(context);
|
||||||
if (files.isNotEmpty) onFiles(files);
|
if (files.isNotEmpty) onFiles(files);
|
||||||
|
|||||||
@ -4,8 +4,9 @@
|
|||||||
/// screen still owns every action; this just lays the row out.
|
/// screen still owns every action; this just lays the row out.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show WaitWatch;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
import 'package:todo/frame_stats.dart';
|
import 'package:todo/frame_stats.dart';
|
||||||
@ -86,26 +87,29 @@ class CaptureAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
// Not gated on advanced mode: attaching is basic capture.
|
// Not gated on advanced mode: attaching is basic capture.
|
||||||
AttachButton(onFiles: onAttachFiles, picking: attachmentPicking),
|
AttachButton(onFiles: onAttachFiles, picking: attachmentPicking),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'New note',
|
tooltip: 'new',
|
||||||
onPressed: onNewNote,
|
onPressed: onNewNote,
|
||||||
icon: const Icon(Icons.check),
|
icon: const Icon(Icons.check, semanticLabel: 'New note'),
|
||||||
),
|
),
|
||||||
if (advanced)
|
if (advanced)
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Sync',
|
tooltip: 'sync',
|
||||||
onPressed: syncing ? null : onSync,
|
onPressed: syncing ? null : onSync,
|
||||||
icon: syncing
|
icon: syncing
|
||||||
? const SizedBox(
|
? const WaitWatch(
|
||||||
width: 18,
|
operation: 'sync.run',
|
||||||
height: 18,
|
child: SizedBox(
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: const Icon(Icons.sync),
|
: const Icon(Icons.sync, semanticLabel: 'Sync'),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Notes',
|
tooltip: 'notes',
|
||||||
onPressed: onOpenList,
|
onPressed: onOpenList,
|
||||||
icon: const Icon(Icons.list),
|
icon: const Icon(Icons.list, semanticLabel: 'Notes'),
|
||||||
),
|
),
|
||||||
// Live count of stored notes, proving local persistence. Sits directly
|
// Live count of stored notes, proving local persistence. Sits directly
|
||||||
// right of the Notes button it belongs to, and carries no icon of its
|
// right of the Notes button it belongs to, and carries no icon of its
|
||||||
@ -122,9 +126,9 @@ class CaptureAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
),
|
),
|
||||||
CaptureConfirmMark(captured: captured),
|
CaptureConfirmMark(captured: captured),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Settings',
|
tooltip: 'settings',
|
||||||
onPressed: onOpenSettings,
|
onPressed: onOpenSettings,
|
||||||
icon: const Icon(Icons.settings),
|
icon: const Icon(Icons.settings, semanticLabel: 'Settings'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@ -3,7 +3,7 @@ library;
|
|||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
/// Plays once each time [captured] changes value.
|
/// Plays once each time [captured] changes value.
|
||||||
class CaptureConfirmMark extends StatefulWidget {
|
class CaptureConfirmMark extends StatefulWidget {
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
import 'package:design_system/design_system.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:todo/analytics/analytics_event.dart';
|
import 'package:todo/analytics/analytics_event.dart';
|
||||||
import 'package:todo/analytics/analytics_service.dart';
|
import 'package:todo/analytics/analytics_service.dart';
|
||||||
import 'package:todo/attachments/image_store_scope.dart';
|
import 'package:todo/attachments/image_store_scope.dart';
|
||||||
@ -22,6 +21,7 @@ import 'package:todo/ui/capture_draft.dart';
|
|||||||
import 'package:todo/ui/capture_status.dart';
|
import 'package:todo/ui/capture_status.dart';
|
||||||
import 'package:todo/ui/capture_status_footer.dart';
|
import 'package:todo/ui/capture_status_footer.dart';
|
||||||
import 'package:todo/ui/capture_sync_runner.dart';
|
import 'package:todo/ui/capture_sync_runner.dart';
|
||||||
|
import 'package:todo/ui/cue_snack.dart';
|
||||||
import 'package:todo/ui/image_attach.dart';
|
import 'package:todo/ui/image_attach.dart';
|
||||||
import 'package:todo/ui/image_input.dart';
|
import 'package:todo/ui/image_input.dart';
|
||||||
import 'package:todo/ui/note_form.dart';
|
import 'package:todo/ui/note_form.dart';
|
||||||
@ -194,7 +194,14 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
Future<void> _sync() async {
|
Future<void> _sync() async {
|
||||||
final settings = _settings ?? await SyncSettings.load();
|
final settings = _settings ?? await SyncSettings.load();
|
||||||
if (!settings.isConfigured && await openFirebase() == null) {
|
if (!settings.isConfigured && await openFirebase() == null) {
|
||||||
_showSnack('Connect Firebase (or add a GitHub token) in settings');
|
// The cue plus the settings screen opening is the whole message.
|
||||||
|
if (mounted) {
|
||||||
|
showCue(
|
||||||
|
context,
|
||||||
|
Icons.cloud_off,
|
||||||
|
'Connect Firebase (or add a GitHub token) in settings',
|
||||||
|
);
|
||||||
|
}
|
||||||
await _openSettings();
|
await _openSettings();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -215,12 +222,7 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
if (outcome.ok) 'detail': outcome.detail,
|
if (outcome.ok) 'detail': outcome.detail,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
_showSnack(
|
_showSyncCue(outcome);
|
||||||
outcome.ok
|
|
||||||
? 'Synced: ${outcome.detail}'
|
|
||||||
: 'Sync failed: ${outcome.detail}',
|
|
||||||
isError: !outcome.ok,
|
|
||||||
);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (mounted) setState(() => _syncing = false);
|
if (mounted) setState(() => _syncing = false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,6 +75,7 @@ extension _CaptureSyncBehaviour on _CaptureScreenState {
|
|||||||
analytics: widget.analytics,
|
analytics: widget.analytics,
|
||||||
httpClient: widget.httpClient,
|
httpClient: widget.httpClient,
|
||||||
),
|
),
|
||||||
|
name: '/settings',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
@ -94,6 +95,7 @@ extension _CaptureSyncBehaviour on _CaptureScreenState {
|
|||||||
repository: widget.repository,
|
repository: widget.repository,
|
||||||
appSettings: widget.appSettings,
|
appSettings: widget.appSettings,
|
||||||
),
|
),
|
||||||
|
name: '/notes',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -104,13 +106,20 @@ extension _CaptureSyncBehaviour on _CaptureScreenState {
|
|||||||
/// replace-don't-queue behaviour match every other app; [isError] picks
|
/// replace-don't-queue behaviour match every other app; [isError] picks
|
||||||
/// the danger hue and the longer duration, because an error the user
|
/// the danger hue and the longer duration, because an error the user
|
||||||
/// missed is an error they will hit again.
|
/// missed is an error they will hit again.
|
||||||
void _showSnack(String message, {bool isError = false}) {
|
/// A manual sync's result as a glyph: done, done-but-degraded (Firebase
|
||||||
|
/// off or a peer unreadable, in the danger hue), or failed. The summary
|
||||||
|
/// sentence is spoken only; the status line keeps the failure time.
|
||||||
|
void _showSyncCue(CaptureSyncOutcome outcome) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (isError) {
|
final spoken = outcome.ok
|
||||||
showError(context, message);
|
? 'Synced: ${outcome.detail}'
|
||||||
} else {
|
: 'Sync failed: ${outcome.detail}';
|
||||||
showToast(context, message);
|
final (icon, error) = !outcome.ok
|
||||||
}
|
? (Icons.sync_problem, true)
|
||||||
|
: outcome.degraded
|
||||||
|
? (Icons.warning_amber, true)
|
||||||
|
: (Icons.cloud_done, false);
|
||||||
|
showCue(context, icon, spoken, error: error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reloads the persisted last-sync outcome so the status line survives a
|
/// Reloads the persisted last-sync outcome so the status line survives a
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/// library-scoped.
|
/// library-scoped.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'package:todo/sync/sync_service.dart';
|
import 'package:todo/sync/sync_service.dart';
|
||||||
@ -98,6 +98,7 @@ class SyncStatusStore {
|
|||||||
/// precisely how a desktop stuck syncing over the GitHub mirror alone
|
/// precisely how a desktop stuck syncing over the GitHub mirror alone
|
||||||
/// went unnoticed for days.
|
/// went unnoticed for days.
|
||||||
String describeSyncResult(SyncResult result) {
|
String describeSyncResult(SyncResult result) {
|
||||||
|
if (result.locked) return '🔒';
|
||||||
final skipped = result.skippedFiles.length;
|
final skipped = result.skippedFiles.length;
|
||||||
final backend = result.firebaseConnected
|
final backend = result.firebaseConnected
|
||||||
? ''
|
? ''
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/ui/capture_status.dart';
|
import 'package:todo/ui/capture_status.dart';
|
||||||
|
|
||||||
@ -44,16 +44,16 @@ class CaptureStatusFooter extends StatelessWidget {
|
|||||||
if (status == null || status.ok) {
|
if (status == null || status.ok) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
// Glyph + time in the danger hue; the error itself is spoken.
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(top: 8),
|
padding: const EdgeInsets.only(top: 8),
|
||||||
child: Text(
|
child: _cueLine(
|
||||||
|
Icons.sync_problem,
|
||||||
|
formatSyncTime(status.time),
|
||||||
'Sync failed at ${formatSyncTime(status.time)} · '
|
'Sync failed at ${formatSyncTime(status.time)} · '
|
||||||
'${status.detail}',
|
'${status.detail}',
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
theme.textTheme.bodySmall,
|
||||||
color: theme.colorScheme.error,
|
theme.colorScheme.error,
|
||||||
),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -63,15 +63,45 @@ class CaptureStatusFooter extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.only(top: 4),
|
padding: const EdgeInsets.only(top: 4),
|
||||||
child: ValueListenableBuilder<DateTime?>(
|
child: ValueListenableBuilder<DateTime?>(
|
||||||
valueListenable: lastSavedAt,
|
valueListenable: lastSavedAt,
|
||||||
builder: (context, savedAt, _) => Text(
|
// Before the first save: the save glyph alone, muted.
|
||||||
savedAt == null
|
builder: (context, savedAt, _) => savedAt == null
|
||||||
? 'Autosaves as you type'
|
? _cueLine(
|
||||||
: 'Saved locally at ${formatSyncTime(savedAt)}',
|
Icons.save_outlined,
|
||||||
style: theme.textTheme.bodySmall,
|
'',
|
||||||
),
|
'Autosaves as you type',
|
||||||
|
theme.textTheme.bodySmall,
|
||||||
|
theme.colorScheme.outline,
|
||||||
|
)
|
||||||
|
: _cueLine(
|
||||||
|
Icons.save,
|
||||||
|
formatSyncTime(savedAt),
|
||||||
|
'Saved locally at ${formatSyncTime(savedAt)}',
|
||||||
|
theme.textTheme.bodySmall,
|
||||||
|
null,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One status line: a small glyph and a time, spoken as [spoken].
|
||||||
|
Widget _cueLine(
|
||||||
|
IconData icon,
|
||||||
|
String time,
|
||||||
|
String spoken,
|
||||||
|
TextStyle? style,
|
||||||
|
Color? color,
|
||||||
|
) => Semantics(
|
||||||
|
label: spoken,
|
||||||
|
excludeSemantics: true,
|
||||||
|
container: true,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 16, color: color),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(time, style: style?.copyWith(color: color)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,11 +26,16 @@ class CaptureSyncOutcome {
|
|||||||
required this.ok,
|
required this.ok,
|
||||||
required this.detail,
|
required this.detail,
|
||||||
this.reconciled,
|
this.reconciled,
|
||||||
|
this.degraded = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Whether the pass completed without throwing.
|
/// Whether the pass completed without throwing.
|
||||||
final bool ok;
|
final bool ok;
|
||||||
|
|
||||||
|
/// A pass that completed but not fully: Firebase was not connected, or a
|
||||||
|
/// peer's file could not be read. Shown as a warning, not a plain success.
|
||||||
|
final bool degraded;
|
||||||
|
|
||||||
/// One-line summary: merged/skipped counts on success, the error otherwise.
|
/// One-line summary: merged/skipped counts on success, the error otherwise.
|
||||||
final String detail;
|
final String detail;
|
||||||
|
|
||||||
@ -90,10 +95,15 @@ class CaptureSyncRunner {
|
|||||||
);
|
);
|
||||||
final detail = describeSyncResult(result.syncResult);
|
final detail = describeSyncResult(result.syncResult);
|
||||||
await status.record(ok: true, detail: detail, live: live());
|
await status.record(ok: true, detail: detail, live: live());
|
||||||
|
final synced = result.syncResult;
|
||||||
return CaptureSyncOutcome(
|
return CaptureSyncOutcome(
|
||||||
ok: true,
|
ok: true,
|
||||||
detail: detail,
|
detail: detail,
|
||||||
reconciled: result.appSettings,
|
reconciled: result.appSettings,
|
||||||
|
degraded:
|
||||||
|
synced.locked ||
|
||||||
|
!synced.firebaseConnected ||
|
||||||
|
synced.skippedFiles.isNotEmpty,
|
||||||
);
|
);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
await status.record(ok: false, detail: '$e', live: live());
|
await status.record(ok: false, detail: '$e', live: live());
|
||||||
|
|||||||
@ -10,14 +10,15 @@ library;
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:todo/attachments/image_password_store.dart';
|
import 'package:todo/attachments/image_password_store.dart';
|
||||||
import 'package:todo/attachments/image_store_api.dart';
|
import 'package:todo/attachments/image_store_api.dart';
|
||||||
import 'package:todo/attachments/image_store_scope.dart';
|
import 'package:todo/attachments/image_store_scope.dart';
|
||||||
import 'package:todo/images/dufs_image_client.dart';
|
import 'package:todo/images/dufs_image_client.dart';
|
||||||
import 'package:todo/ui/app_route.dart';
|
import 'package:todo/ui/app_route.dart';
|
||||||
|
import 'package:todo/ui/status_cue.dart';
|
||||||
|
|
||||||
/// The command that creates the login, shown wherever it is missing.
|
/// The command that creates the login, shown wherever it is missing.
|
||||||
const kAddLoginCommand =
|
const kAddLoginCommand =
|
||||||
@ -34,11 +35,14 @@ class CloudImagesTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => ListTile(
|
Widget build(BuildContext context) => ListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
title: const Text('Cloud images'),
|
leading: const Icon(Icons.cloud, semanticLabel: 'Cloud images'),
|
||||||
subtitle: const Text('Where attached images and files upload (dufs)'),
|
|
||||||
trailing: const Icon(Icons.chevron_right),
|
trailing: const Icon(Icons.chevron_right),
|
||||||
onTap: () => Navigator.of(context).push<void>(
|
onTap: () => Navigator.of(context).push<void>(
|
||||||
appRoute(context, (_) => CloudImagesScreen(httpClient: httpClient)),
|
appRoute(
|
||||||
|
context,
|
||||||
|
(_) => CloudImagesScreen(httpClient: httpClient),
|
||||||
|
name: '/settings/images',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -69,7 +73,7 @@ class CloudImagesScreen extends StatefulWidget {
|
|||||||
class _CloudImagesScreenState extends State<CloudImagesScreen> {
|
class _CloudImagesScreenState extends State<CloudImagesScreen> {
|
||||||
final _password = TextEditingController();
|
final _password = TextEditingController();
|
||||||
ImageStoreStatus? _status;
|
ImageStoreStatus? _status;
|
||||||
String? _checkResult;
|
StatusCue? _checkResult;
|
||||||
bool _checking = false;
|
bool _checking = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -98,7 +102,11 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
|
|||||||
final password = _password.text.trim();
|
final password = _password.text.trim();
|
||||||
setState(() => _checking = true);
|
setState(() => _checking = true);
|
||||||
final saved = await widget.passwords.write(password);
|
final saved = await widget.passwords.write(password);
|
||||||
var result = 'Could not save: the keystore is unavailable';
|
var result = const StatusCue(
|
||||||
|
Icons.no_encryption,
|
||||||
|
'Could not save: the keystore is unavailable',
|
||||||
|
error: true,
|
||||||
|
);
|
||||||
if (saved) {
|
if (saved) {
|
||||||
final client = DufsImageClient(
|
final client = DufsImageClient(
|
||||||
DufsLogin(user: kDufsImagesUser, password: password),
|
DufsLogin(user: kDufsImagesUser, password: password),
|
||||||
@ -106,9 +114,17 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
|
|||||||
);
|
);
|
||||||
final check = await client.check();
|
final check = await client.check();
|
||||||
result = switch (check) {
|
result = switch (check) {
|
||||||
DufsCheck.ok => 'Saved — dufs accepted the login',
|
DufsCheck.ok => const StatusCue.ok('Saved — dufs accepted the login'),
|
||||||
DufsCheck.rejected => 'Saved, but dufs rejected the password',
|
DufsCheck.rejected => const StatusCue(
|
||||||
DufsCheck.unreachable => 'Saved — dufs is unreachable right now',
|
Icons.lock,
|
||||||
|
'Saved, but dufs rejected the password',
|
||||||
|
error: true,
|
||||||
|
),
|
||||||
|
DufsCheck.unreachable => const StatusCue(
|
||||||
|
Icons.cloud_off,
|
||||||
|
'Saved — dufs is unreachable right now',
|
||||||
|
error: true,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
// Upload what queued up while there was no password, now rather than
|
// Upload what queued up while there was no password, now rather than
|
||||||
// on the next sync. No note texts: an empty ref set only uploads, it
|
// on the next sync. No note texts: an empty ref set only uploads, it
|
||||||
@ -129,7 +145,9 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final status = _status;
|
final status = _status;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text('Cloud images')),
|
appBar: AppBar(
|
||||||
|
title: const Icon(Icons.cloud_outlined, semanticLabel: 'Cloud images'),
|
||||||
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
@ -138,36 +156,79 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
|
|||||||
controller: _password,
|
controller: _password,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Password for the "todo" dufs login',
|
prefixIcon: Icon(
|
||||||
|
Icons.lock_outline,
|
||||||
|
semanticLabel: 'Password for the "todo" dufs login',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: _checking ? null : _saveAndTest,
|
onPressed: _checking ? null : _saveAndTest,
|
||||||
child: const Text('Save & test'),
|
child: const Icon(Icons.save, semanticLabel: 'Save & test'),
|
||||||
),
|
),
|
||||||
if (_checkResult case final result?) ...[
|
if (_checkResult case final result?) ...[
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(result),
|
StatusCueView(result),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
],
|
],
|
||||||
if (status != null) ...[
|
if (status != null) ...[
|
||||||
Text(
|
// Shape + colour: a filled check, or a red error ring followed by
|
||||||
status.configured
|
// a copy button that puts the fixing command on the clipboard.
|
||||||
? 'Login: configured'
|
Row(
|
||||||
: 'Login: missing — create it on the PC with',
|
children: [
|
||||||
|
Icon(
|
||||||
|
status.configured ? Icons.check_circle : Icons.error_outline,
|
||||||
|
color: status.configured
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: Theme.of(context).colorScheme.error,
|
||||||
|
semanticLabel: status.configured
|
||||||
|
? 'Login: configured'
|
||||||
|
: 'Login: missing — create it on the PC with',
|
||||||
|
),
|
||||||
|
if (!status.configured)
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'copy',
|
||||||
|
onPressed: () => unawaited(
|
||||||
|
Clipboard.setData(
|
||||||
|
const ClipboardData(text: kAddLoginCommand),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.content_copy,
|
||||||
|
semanticLabel: 'Copy: $kAddLoginCommand',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
if (!status.configured) const SelectableText(kAddLoginCommand),
|
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text('Waiting to upload: ${status.pending}'),
|
// Icon + the count itself: the number is the information.
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.cloud_upload_outlined),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'${status.pending}',
|
||||||
|
semanticsLabel: 'Waiting to upload: ${status.pending}',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
// Shrunk + no location, as glyphs; the sentence is spoken only.
|
||||||
'Images are shrunk to 2560px JPEGs without location data before '
|
const Row(
|
||||||
'they leave this device. Other files upload unchanged, at any '
|
children: [
|
||||||
'size.',
|
Icon(
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
Icons.photo_size_select_large,
|
||||||
|
semanticLabel:
|
||||||
|
'Images are shrunk to 2560px JPEGs without location data '
|
||||||
|
'before they leave this device. Other files upload '
|
||||||
|
'unchanged, at any size.',
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Icon(Icons.location_off),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
60
lib/ui/confirm_delete.dart
Normal file
60
lib/ui/confirm_delete.dart
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/// Icon-only confirmation before deleting a note.
|
||||||
|
///
|
||||||
|
/// Replaces design_system's `confirmDestructive` here because that dialog
|
||||||
|
/// paints its title, message and button labels as text. The safety contract
|
||||||
|
/// is kept: Cancel is autofocused (a reflexive Return keeps the note), Escape
|
||||||
|
/// and the barrier answer "no", and the confirm glyph wears the error colour.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
/// Asks whether to delete a note; true only when the delete glyph is pressed.
|
||||||
|
Future<bool> confirmDeleteNote(BuildContext context) async {
|
||||||
|
final confirmed = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => const _ConfirmDeleteDialog(),
|
||||||
|
);
|
||||||
|
return confirmed ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ConfirmDeleteDialog extends StatelessWidget {
|
||||||
|
const _ConfirmDeleteDialog();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final error = Theme.of(context).colorScheme.error;
|
||||||
|
return CallbackShortcuts(
|
||||||
|
bindings: {
|
||||||
|
const SingleActivator(LogicalKeyboardKey.escape): () =>
|
||||||
|
Navigator.of(context).pop(false),
|
||||||
|
},
|
||||||
|
child: AlertDialog(
|
||||||
|
// Spoken when the dialog opens; the old written body.
|
||||||
|
semanticLabel: 'This cannot be undone.',
|
||||||
|
title: Icon(
|
||||||
|
Icons.delete_forever,
|
||||||
|
size: 40,
|
||||||
|
color: error,
|
||||||
|
semanticLabel: 'Delete note?',
|
||||||
|
),
|
||||||
|
actionsAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
key: const ValueKey('confirm-cancel'),
|
||||||
|
tooltip: 'cancel',
|
||||||
|
autofocus: true,
|
||||||
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
|
icon: const Icon(Icons.close, semanticLabel: 'Cancel'),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
key: const ValueKey('confirm-delete'),
|
||||||
|
tooltip: 'delete',
|
||||||
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
|
icon: Icon(Icons.delete, color: error, semanticLabel: 'Delete'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
lib/ui/cue_snack.dart
Normal file
58
lib/ui/cue_snack.dart
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/// Transient feedback as a glyph, not a sentence (kuhy's textgate rule).
|
||||||
|
///
|
||||||
|
/// The design system's `showToast`/`showError` paint a message; this paints
|
||||||
|
/// an icon (plus an optional number) and keeps the old sentence as the
|
||||||
|
/// spoken label only. Colour is the second channel: errors use the danger
|
||||||
|
/// hue and stay up longer, as `showError` does.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:design_system/design_system.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
const Duration _toastDuration = Duration(seconds: 3);
|
||||||
|
const Duration _errorDuration = Duration(seconds: 5);
|
||||||
|
|
||||||
|
/// Shows [icon] (and [count], if given) in a snack bar; [spoken] is what a
|
||||||
|
/// screen reader says. Returns quietly when no `ScaffoldMessenger` is above
|
||||||
|
/// [context] (an async callback outliving its screen).
|
||||||
|
void showCue(
|
||||||
|
BuildContext context,
|
||||||
|
IconData icon,
|
||||||
|
String spoken, {
|
||||||
|
bool error = false,
|
||||||
|
int? count,
|
||||||
|
}) {
|
||||||
|
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||||
|
if (messenger == null) return;
|
||||||
|
final colors = context.statusColors;
|
||||||
|
final fg = error ? colors.onStatus : null;
|
||||||
|
// Replace rather than queue: a queued cue describes an action the user
|
||||||
|
// has already moved on from.
|
||||||
|
messenger
|
||||||
|
..clearSnackBars()
|
||||||
|
..showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Semantics(
|
||||||
|
label: spoken,
|
||||||
|
excludeSemantics: true,
|
||||||
|
// Its own node: otherwise the label merges into the snack bar's.
|
||||||
|
container: true,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(icon, color: fg),
|
||||||
|
if (count != null) ...[
|
||||||
|
const SizedBox(width: AppSpacing.sm),
|
||||||
|
Text('$count', style: TextStyle(color: fg)),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
backgroundColor: error ? colors.danger : null,
|
||||||
|
duration: error ? _errorDuration : _toastDuration,
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
23
lib/ui/empty_notes_cue.dart
Normal file
23
lib/ui/empty_notes_cue.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/// The notes list's empty state as a picture, not a sentence.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
/// A large muted glyph: an empty inbox when there are no notes at all, a
|
||||||
|
/// crossed-out filter when the current filter hides every note (the filter
|
||||||
|
/// button's badge is the second channel saying a filter is on).
|
||||||
|
class EmptyNotesCue extends StatelessWidget {
|
||||||
|
/// Creates the cue; [filtered] picks the filter variant.
|
||||||
|
const EmptyNotesCue({required this.filtered, super.key});
|
||||||
|
|
||||||
|
/// Whether a filter is active (notes may exist but none match).
|
||||||
|
final bool filtered;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Icon(
|
||||||
|
filtered ? Icons.filter_alt_off_outlined : Icons.inbox_outlined,
|
||||||
|
size: 64,
|
||||||
|
color: Theme.of(context).colorScheme.outline,
|
||||||
|
semanticLabel: filtered ? 'No notes match these filters' : 'No notes yet',
|
||||||
|
);
|
||||||
|
}
|
||||||
105
lib/ui/enum_glyphs.dart
Normal file
105
lib/ui/enum_glyphs.dart
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/// Glyphs for the Priority and Status enums, and the chip row that picks
|
||||||
|
/// them, so every picker shows the same shape + colour for the same value.
|
||||||
|
///
|
||||||
|
/// The enum's `label` survives only as the spoken (semantics) label.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
import 'package:todo/data/note.dart';
|
||||||
|
import 'package:todo/ui/note_grid_tile.dart';
|
||||||
|
|
||||||
|
/// Shape channel for a priority: up for high, level for medium, down for low.
|
||||||
|
/// Colour ([priorityColor]) is the second channel.
|
||||||
|
IconData priorityIcon(Priority p) => switch (p) {
|
||||||
|
Priority.high => Icons.keyboard_double_arrow_up,
|
||||||
|
Priority.medium => Icons.drag_handle,
|
||||||
|
Priority.low => Icons.keyboard_double_arrow_down,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Heading glyph standing for "status" (matches the bulk-status button).
|
||||||
|
const IconData kStatusHeadingIcon = Icons.task_alt;
|
||||||
|
|
||||||
|
/// Heading glyph standing for "priority" (matches the bulk-priority button).
|
||||||
|
const IconData kPriorityHeadingIcon = Icons.flag_outlined;
|
||||||
|
|
||||||
|
/// [s] as its glyph, spoken as its label.
|
||||||
|
Widget statusGlyph(Status s, {double? size}) =>
|
||||||
|
Icon(statusIcon(s), size: size, semanticLabel: s.label);
|
||||||
|
|
||||||
|
/// [p] as its tinted glyph, spoken as its label.
|
||||||
|
Widget priorityGlyph(BuildContext context, Priority p, {double? size}) => Icon(
|
||||||
|
priorityIcon(p),
|
||||||
|
size: size,
|
||||||
|
color: priorityColor(p, Theme.of(context).colorScheme),
|
||||||
|
semanticLabel: p.label,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// A heading glyph followed by one chip per value, each chip a glyph.
|
||||||
|
///
|
||||||
|
/// [multi] switches between FilterChips (toggle many) and ChoiceChips (pick
|
||||||
|
/// one); either way the selected chips are filled and checked.
|
||||||
|
class GlyphChips<T> extends StatelessWidget {
|
||||||
|
/// Creates a chip row for [values].
|
||||||
|
const GlyphChips({
|
||||||
|
required this.heading,
|
||||||
|
required this.semanticLabel,
|
||||||
|
required this.values,
|
||||||
|
required this.selected,
|
||||||
|
required this.glyphOf,
|
||||||
|
required this.onTap,
|
||||||
|
this.multi = false,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
/// Glyph shown in front of the chips in place of a written heading.
|
||||||
|
final IconData heading;
|
||||||
|
|
||||||
|
/// Spoken name of the row (the old written heading).
|
||||||
|
final String semanticLabel;
|
||||||
|
|
||||||
|
/// Every value offered.
|
||||||
|
final List<T> values;
|
||||||
|
|
||||||
|
/// Values currently selected.
|
||||||
|
final Set<T> selected;
|
||||||
|
|
||||||
|
/// Builds the glyph for one value.
|
||||||
|
final Widget Function(T) glyphOf;
|
||||||
|
|
||||||
|
/// Called with the tapped value.
|
||||||
|
final ValueChanged<T> onTap;
|
||||||
|
|
||||||
|
/// Whether this is a multi-select (filter) row.
|
||||||
|
final bool multi;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Icon(heading, semanticLabel: semanticLabel),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: [
|
||||||
|
for (final v in values)
|
||||||
|
if (multi)
|
||||||
|
FilterChip(
|
||||||
|
label: glyphOf(v),
|
||||||
|
selected: selected.contains(v),
|
||||||
|
onSelected: (_) => onTap(v),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
ChoiceChip(
|
||||||
|
label: glyphOf(v),
|
||||||
|
selected: selected.contains(v),
|
||||||
|
onSelected: (_) => onTap(v),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,33 +1,27 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show WaitWatch;
|
||||||
import 'package:github_device_auth/github_device_auth.dart';
|
import 'package:github_device_auth/github_device_auth.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:todo/analytics/analytics_service.dart';
|
import 'package:todo/analytics/analytics_service.dart';
|
||||||
import 'package:todo/data/app_settings.dart';
|
import 'package:todo/data/app_settings.dart';
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
import 'package:todo/sync/run_sync.dart';
|
import 'package:todo/sync/run_sync.dart';
|
||||||
import 'package:todo/sync/sync_settings.dart';
|
import 'package:todo/sync/sync_settings.dart';
|
||||||
|
import 'package:todo/ui/status_cue.dart';
|
||||||
|
|
||||||
part 'github_mirror_screen_widget.dart';
|
part 'github_mirror_screen_widget.dart';
|
||||||
|
|
||||||
class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
||||||
late final TextEditingController _owner = TextEditingController(
|
late final _owner = TextEditingController(text: widget.initial.owner);
|
||||||
text: widget.initial.owner,
|
late final _repo = TextEditingController(text: widget.initial.repo);
|
||||||
);
|
late final _token = TextEditingController(text: widget.initial.token);
|
||||||
late final TextEditingController _repo = TextEditingController(
|
late final _clientId = TextEditingController(text: widget.initial.clientId);
|
||||||
text: widget.initial.repo,
|
|
||||||
);
|
|
||||||
late final TextEditingController _token = TextEditingController(
|
|
||||||
text: widget.initial.token,
|
|
||||||
);
|
|
||||||
late final TextEditingController _clientId = TextEditingController(
|
|
||||||
text: widget.initial.clientId,
|
|
||||||
);
|
|
||||||
|
|
||||||
bool _testing = false;
|
bool _testing = false;
|
||||||
String? _status;
|
StatusCue? _status;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -49,8 +43,13 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
Future<void> _connectGitHub() async {
|
Future<void> _connectGitHub() async {
|
||||||
final clientId = _clientId.text.trim();
|
final clientId = _clientId.text.trim();
|
||||||
if (clientId.isEmpty) {
|
if (clientId.isEmpty) {
|
||||||
setState(() => _status = 'Enter the OAuth App client id first.');
|
return _show(
|
||||||
return;
|
const StatusCue(
|
||||||
|
Icons.key_off,
|
||||||
|
'Enter the OAuth App client id first.',
|
||||||
|
error: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final auth = GitHubDeviceAuth(
|
final auth = GitHubDeviceAuth(
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
@ -67,20 +66,19 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
if (token != null && token.isNotEmpty) {
|
if (token != null && token.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_token.text = token;
|
_token.text = token;
|
||||||
_status = 'Connected — syncing…';
|
_status = const StatusCue(Icons.sync, 'Connected — syncing…');
|
||||||
});
|
});
|
||||||
await _current.save();
|
await _current.save();
|
||||||
await _syncAfterConnect();
|
await _syncAfterConnect();
|
||||||
}
|
}
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
if (mounted) setState(() => _status = 'Could not start device flow: $e');
|
_show(StatusCue.failed('Could not start device flow: $e'));
|
||||||
} finally {
|
} finally {
|
||||||
auth.close();
|
auth.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs a sync right after connecting so the user's notes download
|
/// Syncs right after connecting so notes download at once, with a cue.
|
||||||
/// immediately and they get clear confirmation it worked.
|
|
||||||
Future<void> _syncAfterConnect() async {
|
Future<void> _syncAfterConnect() async {
|
||||||
final s = _current;
|
final s = _current;
|
||||||
try {
|
try {
|
||||||
@ -96,19 +94,29 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
widget.appSettings.value = widget.appSettings.value.adopt(
|
widget.appSettings.value = widget.appSettings.value.adopt(
|
||||||
run.appSettings,
|
run.appSettings,
|
||||||
);
|
);
|
||||||
if (mounted) {
|
_show(
|
||||||
setState(
|
StatusCue.ok(
|
||||||
() => _status =
|
'Connected and synced (merged '
|
||||||
'Connected and synced (merged '
|
'${run.syncResult.mergedDevices} device(s)). Your notes are '
|
||||||
'${run.syncResult.mergedDevices} device(s)). Your notes are '
|
'up to date.',
|
||||||
'up to date.',
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
if (mounted) setState(() => _status = 'Connected, but sync failed: $e');
|
_show(
|
||||||
|
StatusCue(
|
||||||
|
Icons.sync_problem,
|
||||||
|
'Connected, but sync failed: $e',
|
||||||
|
error: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shows [cue] as the screen's latest result, if still mounted.
|
||||||
|
void _show(StatusCue cue) {
|
||||||
|
if (mounted) setState(() => _status = cue);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _test() async {
|
Future<void> _test() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
_testing = true;
|
_testing = true;
|
||||||
@ -123,13 +131,17 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
final ok = await client.canAccessRepo();
|
final ok = await client.canAccessRepo();
|
||||||
setState(
|
_show(
|
||||||
() => _status = ok
|
ok
|
||||||
? 'Connected — repo is reachable.'
|
? const StatusCue.ok('Connected — repo is reachable.')
|
||||||
: 'Could not access ${s.owner}/${s.repo}. Check token scope.',
|
: StatusCue(
|
||||||
|
Icons.lock,
|
||||||
|
'Could not access ${s.owner}/${s.repo}. Check token scope.',
|
||||||
|
error: true,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
setState(() => _status = 'Error: $e');
|
_show(StatusCue.failed('Error: $e'));
|
||||||
} finally {
|
} finally {
|
||||||
client.close();
|
client.close();
|
||||||
if (mounted) setState(() => _testing = false);
|
if (mounted) setState(() => _testing = false);
|
||||||
@ -145,29 +157,28 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text('Advanced sync (GitHub)')),
|
appBar: AppBar(
|
||||||
|
title: const Icon(
|
||||||
|
Icons.cloud_sync,
|
||||||
|
semanticLabel: 'Advanced sync (GitHub)',
|
||||||
|
),
|
||||||
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
Text(
|
|
||||||
'Authorize in your browser — no token to paste. Syncs to '
|
|
||||||
'kuhyx/syncs by default.',
|
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: FilledButton.icon(
|
child: IconButton.filled(
|
||||||
|
tooltip: 'connect',
|
||||||
onPressed: _connectGitHub,
|
onPressed: _connectGitHub,
|
||||||
icon: const Icon(Icons.login),
|
icon: const Icon(Icons.login, semanticLabel: 'Connect GitHub'),
|
||||||
label: const Text('Connect GitHub'),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _owner,
|
controller: _owner,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'GitHub owner',
|
prefixIcon: Icon(Icons.person, semanticLabel: 'GitHub owner'),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -175,7 +186,7 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: _repo,
|
controller: _repo,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Repository name',
|
prefixIcon: Icon(Icons.folder, semanticLabel: 'Repository name'),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -183,8 +194,7 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: _clientId,
|
controller: _clientId,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'OAuth App client id',
|
prefixIcon: Icon(Icons.key, semanticLabel: 'OAuth App client id'),
|
||||||
helperText: 'Leave as the baked-in default unless self-hosting',
|
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -193,36 +203,44 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
|
|||||||
controller: _token,
|
controller: _token,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Access token (fallback)',
|
prefixIcon: Icon(
|
||||||
helperText: 'Contents: read/write on the sync repo only',
|
Icons.vpn_key,
|
||||||
|
semanticLabel: 'Access token (fallback)',
|
||||||
|
),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
OutlinedButton.icon(
|
IconButton.outlined(
|
||||||
|
tooltip: 'test',
|
||||||
onPressed: _testing ? null : _test,
|
onPressed: _testing ? null : _test,
|
||||||
icon: _testing
|
icon: _testing
|
||||||
? const SizedBox(
|
? const WaitWatch(
|
||||||
width: 16,
|
operation: 'mirror.test',
|
||||||
height: 16,
|
child: SizedBox(
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: const Icon(Icons.wifi_tethering),
|
: const Icon(
|
||||||
label: const Text('Test connection'),
|
Icons.wifi_tethering,
|
||||||
|
semanticLabel: 'Test connection',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
FilledButton.icon(
|
IconButton.filled(
|
||||||
|
tooltip: 'save',
|
||||||
onPressed: _save,
|
onPressed: _save,
|
||||||
icon: const Icon(Icons.save),
|
icon: const Icon(Icons.save, semanticLabel: 'Save'),
|
||||||
label: const Text('Save'),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (_status != null) ...[
|
if (_status != null) ...[
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(_status!, style: Theme.of(context).textTheme.bodyMedium),
|
StatusCueView(_status!),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -9,12 +9,12 @@ library;
|
|||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
|
||||||
|
|
||||||
import 'package:todo/attachments/image_store_api.dart';
|
import 'package:todo/attachments/image_store_api.dart';
|
||||||
import 'package:todo/attachments/image_store_scope.dart';
|
import 'package:todo/attachments/image_store_scope.dart';
|
||||||
import 'package:todo/images/attachment_ref.dart';
|
import 'package:todo/images/attachment_ref.dart';
|
||||||
|
import 'package:todo/ui/cue_snack.dart';
|
||||||
|
|
||||||
/// Lets a screen insert lines into whichever editor is currently mounted.
|
/// Lets a screen insert lines into whichever editor is currently mounted.
|
||||||
class ImageAttachController {
|
class ImageAttachController {
|
||||||
@ -73,11 +73,15 @@ Future<void> attachImages(
|
|||||||
target.insert([for (final ref in refs) ref.imageMarkdown]);
|
target.insert([for (final ref in refs) ref.imageMarkdown]);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
if (failure != null) {
|
if (failure != null) {
|
||||||
showError(context, failure);
|
showCue(context, Icons.cloud_off, failure, error: true);
|
||||||
} else if (notImages > 0) {
|
} else if (notImages > 0) {
|
||||||
showError(
|
// A broken-image glyph plus how many were refused.
|
||||||
|
showCue(
|
||||||
context,
|
context,
|
||||||
|
Icons.broken_image_outlined,
|
||||||
notImages == 1 ? 'Not an image' : '$notImages files were not images',
|
notImages == 1 ? 'Not an image' : '$notImages files were not images',
|
||||||
|
error: true,
|
||||||
|
count: notImages,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,5 +108,7 @@ Future<void> attachFiles(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
target.insert([for (final attachment in attached) attachment.markdown]);
|
target.insert([for (final attachment in attached) attachment.markdown]);
|
||||||
if (failure != null && context.mounted) showError(context, failure);
|
if (failure != null && context.mounted) {
|
||||||
|
showCue(context, Icons.cloud_off, failure, error: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/images/attachment_links.dart';
|
import 'package:todo/images/attachment_links.dart';
|
||||||
import 'package:todo/ui/images/file_embed.dart';
|
import 'package:todo/ui/images/file_embed.dart';
|
||||||
|
|||||||
@ -3,11 +3,12 @@
|
|||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/attachments/image_store_api.dart';
|
import 'package:todo/attachments/image_store_api.dart';
|
||||||
import 'package:todo/attachments/image_store_scope.dart';
|
import 'package:todo/attachments/image_store_scope.dart';
|
||||||
import 'package:todo/images/attachment_ref.dart';
|
import 'package:todo/images/attachment_ref.dart';
|
||||||
|
import 'package:todo/ui/cue_snack.dart';
|
||||||
import 'package:todo/ui/images/file_opening.dart';
|
import 'package:todo/ui/images/file_opening.dart';
|
||||||
import 'package:todo/ui/images/image_embed.dart';
|
import 'package:todo/ui/images/image_embed.dart';
|
||||||
|
|
||||||
@ -51,7 +52,9 @@ class _FileEmbedState extends State<FileEmbed> {
|
|||||||
|
|
||||||
Future<void> _open(ImageSource source) async {
|
Future<void> _open(ImageSource source) async {
|
||||||
final failure = await widget.opening(source, widget.attachment.name);
|
final failure = await widget.opening(source, widget.attachment.name);
|
||||||
if (failure != null && mounted) showError(context, failure);
|
if (failure != null && mounted) {
|
||||||
|
showCue(context, Icons.block, failure, error: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -73,9 +76,10 @@ class _FileEmbedState extends State<FileEmbed> {
|
|||||||
style: widget.compact ? theme.textTheme.bodySmall : null,
|
style: widget.compact ? theme.textTheme.bodySmall : null,
|
||||||
);
|
);
|
||||||
final pending = store.isPending(attachment.ref)
|
final pending = store.isPending(attachment.ref)
|
||||||
? const Tooltip(
|
? const Icon(
|
||||||
message: kImageWaitingToUpload,
|
Icons.cloud_upload_outlined,
|
||||||
child: Icon(Icons.cloud_upload_outlined, size: 18),
|
size: 18,
|
||||||
|
semanticLabel: kImageWaitingToUpload,
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
final content = widget.compact
|
final content = widget.compact
|
||||||
@ -104,15 +108,21 @@ class _FileEmbedState extends State<FileEmbed> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
name,
|
name,
|
||||||
Text(detail, style: theme.textTheme.bodySmall),
|
// Not downloaded: a download glyph; else the size.
|
||||||
|
if (size == null)
|
||||||
|
const Icon(Icons.cloud_download_outlined, size: 16)
|
||||||
|
else
|
||||||
|
Text(detail, style: theme.textTheme.bodySmall),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
?pending,
|
?pending,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
// Spoken only: nothing paints this string.
|
||||||
|
final semanticLabel = 'Attached file ${attachment.name}, $detail';
|
||||||
return Semantics(
|
return Semantics(
|
||||||
label: 'Attached file ${attachment.name}, $detail',
|
label: semanticLabel,
|
||||||
button: size != null,
|
button: size != null,
|
||||||
child: Material(
|
child: Material(
|
||||||
color: theme.colorScheme.surfaceContainerHighest,
|
color: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
/// saying why it is not here yet. Tapping opens it full screen.
|
/// saying why it is not here yet. Tapping opens it full screen.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/attachments/image_store_api.dart';
|
import 'package:todo/attachments/image_store_api.dart';
|
||||||
import 'package:todo/attachments/image_store_scope.dart';
|
import 'package:todo/attachments/image_store_scope.dart';
|
||||||
@ -33,14 +33,20 @@ class ImageEmbed extends StatelessWidget {
|
|||||||
final store = ImageStoreScope.of(context);
|
final store = ImageStoreScope.of(context);
|
||||||
final source = store.sourceFor(ref);
|
final source = store.sourceFor(ref);
|
||||||
final picture = imageFor(source, fit: fit);
|
final picture = imageFor(source, fit: fit);
|
||||||
|
// Spoken only: nothing paints this string.
|
||||||
|
const semanticLabel = 'Attached image';
|
||||||
return Semantics(
|
return Semantics(
|
||||||
label: 'Attached image',
|
label: semanticLabel,
|
||||||
button: source is! MissingImageSource,
|
button: source is! MissingImageSource,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: source is MissingImageSource
|
onTap: source is MissingImageSource
|
||||||
? null
|
? null
|
||||||
: () => Navigator.of(context).push<void>(
|
: () => Navigator.of(context).push<void>(
|
||||||
appRoute(context, (_) => ImageViewerScreen(source: source)),
|
appRoute(
|
||||||
|
context,
|
||||||
|
(_) => ImageViewerScreen(source: source),
|
||||||
|
name: '/image',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
@ -52,9 +58,10 @@ class ImageEmbed extends StatelessWidget {
|
|||||||
const Positioned(
|
const Positioned(
|
||||||
right: 4,
|
right: 4,
|
||||||
top: 4,
|
top: 4,
|
||||||
child: Tooltip(
|
child: Icon(
|
||||||
message: kImageWaitingToUpload,
|
Icons.cloud_upload_outlined,
|
||||||
child: Icon(Icons.cloud_upload_outlined, size: 18),
|
size: 18,
|
||||||
|
semanticLabel: kImageWaitingToUpload,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -85,7 +92,7 @@ Widget imageFor(ImageSource source, {required BoxFit fit}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Grey box with [kImageNotDownloaded].
|
/// Grey box with a download glyph, spoken as [kImageNotDownloaded].
|
||||||
class ImagePlaceholder extends StatelessWidget {
|
class ImagePlaceholder extends StatelessWidget {
|
||||||
/// Creates the placeholder.
|
/// Creates the placeholder.
|
||||||
const ImagePlaceholder({super.key});
|
const ImagePlaceholder({super.key});
|
||||||
@ -98,10 +105,10 @@ class ImagePlaceholder extends StatelessWidget {
|
|||||||
child: Center(
|
child: Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
child: Text(
|
child: Icon(
|
||||||
kImageNotDownloaded,
|
Icons.cloud_download_outlined,
|
||||||
textAlign: TextAlign.center,
|
color: theme.colorScheme.outline,
|
||||||
style: theme.textTheme.bodySmall,
|
semanticLabel: kImageNotDownloaded,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/attachments/image_store_api.dart';
|
import 'package:todo/attachments/image_store_api.dart';
|
||||||
import 'package:todo/ui/images/image_embed.dart';
|
import 'package:todo/ui/images/image_embed.dart';
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/images/attachment_links.dart';
|
import 'package:todo/images/attachment_links.dart';
|
||||||
import 'package:todo/ui/images/file_embed.dart';
|
import 'package:todo/ui/images/file_embed.dart';
|
||||||
|
|||||||
@ -6,10 +6,11 @@ library;
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
import 'package:todo/ui/confirm_delete.dart';
|
||||||
|
import 'package:todo/ui/enum_glyphs.dart';
|
||||||
import 'package:todo/ui/note_sheet_details.dart';
|
import 'package:todo/ui/note_sheet_details.dart';
|
||||||
import 'package:todo/ui/note_task_details.dart';
|
import 'package:todo/ui/note_task_details.dart';
|
||||||
|
|
||||||
@ -61,53 +62,55 @@ class _NoteActionsSheetState extends State<NoteActionsSheet> {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// User content; untitled shows nothing, not a placeholder.
|
||||||
firstLine.isEmpty ? '(empty)' : firstLine,
|
if (firstLine.isNotEmpty)
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
Text(
|
||||||
maxLines: 2,
|
firstLine,
|
||||||
overflow: TextOverflow.ellipsis,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
NoteSheetDetails(note: widget.note),
|
NoteSheetDetails(note: widget.note),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_EnumChips<Status>(
|
GlyphChips<Status>(
|
||||||
label: 'Status',
|
heading: kStatusHeadingIcon,
|
||||||
|
semanticLabel: 'Status',
|
||||||
values: Status.values,
|
values: Status.values,
|
||||||
selected: {_status},
|
selected: {_status},
|
||||||
labelOf: (s) => s.label,
|
glyphOf: statusGlyph,
|
||||||
onSelected: (s) {
|
onTap: (s) {
|
||||||
setState(() => _status = s);
|
setState(() => _status = s);
|
||||||
unawaited(_persist());
|
unawaited(_persist());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_EnumChips<Priority>(
|
GlyphChips<Priority>(
|
||||||
label: 'Priority',
|
heading: kPriorityHeadingIcon,
|
||||||
|
semanticLabel: 'Priority',
|
||||||
values: Priority.values,
|
values: Priority.values,
|
||||||
selected: {_priority},
|
selected: {_priority},
|
||||||
labelOf: (p) => p.label,
|
glyphOf: (p) => priorityGlyph(context, p),
|
||||||
onSelected: (p) {
|
onTap: (p) {
|
||||||
setState(() => _priority = p);
|
setState(() => _priority = p);
|
||||||
unawaited(_persist());
|
unawaited(_persist());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
NoteTaskDetails(note: widget.note),
|
NoteTaskDetails(note: widget.note),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
OutlinedButton.icon(
|
Align(
|
||||||
icon: const Icon(Icons.delete_outline),
|
child: IconButton.outlined(
|
||||||
label: const Text('Delete note'),
|
tooltip: 'delete',
|
||||||
style: OutlinedButton.styleFrom(
|
color: Theme.of(context).colorScheme.error,
|
||||||
foregroundColor: Theme.of(context).colorScheme.error,
|
icon: const Icon(
|
||||||
|
Icons.delete_outline,
|
||||||
|
semanticLabel: 'Delete note',
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
if (!await confirmDeleteNote(context)) return;
|
||||||
|
await widget.onDelete();
|
||||||
|
if (context.mounted) Navigator.of(context).pop();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
|
||||||
final confirmed = await confirmDestructive(
|
|
||||||
context,
|
|
||||||
title: 'Delete note?',
|
|
||||||
message: 'This cannot be undone.',
|
|
||||||
);
|
|
||||||
if (!confirmed) return;
|
|
||||||
await widget.onDelete();
|
|
||||||
if (context.mounted) Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -116,42 +119,3 @@ class _NoteActionsSheetState extends State<NoteActionsSheet> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Single-select chip row for an enum (used for per-note priority/status).
|
|
||||||
class _EnumChips<T> extends StatelessWidget {
|
|
||||||
const _EnumChips({
|
|
||||||
required this.label,
|
|
||||||
required this.values,
|
|
||||||
required this.selected,
|
|
||||||
required this.labelOf,
|
|
||||||
required this.onSelected,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String label;
|
|
||||||
final List<T> values;
|
|
||||||
final Set<T> selected;
|
|
||||||
final String Function(T) labelOf;
|
|
||||||
final ValueChanged<T> onSelected;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(label, style: Theme.of(context).textTheme.labelLarge),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
for (final v in values)
|
|
||||||
ChoiceChip(
|
|
||||||
label: Text(labelOf(v)),
|
|
||||||
selected: selected.contains(v),
|
|
||||||
onSelected: (_) => onSelected(v),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,21 +7,33 @@ library;
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
/// Glyph for "created" (a note added), shared by the filter and sort menus.
|
||||||
|
const IconData kCreatedIcon = Icons.post_add;
|
||||||
|
|
||||||
|
/// Glyph for "last updated", shared by the filter and sort menus.
|
||||||
|
const IconData kUpdatedIcon = Icons.update;
|
||||||
|
|
||||||
/// A labelled date range shown as one preset menu plus a custom picker.
|
/// A labelled date range shown as one preset menu plus a custom picker.
|
||||||
|
///
|
||||||
|
/// One-word tooltips on hover/long-press per textgate rule.
|
||||||
class DateRangeField extends StatelessWidget {
|
class DateRangeField extends StatelessWidget {
|
||||||
/// Creates a labelled date-range control.
|
/// Creates a labelled date-range control.
|
||||||
const DateRangeField({
|
const DateRangeField({
|
||||||
required this.label,
|
required this.icon,
|
||||||
|
required this.semanticLabel,
|
||||||
required this.from,
|
required this.from,
|
||||||
required this.to,
|
required this.to,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Heading shown above the control (e.g. 'Created').
|
/// Glyph shown in the control's border in place of a written heading.
|
||||||
final String label;
|
final IconData icon;
|
||||||
|
|
||||||
|
/// Spoken name of the control (e.g. 'Created'); never painted.
|
||||||
|
final String semanticLabel;
|
||||||
|
|
||||||
/// Start of the selected range, or null when unbounded.
|
/// Start of the selected range, or null when unbounded.
|
||||||
final DateTime? from;
|
final DateTime? from;
|
||||||
@ -86,15 +98,33 @@ class DateRangeField extends StatelessWidget {
|
|||||||
// A popup menu rather than DropdownButton: re-picking "Custom…" while a
|
// A popup menu rather than DropdownButton: re-picking "Custom…" while a
|
||||||
// custom range is shown must still reopen the picker.
|
// custom range is shown must still reopen the picker.
|
||||||
return PopupMenuButton<_Preset>(
|
return PopupMenuButton<_Preset>(
|
||||||
tooltip: label,
|
tooltip: 'range',
|
||||||
onSelected: (p) => _select(context, p),
|
onSelected: (p) => _select(context, p),
|
||||||
itemBuilder: (_) => [
|
itemBuilder: (_) => [
|
||||||
for (final p in _Preset.values)
|
PopupMenuItem(
|
||||||
PopupMenuItem(value: p, child: Text(p.label)),
|
value: _Preset.any,
|
||||||
|
child: Tooltip(message: 'any', child: _Preset.any.glyph()),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _Preset.today,
|
||||||
|
child: Tooltip(message: 'today', child: _Preset.today.glyph()),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _Preset.week,
|
||||||
|
child: Tooltip(message: 'week', child: _Preset.week.glyph()),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _Preset.month,
|
||||||
|
child: Tooltip(message: 'month', child: _Preset.month.glyph()),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _Preset.custom,
|
||||||
|
child: Tooltip(message: 'custom', child: _Preset.custom.glyph()),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: InputDecorator(
|
child: InputDecorator(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: label,
|
prefixIcon: Icon(icon, semanticLabel: semanticLabel),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
@ -103,10 +133,9 @@ class DateRangeField extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
suffixIcon: const Icon(Icons.arrow_drop_down),
|
suffixIcon: const Icon(Icons.arrow_drop_down),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: current == _Preset.custom
|
||||||
current == _Preset.custom ? _rangeLabel() : current.label,
|
? Text(_rangeLabel(), style: theme.textTheme.bodyMedium)
|
||||||
style: theme.textTheme.bodyMedium,
|
: current.glyph(),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -131,8 +160,26 @@ enum _Preset {
|
|||||||
|
|
||||||
const _Preset(this.label, this.days);
|
const _Preset(this.label, this.days);
|
||||||
|
|
||||||
|
/// Spoken name only; what is painted is [glyph].
|
||||||
final String label;
|
final String label;
|
||||||
final int? days;
|
final int? days;
|
||||||
|
|
||||||
|
/// "Any" is an infinity sign, "today" the today-calendar, a span its day
|
||||||
|
/// count beside a range-calendar, "custom" the edit-calendar.
|
||||||
|
Widget glyph() => Semantics(
|
||||||
|
label: label,
|
||||||
|
excludeSemantics: true,
|
||||||
|
container: true,
|
||||||
|
child: switch (this) {
|
||||||
|
any => const Icon(Icons.all_inclusive),
|
||||||
|
today => const Icon(Icons.today),
|
||||||
|
custom => const Icon(Icons.edit_calendar),
|
||||||
|
week || month => Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [const Icon(Icons.date_range), Text(' $days')],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
static const List<_Preset> dayPresets = [today, week, month];
|
static const List<_Preset> dayPresets = [today, week, month];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:todo/data/app_settings.dart';
|
import 'package:todo/data/app_settings.dart';
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
import 'package:todo/ui/attachment_picking.dart';
|
import 'package:todo/ui/attachment_picking.dart';
|
||||||
|
import 'package:todo/ui/confirm_delete.dart';
|
||||||
import 'package:todo/ui/image_attach.dart';
|
import 'package:todo/ui/image_attach.dart';
|
||||||
import 'package:todo/ui/image_input.dart';
|
import 'package:todo/ui/image_input.dart';
|
||||||
import 'package:todo/ui/note_form.dart';
|
import 'package:todo/ui/note_form.dart';
|
||||||
@ -85,12 +85,7 @@ class _NoteDetailScreenState extends State<NoteDetailScreen> {
|
|||||||
_persist(_note.copyWith(text: text, updatedAt: DateTime.now()));
|
_persist(_note.copyWith(text: text, updatedAt: DateTime.now()));
|
||||||
|
|
||||||
Future<void> _delete() async {
|
Future<void> _delete() async {
|
||||||
final confirmed = await confirmDestructive(
|
if (!await confirmDeleteNote(context)) return;
|
||||||
context,
|
|
||||||
title: 'Delete note?',
|
|
||||||
message: 'This cannot be undone.',
|
|
||||||
);
|
|
||||||
if (!confirmed) return;
|
|
||||||
await widget.repository.delete(_note.id);
|
await widget.repository.delete(_note.id);
|
||||||
if (mounted) Navigator.of(context).pop();
|
if (mounted) Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
@ -100,13 +95,15 @@ class _NoteDetailScreenState extends State<NoteDetailScreen> {
|
|||||||
final title = noteTitle(_note.text);
|
final title = noteTitle(_note.text);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(title.isEmpty ? '(empty)' : title),
|
// An untitled note shows no title rather than a written placeholder.
|
||||||
|
title: title.isEmpty ? null : Text(title),
|
||||||
actions: [
|
actions: [
|
||||||
AttachButton(
|
AttachButton(
|
||||||
onFiles: _attachFiles,
|
onFiles: _attachFiles,
|
||||||
picking: widget.attachmentPicking,
|
picking: widget.attachmentPicking,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
|
tooltip: 'copy',
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_copied ? Icons.check : Icons.copy_all,
|
_copied ? Icons.check : Icons.copy_all,
|
||||||
semanticLabel: 'Copy',
|
semanticLabel: 'Copy',
|
||||||
@ -114,8 +111,11 @@ class _NoteDetailScreenState extends State<NoteDetailScreen> {
|
|||||||
onPressed: _copy,
|
onPressed: _copy,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Delete note',
|
tooltip: 'delete',
|
||||||
icon: const Icon(Icons.delete_outline),
|
icon: const Icon(
|
||||||
|
Icons.delete_outline,
|
||||||
|
semanticLabel: 'Delete note',
|
||||||
|
),
|
||||||
onPressed: _delete,
|
onPressed: _delete,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import 'package:design_system/design_system.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
import 'package:todo/ui/cue_snack.dart';
|
||||||
import 'package:todo/ui/image_attach.dart';
|
import 'package:todo/ui/image_attach.dart';
|
||||||
import 'package:todo/ui/markdown_view.dart';
|
import 'package:todo/ui/markdown_view.dart';
|
||||||
import 'package:todo/ui/note_editor_chrome.dart';
|
import 'package:todo/ui/note_editor_chrome.dart';
|
||||||
@ -127,9 +127,12 @@ class _NoteEditorState extends State<NoteEditor> {
|
|||||||
case NoteEditorMode.guided:
|
case NoteEditorMode.guided:
|
||||||
// raw -> guided: only if the edited text still fits the template.
|
// raw -> guided: only if the edited text still fits the template.
|
||||||
if (!_doc.tryAdoptGuided()) {
|
if (!_doc.tryAdoptGuided()) {
|
||||||
showError(
|
// The mode toggle staying on raw is the second channel.
|
||||||
|
showCue(
|
||||||
context,
|
context,
|
||||||
|
Icons.rule,
|
||||||
"Text doesn't match the template — staying in raw",
|
"Text doesn't match the template — staying in raw",
|
||||||
|
error: true,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,11 @@
|
|||||||
/// built in Preview and Raw.
|
/// built in Preview and Raw.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
import 'package:todo/ui/note_editor_mode.dart';
|
import 'package:todo/ui/note_editor_mode.dart';
|
||||||
|
import 'package:todo/ui/template_glyphs.dart';
|
||||||
|
|
||||||
/// Template dropdown above a segmented View / Guided / Raw selector.
|
/// Template dropdown above a segmented View / Guided / Raw selector.
|
||||||
class NoteEditorChrome extends StatelessWidget {
|
class NoteEditorChrome extends StatelessWidget {
|
||||||
@ -43,20 +44,20 @@ class NoteEditorChrome extends StatelessWidget {
|
|||||||
DropdownButtonFormField<String>(
|
DropdownButtonFormField<String>(
|
||||||
initialValue: template.id,
|
initialValue: template.id,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Template',
|
// A prefix, not a floating label: a floated icon sat on the
|
||||||
|
// border on top of the selected template's glyph.
|
||||||
|
prefixIcon: Icon(Icons.description, semanticLabel: 'Template'),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
),
|
),
|
||||||
items: [
|
items: [
|
||||||
for (final t in NoteTemplate.all)
|
for (final t in NoteTemplate.all)
|
||||||
DropdownMenuItem(value: t.id, child: Text(t.label)),
|
DropdownMenuItem(value: t.id, child: templateGlyph(t)),
|
||||||
],
|
],
|
||||||
onChanged: (id) {
|
onChanged: (id) {
|
||||||
if (id == null) return;
|
if (id == null) return;
|
||||||
onTemplateSelected(
|
onTemplateSelected(NoteTemplate.all.firstWhere((t) => t.id == id));
|
||||||
NoteTemplate.all.firstWhere((t) => t.id == id),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
@ -67,8 +68,7 @@ class NoteEditorChrome extends StatelessWidget {
|
|||||||
segments: [
|
segments: [
|
||||||
const ButtonSegment(
|
const ButtonSegment(
|
||||||
value: NoteEditorMode.preview,
|
value: NoteEditorMode.preview,
|
||||||
icon: Icon(Icons.visibility_outlined),
|
icon: Icon(Icons.visibility_outlined, semanticLabel: 'View'),
|
||||||
label: Text('View'),
|
|
||||||
),
|
),
|
||||||
// Guided is offered for any structured template; tapping it
|
// Guided is offered for any structured template; tapping it
|
||||||
// on an empty draft opens the wizard, and is blocked at
|
// on an empty draft opens the wizard, and is blocked at
|
||||||
@ -76,13 +76,11 @@ class NoteEditorChrome extends StatelessWidget {
|
|||||||
if (!template.isFreeform)
|
if (!template.isFreeform)
|
||||||
const ButtonSegment(
|
const ButtonSegment(
|
||||||
value: NoteEditorMode.guided,
|
value: NoteEditorMode.guided,
|
||||||
icon: Icon(Icons.checklist),
|
icon: Icon(Icons.checklist, semanticLabel: 'Guided'),
|
||||||
label: Text('Guided'),
|
|
||||||
),
|
),
|
||||||
const ButtonSegment(
|
const ButtonSegment(
|
||||||
value: NoteEditorMode.raw,
|
value: NoteEditorMode.raw,
|
||||||
icon: Icon(Icons.notes),
|
icon: Icon(Icons.notes, semanticLabel: 'Raw'),
|
||||||
label: Text('Raw'),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
selected: {mode},
|
selected: {mode},
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
/// [body] and the editor shows the raw field instead.
|
/// [body] and the editor shows the raw field instead.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
/// A full-height plain-text field for the note's assembled Markdown.
|
/// A full-height plain-text field for the note's assembled Markdown.
|
||||||
class NoteEditorRawField extends StatelessWidget {
|
class NoteEditorRawField extends StatelessWidget {
|
||||||
@ -44,10 +44,8 @@ class NoteEditorRawField extends StatelessWidget {
|
|||||||
textAlignVertical: TextAlignVertical.top,
|
textAlignVertical: TextAlignVertical.top,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
decoration: const InputDecoration(
|
// No hint: the cursor in an empty full-height box says "type".
|
||||||
border: InputBorder.none,
|
decoration: const InputDecoration(border: InputBorder.none),
|
||||||
hintText: 'Write your idea…',
|
|
||||||
),
|
|
||||||
onChanged: (_) => onChanged(),
|
onChanged: (_) => onChanged(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -12,10 +12,11 @@
|
|||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
import 'package:todo/ui/motion.dart';
|
import 'package:todo/ui/motion.dart';
|
||||||
|
import 'package:todo/ui/template_glyphs.dart';
|
||||||
|
|
||||||
/// One step of the guided editor: label, guidance, input, and navigation.
|
/// One step of the guided editor: label, guidance, input, and navigation.
|
||||||
class NoteEditorStepPage extends StatelessWidget {
|
class NoteEditorStepPage extends StatelessWidget {
|
||||||
@ -66,8 +67,8 @@ class NoteEditorStepPage extends StatelessWidget {
|
|||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Icons.arrow_back),
|
tooltip: 'exit',
|
||||||
tooltip: 'Exit guided',
|
icon: const Icon(Icons.arrow_back, semanticLabel: 'Exit guided'),
|
||||||
onPressed: onExit,
|
onPressed: onExit,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -96,16 +97,14 @@ class NoteEditorStepPage extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// A glyph per section; its label (the note's `## heading`) and
|
||||||
section.isTitle ? 'title' : section.label,
|
// the helper sentence are spoken only.
|
||||||
style: theme.textTheme.titleMedium,
|
Icon(
|
||||||
),
|
sectionIcon(section),
|
||||||
const SizedBox(height: 4),
|
color: theme.colorScheme.primary,
|
||||||
Text(
|
semanticLabel: section.isTitle
|
||||||
section.helper,
|
? section.helper
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
: '${section.label}: ${section.helper}',
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
],
|
],
|
||||||
@ -123,9 +122,10 @@ class NoteEditorStepPage extends StatelessWidget {
|
|||||||
maxLines: null,
|
maxLines: null,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
textAlignVertical: TextAlignVertical.top,
|
textAlignVertical: TextAlignVertical.top,
|
||||||
decoration: InputDecoration(
|
// No hintText: a hint is painted text. The section glyph
|
||||||
hintText: section.hint,
|
// above already names the field.
|
||||||
border: const OutlineInputBorder(),
|
decoration: const InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
),
|
),
|
||||||
onChanged: (_) => onChanged(),
|
onChanged: (_) => onChanged(),
|
||||||
@ -140,16 +140,22 @@ class NoteEditorStepPage extends StatelessWidget {
|
|||||||
if (index > 0)
|
if (index > 0)
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => onGoToStep(index - 1),
|
onPressed: () => onGoToStep(index - 1),
|
||||||
child: const Text('Back'),
|
child: const Icon(
|
||||||
|
Icons.navigate_before,
|
||||||
|
semanticLabel: 'Back',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
if (index < total - 1)
|
if (index < total - 1)
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: () => onGoToStep(index + 1),
|
onPressed: () => onGoToStep(index + 1),
|
||||||
child: const Text('Next'),
|
child: const Icon(Icons.navigate_next, semanticLabel: 'Next'),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
FilledButton(onPressed: onExit, child: const Text('Done')),
|
FilledButton(
|
||||||
|
onPressed: onExit,
|
||||||
|
child: const Icon(Icons.check, semanticLabel: 'Done'),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -9,10 +9,12 @@
|
|||||||
/// make sense before there is anything to guide.
|
/// make sense before there is anything to guide.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
import 'package:todo/ui/enum_glyphs.dart';
|
||||||
|
import 'package:todo/ui/template_glyphs.dart';
|
||||||
|
|
||||||
/// Asks for a priority, then a template, then hands both back via [onStart].
|
/// Asks for a priority, then a template, then hands both back via [onStart].
|
||||||
class NoteEditorWizard extends StatefulWidget {
|
class NoteEditorWizard extends StatefulWidget {
|
||||||
@ -48,7 +50,7 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final semanticLabel = 'Step ${_step + 1} of 2';
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@ -56,11 +58,25 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.close),
|
tooltip: 'cancel',
|
||||||
tooltip: 'Cancel',
|
icon: const Icon(Icons.close, semanticLabel: 'Cancel'),
|
||||||
onPressed: widget.onCancel,
|
onPressed: widget.onCancel,
|
||||||
),
|
),
|
||||||
Text('Step ${_step + 1} of 2', style: theme.textTheme.labelLarge),
|
// Two step dots, the current one filled: position by shape.
|
||||||
|
Semantics(
|
||||||
|
label: semanticLabel,
|
||||||
|
child: ExcludeSemantics(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
Icon(
|
||||||
|
i == _step ? Icons.circle : Icons.circle_outlined,
|
||||||
|
size: 12,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
@ -74,14 +90,14 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
|
|||||||
DropdownButtonFormField<Priority>(
|
DropdownButtonFormField<Priority>(
|
||||||
initialValue: _priority,
|
initialValue: _priority,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Priority',
|
prefixIcon: Icon(kPriorityHeadingIcon, semanticLabel: 'Priority'),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
),
|
),
|
||||||
items: [
|
items: [
|
||||||
for (final p in Priority.values)
|
for (final p in Priority.values)
|
||||||
DropdownMenuItem(value: p, child: Text(p.label)),
|
DropdownMenuItem(value: p, child: priorityGlyph(context, p)),
|
||||||
],
|
],
|
||||||
onChanged: (p) {
|
onChanged: (p) {
|
||||||
if (p != null) setState(() => _priority = p);
|
if (p != null) setState(() => _priority = p);
|
||||||
@ -92,7 +108,7 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
|
|||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
onPressed: () => setState(() => _step = 1),
|
onPressed: () => setState(() => _step = 1),
|
||||||
child: const Text('Next'),
|
child: const Icon(Icons.navigate_next, semanticLabel: 'Next'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
@ -104,14 +120,14 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
|
|||||||
DropdownButtonFormField<String>(
|
DropdownButtonFormField<String>(
|
||||||
initialValue: _template.id,
|
initialValue: _template.id,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Template',
|
prefixIcon: Icon(Icons.description, semanticLabel: 'Template'),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
),
|
),
|
||||||
items: [
|
items: [
|
||||||
for (final t in templates)
|
for (final t in templates)
|
||||||
DropdownMenuItem(value: t.id, child: Text(t.label)),
|
DropdownMenuItem(value: t.id, child: templateGlyph(t)),
|
||||||
],
|
],
|
||||||
onChanged: (id) {
|
onChanged: (id) {
|
||||||
if (id == null) return;
|
if (id == null) return;
|
||||||
@ -124,12 +140,12 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
|
|||||||
children: [
|
children: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => setState(() => _step = 0),
|
onPressed: () => setState(() => _step = 0),
|
||||||
child: const Text('Back'),
|
child: const Icon(Icons.arrow_back, semanticLabel: 'Back'),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: () => widget.onStart(_priority, _template),
|
onPressed: () => widget.onStart(_priority, _template),
|
||||||
child: const Text('Start'),
|
child: const Icon(Icons.play_arrow, semanticLabel: 'Start'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
/// defaults to false.
|
/// defaults to false.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
/// lives here so both surfaces resolve visibility by the same rule.
|
/// lives here so both surfaces resolve visibility by the same rule.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
/// Holds the editor's chrome-visibility signal and resolves it against
|
/// Holds the editor's chrome-visibility signal and resolves it against
|
||||||
/// advanced mode.
|
/// advanced mode.
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
import 'package:todo/ui/enum_glyphs.dart';
|
||||||
|
|
||||||
/// Danger for high, the accent for medium, muted for low.
|
/// Danger for high, the accent for medium, muted for low.
|
||||||
Color priorityColor(Priority p, ColorScheme scheme) => switch (p) {
|
Color priorityColor(Priority p, ColorScheme scheme) => switch (p) {
|
||||||
@ -14,6 +15,9 @@ Color priorityColor(Priority p, ColorScheme scheme) => switch (p) {
|
|||||||
Priority.low => scheme.outline,
|
Priority.low => scheme.outline,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Painted in place of an empty note's title: a mark, not a word.
|
||||||
|
const String kEmptyTitle = '…';
|
||||||
|
|
||||||
/// The glyph standing for [s] wherever a status is shown without words.
|
/// The glyph standing for [s] wherever a status is shown without words.
|
||||||
IconData statusIcon(Status s) => switch (s) {
|
IconData statusIcon(Status s) => switch (s) {
|
||||||
Status.todo => Icons.radio_button_unchecked,
|
Status.todo => Icons.radio_button_unchecked,
|
||||||
@ -85,7 +89,7 @@ class NoteGridTile extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
title.isEmpty ? '(empty)' : title,
|
title.isEmpty ? kEmptyTitle : title,
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
@ -115,25 +119,20 @@ class NoteGridTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
|
// Shape + the tile's accent border carry status/priority;
|
||||||
|
// the enum words survive only as spoken labels.
|
||||||
Icon(
|
Icon(
|
||||||
statusIcon(note.status),
|
statusIcon(note.status),
|
||||||
size: 14,
|
size: 14,
|
||||||
color: scheme.onSurfaceVariant,
|
color: scheme.onSurfaceVariant,
|
||||||
),
|
semanticLabel: note.status.label,
|
||||||
const SizedBox(width: AppSpacing.xs),
|
|
||||||
Flexible(
|
|
||||||
child: Text(
|
|
||||||
note.status.label,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: cue,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Text(
|
Icon(
|
||||||
note.priority.label,
|
priorityIcon(note.priority),
|
||||||
maxLines: 1,
|
size: 14,
|
||||||
style: cue?.copyWith(color: accentFor(scheme)),
|
color: accentFor(scheme),
|
||||||
|
semanticLabel: note.priority.label,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -5,27 +5,33 @@
|
|||||||
/// two cannot drift apart. Public only because Dart privacy is library-scoped.
|
/// two cannot drift apart. Public only because Dart privacy is library-scoped.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
|
import 'package:todo/ui/enum_glyphs.dart';
|
||||||
|
|
||||||
/// A compact labelled dropdown for picking an enum value (priority/status).
|
/// A compact dropdown for picking an enum value (priority/status), headed by
|
||||||
|
/// a glyph and showing each value as its glyph.
|
||||||
///
|
///
|
||||||
/// Generic over the enum type [T] so the same control drives both pickers
|
/// Generic over the enum type [T] so the same control drives both pickers
|
||||||
/// without duplication; [labelOf] maps a value to its display string.
|
/// without duplication; [glyphOf] maps a value to its glyph.
|
||||||
class MetaDropdown<T> extends StatelessWidget {
|
class MetaDropdown<T> extends StatelessWidget {
|
||||||
/// Creates a dropdown showing [value] out of [values].
|
/// Creates a dropdown showing [value] out of [values].
|
||||||
const MetaDropdown({
|
const MetaDropdown({
|
||||||
required this.label,
|
required this.heading,
|
||||||
|
required this.semanticLabel,
|
||||||
required this.value,
|
required this.value,
|
||||||
required this.values,
|
required this.values,
|
||||||
required this.labelOf,
|
required this.glyphOf,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Label shown above the control.
|
/// Glyph in the control's border in place of a written heading.
|
||||||
final String label;
|
final IconData heading;
|
||||||
|
|
||||||
|
/// Spoken name of the control; never painted.
|
||||||
|
final String semanticLabel;
|
||||||
|
|
||||||
/// Currently selected value.
|
/// Currently selected value.
|
||||||
final T value;
|
final T value;
|
||||||
@ -33,8 +39,8 @@ class MetaDropdown<T> extends StatelessWidget {
|
|||||||
/// Every selectable value.
|
/// Every selectable value.
|
||||||
final List<T> values;
|
final List<T> values;
|
||||||
|
|
||||||
/// Maps a value to its display string.
|
/// Maps a value to its glyph.
|
||||||
final String Function(T) labelOf;
|
final Widget Function(T) glyphOf;
|
||||||
|
|
||||||
/// Called with the newly picked value.
|
/// Called with the newly picked value.
|
||||||
final ValueChanged<T> onChanged;
|
final ValueChanged<T> onChanged;
|
||||||
@ -43,7 +49,7 @@ class MetaDropdown<T> extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InputDecorator(
|
return InputDecorator(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: label,
|
prefixIcon: Icon(heading, semanticLabel: semanticLabel),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
@ -55,7 +61,7 @@ class MetaDropdown<T> extends StatelessWidget {
|
|||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
items: [
|
items: [
|
||||||
for (final v in values)
|
for (final v in values)
|
||||||
DropdownMenuItem<T>(value: v, child: Text(labelOf(v))),
|
DropdownMenuItem<T>(value: v, child: glyphOf(v)),
|
||||||
],
|
],
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
if (v != null) onChanged(v);
|
if (v != null) onChanged(v);
|
||||||
@ -98,20 +104,22 @@ class NoteMetaRow extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: MetaDropdown<Priority>(
|
child: MetaDropdown<Priority>(
|
||||||
label: 'Priority',
|
heading: kPriorityHeadingIcon,
|
||||||
|
semanticLabel: 'Priority',
|
||||||
value: priority,
|
value: priority,
|
||||||
values: Priority.values,
|
values: Priority.values,
|
||||||
labelOf: (p) => p.label,
|
glyphOf: (p) => priorityGlyph(context, p),
|
||||||
onChanged: onPriorityChanged,
|
onChanged: onPriorityChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: MetaDropdown<Status>(
|
child: MetaDropdown<Status>(
|
||||||
label: 'Status',
|
heading: kStatusHeadingIcon,
|
||||||
|
semanticLabel: 'Status',
|
||||||
value: status,
|
value: status,
|
||||||
values: Status.values,
|
values: Status.values,
|
||||||
labelOf: (s) => s.label,
|
glyphOf: statusGlyph,
|
||||||
onChanged: onStatusChanged,
|
onChanged: onStatusChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/images/attachment_links.dart';
|
import 'package:todo/images/attachment_links.dart';
|
||||||
@ -39,12 +39,25 @@ class NoteSheetDetails extends StatelessWidget {
|
|||||||
Text(body, style: theme.bodyMedium),
|
Text(body, style: theme.bodyMedium),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Text(
|
Wrap(
|
||||||
'Edited ${_stamp(note.updatedAt)}'
|
spacing: 12,
|
||||||
' · Created ${_stamp(note.createdAt)}',
|
children: [
|
||||||
style: theme.bodySmall,
|
_dated(Icons.history, 'Edited', note.updatedAt, theme.bodySmall),
|
||||||
|
_dated(Icons.add, 'Created', note.createdAt, theme.bodySmall),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A glyph (edited = history, created = plus) before its timestamp.
|
||||||
|
Widget _dated(IconData icon, String spoken, DateTime t, TextStyle? style) =>
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 16, semanticLabel: spoken),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(_stamp(t), style: style),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
|
|
||||||
/// Read-only repo-task fields of [note]; empty for a plain idea.
|
/// Read-only repo-task fields of [note]; empty for a plain idea.
|
||||||
@ -12,20 +12,27 @@ class NoteTaskDetails extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context).textTheme;
|
final theme = Theme.of(context).textTheme;
|
||||||
|
// A glyph per field in place of its written name (kept spoken only);
|
||||||
|
// the values are content and stay as typed.
|
||||||
final rows = [
|
final rows = [
|
||||||
('Repo', note.repo),
|
(Icons.folder_outlined, 'Repo', note.repo),
|
||||||
('Done check', note.doneCheck),
|
(Icons.fact_check_outlined, 'Done check', note.doneCheck),
|
||||||
('By', note.by),
|
(Icons.person_outline, 'By', note.by),
|
||||||
('Evidence', note.evidence),
|
(Icons.verified_outlined, 'Evidence', note.evidence),
|
||||||
].where((row) => row.$2 != null);
|
].where((row) => row.$3 != null);
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
for (final (label, value) in rows) ...[
|
for (final (icon, label, value) in rows) ...[
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Text(label, style: theme.labelLarge),
|
Row(
|
||||||
const SizedBox(height: 4),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Text(value!, style: theme.bodyMedium),
|
children: [
|
||||||
|
Icon(icon, size: 20, semanticLabel: label),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(child: Text(value!, style: theme.bodyMedium)),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@ -4,10 +4,12 @@
|
|||||||
/// Dart privacy is library-scoped.
|
/// Dart privacy is library-scoped.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_template.dart';
|
import 'package:todo/data/note_template.dart';
|
||||||
|
import 'package:todo/ui/enum_glyphs.dart';
|
||||||
|
import 'package:todo/ui/note_grid_tile.dart';
|
||||||
|
|
||||||
/// One row in the notes list: title, metadata line, and an actions button.
|
/// One row in the notes list: title, metadata line, and an actions button.
|
||||||
class NoteTile extends StatelessWidget {
|
class NoteTile extends StatelessWidget {
|
||||||
@ -37,27 +39,20 @@ class NoteTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final firstLine = noteTitle(note.text);
|
final firstLine = noteTitle(note.text);
|
||||||
// Every note has a status and a priority now, so both are always shown.
|
|
||||||
final meta = <String>[
|
|
||||||
note.status.label,
|
|
||||||
note.priority.label,
|
|
||||||
'edited ${_relative(note.updatedAt)}',
|
|
||||||
?note.repoName,
|
|
||||||
].join(' · ');
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
selected: selected,
|
selected: selected,
|
||||||
leading: selected
|
leading: selected
|
||||||
? const Icon(Icons.check_circle, semanticLabel: 'Selected')
|
? const Icon(Icons.check_circle, semanticLabel: 'Selected')
|
||||||
: null,
|
: null,
|
||||||
title: Text(
|
title: Text(
|
||||||
firstLine.isEmpty ? '(empty)' : firstLine,
|
firstLine.isEmpty ? kEmptyTitle : firstLine,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
subtitle: Text(meta),
|
subtitle: _meta(context),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: const Icon(Icons.more_vert),
|
tooltip: 'actions',
|
||||||
tooltip: 'Quick actions',
|
icon: const Icon(Icons.more_vert, semanticLabel: 'Quick actions'),
|
||||||
onPressed: onActions,
|
onPressed: onActions,
|
||||||
),
|
),
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
@ -65,14 +60,28 @@ class NoteTile extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compact relative time like "2m ago" for the list subtitle.
|
/// Status and priority glyphs, the edit age, and the repo (content).
|
||||||
String _relative(DateTime t) {
|
/// Every note has a status and a priority, so both are always shown.
|
||||||
final d = DateTime.now().difference(t);
|
Widget _meta(BuildContext context) => Row(
|
||||||
if (d.inMinutes < 1) return 'just now';
|
children: [
|
||||||
if (d.inHours < 1) return '${d.inMinutes}m ago';
|
statusGlyph(note.status, size: 16),
|
||||||
if (d.inDays < 1) return '${d.inHours}h ago';
|
const SizedBox(width: 6),
|
||||||
return '${d.inDays}d ago';
|
priorityGlyph(context, note.priority, size: 16),
|
||||||
}
|
const SizedBox(width: 6),
|
||||||
|
const Icon(Icons.history, size: 16, semanticLabel: 'Edited'),
|
||||||
|
Text(relativeAge(note.updatedAt)),
|
||||||
|
if (note.repoName case final repo?) ...[
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Flexible(child: Text(repo, overflow: TextOverflow.ellipsis)),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bottom sheet for editing one note's priority/status or deleting it.
|
/// Compact age like "2m" / "3h" / "4d": a number plus a unit symbol.
|
||||||
|
String relativeAge(DateTime t) {
|
||||||
|
final d = DateTime.now().difference(t);
|
||||||
|
if (d.inHours < 1) return '${d.inMinutes}m';
|
||||||
|
if (d.inDays < 1) return '${d.inHours}h';
|
||||||
|
return '${d.inDays}d';
|
||||||
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
/// assign never starts a task.
|
/// assign never starts a task.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
import 'package:todo/data/repo_assign.dart';
|
import 'package:todo/data/repo_assign.dart';
|
||||||
|
|||||||
@ -6,10 +6,11 @@
|
|||||||
/// `_NotesListScreenState._openFilters`.
|
/// `_NotesListScreenState._openFilters`.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
|
import 'package:todo/ui/enum_glyphs.dart';
|
||||||
import 'package:todo/ui/note_date_range_field.dart';
|
import 'package:todo/ui/note_date_range_field.dart';
|
||||||
import 'package:todo/ui/notes_list_defaults.dart';
|
import 'package:todo/ui/notes_list_defaults.dart';
|
||||||
|
|
||||||
@ -66,7 +67,6 @@ class _FilterSheetState extends State<FilterSheet> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
@ -82,33 +82,38 @@ class _FilterSheetState extends State<FilterSheet> {
|
|||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text('Filters', style: theme.textTheme.titleLarge),
|
const Icon(Icons.filter_list, semanticLabel: 'Filters'),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: _clearAll,
|
onPressed: _clearAll,
|
||||||
child: const Text('Clear all'),
|
child: const Icon(Icons.clear, semanticLabel: 'Clear all'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
_MultiChips<Status>(
|
GlyphChips<Status>(
|
||||||
label: 'Status',
|
multi: true,
|
||||||
|
heading: kStatusHeadingIcon,
|
||||||
|
semanticLabel: 'Status',
|
||||||
values: Status.values,
|
values: Status.values,
|
||||||
selected: _statuses,
|
selected: _statuses,
|
||||||
labelOf: (s) => s.label,
|
glyphOf: statusGlyph,
|
||||||
onToggle: (s) => _toggle(_statuses, s),
|
onTap: (s) => _toggle(_statuses, s),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_MultiChips<Priority>(
|
GlyphChips<Priority>(
|
||||||
label: 'Priority',
|
multi: true,
|
||||||
|
heading: kPriorityHeadingIcon,
|
||||||
|
semanticLabel: 'Priority',
|
||||||
values: Priority.values,
|
values: Priority.values,
|
||||||
selected: _priorities,
|
selected: _priorities,
|
||||||
labelOf: (p) => p.label,
|
glyphOf: (p) => priorityGlyph(context, p),
|
||||||
onToggle: (p) => _toggle(_priorities, p),
|
onTap: (p) => _toggle(_priorities, p),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
DateRangeField(
|
DateRangeField(
|
||||||
label: 'Created',
|
icon: kCreatedIcon,
|
||||||
|
semanticLabel: 'Created',
|
||||||
from: _createdFrom,
|
from: _createdFrom,
|
||||||
to: _createdTo,
|
to: _createdTo,
|
||||||
onChanged: (from, to) => setState(() {
|
onChanged: (from, to) => setState(() {
|
||||||
@ -118,7 +123,8 @@ class _FilterSheetState extends State<FilterSheet> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
DateRangeField(
|
DateRangeField(
|
||||||
label: 'Last updated',
|
icon: kUpdatedIcon,
|
||||||
|
semanticLabel: 'Last updated',
|
||||||
from: _updatedFrom,
|
from: _updatedFrom,
|
||||||
to: _updatedTo,
|
to: _updatedTo,
|
||||||
onChanged: (from, to) => setState(() {
|
onChanged: (from, to) => setState(() {
|
||||||
@ -129,7 +135,7 @@ class _FilterSheetState extends State<FilterSheet> {
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: () => Navigator.of(context).pop(_build()),
|
onPressed: () => Navigator.of(context).pop(_build()),
|
||||||
child: const Text('Apply'),
|
child: const Icon(Icons.check, semanticLabel: 'Apply'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -139,45 +145,6 @@ class _FilterSheetState extends State<FilterSheet> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Multi-select chip group for an enum (used by the filter sheet).
|
|
||||||
class _MultiChips<T> extends StatelessWidget {
|
|
||||||
const _MultiChips({
|
|
||||||
required this.label,
|
|
||||||
required this.values,
|
|
||||||
required this.selected,
|
|
||||||
required this.labelOf,
|
|
||||||
required this.onToggle,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String label;
|
|
||||||
final List<T> values;
|
|
||||||
final Set<T> selected;
|
|
||||||
final String Function(T) labelOf;
|
|
||||||
final ValueChanged<T> onToggle;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(label, style: Theme.of(context).textTheme.labelLarge),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
for (final v in values)
|
|
||||||
FilterChip(
|
|
||||||
label: Text(labelOf(v)),
|
|
||||||
selected: selected.contains(v),
|
|
||||||
onSelected: (_) => onToggle(v),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A date-range control offering quick presets plus a custom range picker.
|
/// A date-range control offering quick presets plus a custom range picker.
|
||||||
///
|
///
|
||||||
/// Reports the chosen [from]/[to] (day granularity, both inclusive) back to
|
/// Reports the chosen [from]/[to] (day granularity, both inclusive) back to
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/ui/note_grid_tile.dart';
|
import 'package:todo/ui/note_grid_tile.dart';
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
/// Split out of `notes_list_screen.dart` for file size.
|
/// Split out of `notes_list_screen.dart` for file size.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/ui/note_tile.dart';
|
import 'package:todo/ui/note_tile.dart';
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
/// context, the note, and the store.
|
/// context, the note, and the store.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/app_settings.dart';
|
import 'package:todo/data/app_settings.dart';
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
@ -32,6 +32,7 @@ Future<void> openNote(
|
|||||||
repository: repository,
|
repository: repository,
|
||||||
appSettings: appSettings,
|
appSettings: appSettings,
|
||||||
),
|
),
|
||||||
|
name: '/notes/detail',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/app_settings.dart';
|
import 'package:todo/data/app_settings.dart';
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/data/note_repository.dart';
|
import 'package:todo/data/note_repository.dart';
|
||||||
|
import 'package:todo/ui/empty_notes_cue.dart';
|
||||||
import 'package:todo/ui/note_selection.dart';
|
import 'package:todo/ui/note_selection.dart';
|
||||||
import 'package:todo/ui/notes_assign_flow.dart';
|
import 'package:todo/ui/notes_assign_flow.dart';
|
||||||
import 'package:todo/ui/notes_filter_sheet.dart';
|
import 'package:todo/ui/notes_filter_sheet.dart';
|
||||||
@ -134,11 +135,12 @@ class _NotesListScreenState extends State<NotesListScreen> {
|
|||||||
final badgeCount = userFacetCount(_filter);
|
final badgeCount = userFacetCount(_filter);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Notes'),
|
title: const Icon(Icons.note, semanticLabel: 'Notes'),
|
||||||
actions: [
|
actions: [
|
||||||
_selectButton(),
|
_selectButton(),
|
||||||
// Eye, no label: open = Claude-made notes shown, slashed = hidden.
|
// Eye, no label: open = Claude-made notes shown, slashed = hidden.
|
||||||
IconButton(
|
IconButton(
|
||||||
|
tooltip: 'claude',
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
widget.appSettings.value.showClaudeNotes
|
widget.appSettings.value.showClaudeNotes
|
||||||
? Icons.visibility
|
? Icons.visibility
|
||||||
@ -147,30 +149,7 @@ class _NotesListScreenState extends State<NotesListScreen> {
|
|||||||
),
|
),
|
||||||
onPressed: _toggleClaudeNotes,
|
onPressed: _toggleClaudeNotes,
|
||||||
),
|
),
|
||||||
PopupMenuButton<NoteSort>(
|
_sortButton(),
|
||||||
tooltip: 'Sort',
|
|
||||||
icon: const Icon(Icons.sort),
|
|
||||||
initialValue: _sort,
|
|
||||||
onSelected: _setSort,
|
|
||||||
itemBuilder: (_) => const [
|
|
||||||
PopupMenuItem(
|
|
||||||
value: NoteSort.modifiedDesc,
|
|
||||||
child: Text('Last updated'),
|
|
||||||
),
|
|
||||||
PopupMenuItem(
|
|
||||||
value: NoteSort.createdDesc,
|
|
||||||
child: Text('Newest created'),
|
|
||||||
),
|
|
||||||
PopupMenuItem(
|
|
||||||
value: NoteSort.alphabetical,
|
|
||||||
child: Text('Alphabetical'),
|
|
||||||
),
|
|
||||||
PopupMenuItem(
|
|
||||||
value: NoteSort.priorityDesc,
|
|
||||||
child: Text('Priority'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
// Filter icon with a badge counting user-applied facets. The
|
// Filter icon with a badge counting user-applied facets. The
|
||||||
// trailing padding + inward offset keep the badge from being
|
// trailing padding + inward offset keep the badge from being
|
||||||
// clipped at the screen edge.
|
// clipped at the screen edge.
|
||||||
@ -181,8 +160,8 @@ class _NotesListScreenState extends State<NotesListScreen> {
|
|||||||
label: Text('$badgeCount'),
|
label: Text('$badgeCount'),
|
||||||
offset: const Offset(-8, 4),
|
offset: const Offset(-8, 4),
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
tooltip: 'Filter',
|
tooltip: 'filter',
|
||||||
icon: const Icon(Icons.filter_list),
|
icon: const Icon(Icons.filter_list, semanticLabel: 'Filter'),
|
||||||
onPressed: _openFilters,
|
onPressed: _openFilters,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -198,15 +177,16 @@ class _NotesListScreenState extends State<NotesListScreen> {
|
|||||||
onChanged: _onSearchChanged,
|
onChanged: _onSearchChanged,
|
||||||
textInputAction: TextInputAction.search,
|
textInputAction: TextInputAction.search,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Search notes…',
|
|
||||||
prefixIcon: const Icon(Icons.search),
|
prefixIcon: const Icon(Icons.search),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
suffixIcon: _searchController.text.isEmpty
|
suffixIcon: _searchController.text.isEmpty
|
||||||
? null
|
? null
|
||||||
: IconButton(
|
: IconButton(
|
||||||
tooltip: 'Clear search',
|
icon: const Icon(
|
||||||
icon: const Icon(Icons.clear),
|
Icons.clear,
|
||||||
|
semanticLabel: 'Clear search',
|
||||||
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_searchController.clear();
|
_searchController.clear();
|
||||||
_onSearchChanged('');
|
_onSearchChanged('');
|
||||||
@ -223,11 +203,7 @@ class _NotesListScreenState extends State<NotesListScreen> {
|
|||||||
final notes = snapshot.data ?? const <Note>[];
|
final notes = snapshot.data ?? const <Note>[];
|
||||||
if (notes.isEmpty) {
|
if (notes.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Text(
|
child: EmptyNotesCue(filtered: !_filter.isEmpty),
|
||||||
_filter.isEmpty
|
|
||||||
? 'No notes yet'
|
|
||||||
: 'No notes match these filters',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return NotesListBody(
|
return NotesListBody(
|
||||||
|
|||||||
@ -9,6 +9,7 @@ extension _Selecting on _NotesListScreenState {
|
|||||||
/// App-bar toggle into and out of selection mode (tinted while on).
|
/// App-bar toggle into and out of selection mode (tinted while on).
|
||||||
Widget _selectButton() => IconButton(
|
Widget _selectButton() => IconButton(
|
||||||
key: const ValueKey('select-mode'),
|
key: const ValueKey('select-mode'),
|
||||||
|
tooltip: 'select',
|
||||||
isSelected: _selection.active,
|
isSelected: _selection.active,
|
||||||
onPressed: _selection.toggleMode,
|
onPressed: _selection.toggleMode,
|
||||||
icon: const Icon(Icons.checklist, semanticLabel: 'Select'),
|
icon: const Icon(Icons.checklist, semanticLabel: 'Select'),
|
||||||
@ -40,4 +41,43 @@ extension _Selecting on _NotesListScreenState {
|
|||||||
onClear: _selection.clear,
|
onClear: _selection.clear,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// App-bar sort menu: one icon per order, each with a one-word tooltip.
|
||||||
|
Widget _sortButton() => PopupMenuButton<NoteSort>(
|
||||||
|
// One word, not omitted: null falls back to the painted "Show menu".
|
||||||
|
tooltip: 'sort',
|
||||||
|
icon: const Icon(Icons.sort, semanticLabel: 'Sort'),
|
||||||
|
initialValue: _sort,
|
||||||
|
onSelected: _setSort,
|
||||||
|
itemBuilder: (_) => const [
|
||||||
|
PopupMenuItem(
|
||||||
|
value: NoteSort.modifiedDesc,
|
||||||
|
child: Tooltip(
|
||||||
|
message: 'updated',
|
||||||
|
child: Icon(Icons.update, semanticLabel: 'Last updated'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: NoteSort.createdDesc,
|
||||||
|
child: Tooltip(
|
||||||
|
message: 'newest',
|
||||||
|
child: Icon(Icons.post_add, semanticLabel: 'Newest created'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: NoteSort.alphabetical,
|
||||||
|
child: Tooltip(
|
||||||
|
message: 'alphabetical',
|
||||||
|
child: Icon(Icons.sort_by_alpha, semanticLabel: 'Alphabetical'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: NoteSort.priorityDesc,
|
||||||
|
child: Tooltip(
|
||||||
|
message: 'priority',
|
||||||
|
child: Icon(Icons.flag_outlined, semanticLabel: 'Priority'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ library;
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/note.dart';
|
import 'package:todo/data/note.dart';
|
||||||
import 'package:todo/ui/note_grid_tile.dart';
|
import 'package:todo/ui/note_grid_tile.dart';
|
||||||
@ -13,8 +13,7 @@ const kRefusalFlash = Duration(milliseconds: 1500);
|
|||||||
|
|
||||||
/// Set status, set priority, assign to repo, clear: icons only.
|
/// Set status, set priority, assign to repo, clear: icons only.
|
||||||
///
|
///
|
||||||
/// Menus pass `tooltip: ''` because a tooltip is visible text; the icons
|
/// One-word tooltips on hover/long-press per textgate rule.
|
||||||
/// carry semantic labels instead.
|
|
||||||
class NotesSelectionBar extends StatefulWidget {
|
class NotesSelectionBar extends StatefulWidget {
|
||||||
/// Creates the bar; every callback acts on the whole selection.
|
/// Creates the bar; every callback acts on the whole selection.
|
||||||
const NotesSelectionBar({
|
const NotesSelectionBar({
|
||||||
@ -70,7 +69,7 @@ class _NotesSelectionBarState extends State<NotesSelectionBar> {
|
|||||||
children: [
|
children: [
|
||||||
PopupMenuButton<Status>(
|
PopupMenuButton<Status>(
|
||||||
key: const ValueKey('bulk-status'),
|
key: const ValueKey('bulk-status'),
|
||||||
tooltip: '',
|
tooltip: 'status',
|
||||||
icon: const Icon(Icons.task_alt, semanticLabel: 'Set status'),
|
icon: const Icon(Icons.task_alt, semanticLabel: 'Set status'),
|
||||||
onSelected: widget.onStatus,
|
onSelected: widget.onStatus,
|
||||||
itemBuilder: (_) => [
|
itemBuilder: (_) => [
|
||||||
@ -84,7 +83,7 @@ class _NotesSelectionBarState extends State<NotesSelectionBar> {
|
|||||||
),
|
),
|
||||||
PopupMenuButton<Priority>(
|
PopupMenuButton<Priority>(
|
||||||
key: const ValueKey('bulk-priority'),
|
key: const ValueKey('bulk-priority'),
|
||||||
tooltip: '',
|
tooltip: 'priority',
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.flag_outlined,
|
Icons.flag_outlined,
|
||||||
semanticLabel: 'Set priority',
|
semanticLabel: 'Set priority',
|
||||||
@ -105,6 +104,7 @@ class _NotesSelectionBarState extends State<NotesSelectionBar> {
|
|||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
key: const ValueKey('bulk-assign'),
|
key: const ValueKey('bulk-assign'),
|
||||||
|
tooltip: 'assign',
|
||||||
onPressed: _assign,
|
onPressed: _assign,
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
refused ? Icons.block : Icons.drive_file_move_outline,
|
refused ? Icons.block : Icons.drive_file_move_outline,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/// Bottom sheet picking the repo selected notes are assigned to.
|
/// Bottom sheet picking the repo selected notes are assigned to.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
import 'package:todo/data/repo_assign.dart';
|
import 'package:todo/data/repo_assign.dart';
|
||||||
|
|
||||||
@ -83,6 +83,7 @@ class _RepoPickerSheetState extends State<RepoPickerSheet> {
|
|||||||
: null,
|
: null,
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
key: const ValueKey('repo-new-submit'),
|
key: const ValueKey('repo-new-submit'),
|
||||||
|
tooltip: 'use',
|
||||||
onPressed: _submit,
|
onPressed: _submit,
|
||||||
icon: const Icon(Icons.check, semanticLabel: 'Use repo'),
|
icon: const Icon(Icons.check, semanticLabel: 'Use repo'),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart'
|
||||||
|
show E2ePassphraseButton;
|
||||||
import 'package:file_selector/file_selector.dart';
|
import 'package:file_selector/file_selector.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:kuhy_credit/kuhy_credit.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:sync_settings_ui/sync_settings_ui.dart';
|
import 'package:sync_settings_ui/sync_settings_ui.dart';
|
||||||
import 'package:todo/analytics/analytics_event.dart';
|
import 'package:todo/analytics/analytics_event.dart';
|
||||||
import 'package:todo/analytics/analytics_service.dart';
|
import 'package:todo/analytics/analytics_service.dart';
|
||||||
@ -13,11 +16,14 @@ import 'package:todo/sync/backlog_export.dart';
|
|||||||
import 'package:todo/sync/firebase_backend.dart';
|
import 'package:todo/sync/firebase_backend.dart';
|
||||||
import 'package:todo/sync/google_sign_in_backend.dart';
|
import 'package:todo/sync/google_sign_in_backend.dart';
|
||||||
import 'package:todo/sync/notes_markdown.dart';
|
import 'package:todo/sync/notes_markdown.dart';
|
||||||
|
import 'package:todo/sync/run_sync.dart';
|
||||||
import 'package:todo/sync/sync_settings.dart';
|
import 'package:todo/sync/sync_settings.dart';
|
||||||
import 'package:todo/ui/app_route.dart';
|
import 'package:todo/ui/app_route.dart';
|
||||||
import 'package:todo/ui/cloud_images_settings.dart';
|
import 'package:todo/ui/cloud_images_settings.dart';
|
||||||
import 'package:todo/ui/github_mirror_screen.dart';
|
import 'package:todo/ui/github_mirror_screen.dart';
|
||||||
|
|
||||||
|
part 'settings_screen_actions.dart';
|
||||||
|
|
||||||
/// Settings screen: the "Enable advanced" toggle plus links to the two sync
|
/// Settings screen: the "Enable advanced" toggle plus links to the two sync
|
||||||
/// surfaces.
|
/// surfaces.
|
||||||
///
|
///
|
||||||
@ -105,11 +111,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
/// session is available, best-effort mirrors it so the choice follows the
|
/// session is available, best-effort mirrors it so the choice follows the
|
||||||
/// user to their other devices.
|
/// user to their other devices.
|
||||||
///
|
///
|
||||||
/// The local write always lands — a signed-in-as-wrong-account device
|
/// The local write always lands: a [FirebaseAuthError] from opening the
|
||||||
/// throwing [FirebaseAuthError] out of `openFirebase()` must not take the
|
/// client (wrong account) is caught on its own, before the write.
|
||||||
/// toggle down with it, so opening the client has its own try/catch,
|
|
||||||
/// separate from (and preceding) the try that guards the local write and
|
|
||||||
/// mirror push.
|
|
||||||
Future<void> _setAdvancedMode(bool value) async {
|
Future<void> _setAdvancedMode(bool value) async {
|
||||||
final analytics = widget.analytics;
|
final analytics = widget.analytics;
|
||||||
if (analytics != null) {
|
if (analytics != null) {
|
||||||
@ -140,73 +143,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Exports every note to a single Markdown file. On mobile this opens the
|
|
||||||
/// system share sheet; on desktop it writes the canonical `~/src/todo/
|
|
||||||
/// BACKLOG.md` so a future tool/agent has a stable path to read.
|
|
||||||
Future<void> _export() async {
|
|
||||||
final notes = await widget.repository.listNotes();
|
|
||||||
final markdown = NotesMarkdown.export(notes);
|
|
||||||
await exportBacklog(markdown, notes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Imports notes from a user-picked Markdown file, merging by id so a
|
|
||||||
/// stale backup never clobbers a newer local edit (see
|
|
||||||
/// [NoteRepository.importNotes]).
|
|
||||||
Future<void> _import() async {
|
|
||||||
const group = XTypeGroup(
|
|
||||||
label: 'Markdown',
|
|
||||||
extensions: ['md', 'markdown', 'txt'],
|
|
||||||
// UTIs/MIME so the picker accepts the file on iOS/Android too.
|
|
||||||
uniformTypeIdentifiers: ['net.daringfireball.markdown', 'public.text'],
|
|
||||||
mimeTypes: ['text/markdown', 'text/plain'],
|
|
||||||
);
|
|
||||||
final file = await openFile(acceptedTypeGroups: const [group]);
|
|
||||||
if (file == null) return; // user cancelled
|
|
||||||
final content = await file.readAsString();
|
|
||||||
final notes = NotesMarkdown.parse(content);
|
|
||||||
await widget.repository.importNotes(notes);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _openSyncSettings() async {
|
|
||||||
await Navigator.of(context).push<void>(
|
|
||||||
appRoute(
|
|
||||||
context,
|
|
||||||
(_) => SyncSettingsScreen(
|
|
||||||
accountLoader: widget.accountLoader ?? loadAccount,
|
|
||||||
accountSaver: widget.accountSaver ?? saveAccount,
|
|
||||||
accountClearer: widget.accountClearer ?? clearAccount,
|
|
||||||
sessionProbe: widget.sessionProbe ?? isFirebaseConfigured,
|
|
||||||
firebaseFactory: widget.firebaseFactory ?? openFirebase,
|
|
||||||
googleFirebaseFactory:
|
|
||||||
widget.googleFirebaseFactory ?? openFirebaseWithGoogle,
|
|
||||||
googleAvailable: widget.googleAvailable ?? googleSignInSupported,
|
|
||||||
backup: BackupSlot(label: 'notes', export: _export, import: _import),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _openGitHubMirror() async {
|
|
||||||
await Navigator.of(context).push<SyncSettings>(
|
|
||||||
appRoute(
|
|
||||||
context,
|
|
||||||
(_) => GitHubMirrorScreen(
|
|
||||||
initial: widget.initial,
|
|
||||||
repository: widget.repository,
|
|
||||||
appSettings: widget.appSettings,
|
|
||||||
analytics: widget.analytics,
|
|
||||||
httpClient: widget.httpClient,
|
|
||||||
firebaseFactory: widget.firebaseFactory,
|
|
||||||
stateStore: widget.stateStore,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text('Settings')),
|
appBar: AppBar(
|
||||||
|
title: const Icon(Icons.settings, semanticLabel: 'Settings'),
|
||||||
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
@ -214,33 +156,57 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
valueListenable: widget.appSettings,
|
valueListenable: widget.appSettings,
|
||||||
builder: (context, settings, _) => SwitchListTile(
|
builder: (context, settings, _) => SwitchListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
title: const Text('Enable advanced'),
|
secondary: const Icon(Icons.tune, semanticLabel: _advanced),
|
||||||
subtitle: const Text(
|
|
||||||
'Priority/status, templates, view modes, and sync details '
|
|
||||||
'in the capture screen',
|
|
||||||
),
|
|
||||||
value: settings.advancedMode,
|
value: settings.advancedMode,
|
||||||
onChanged: (value) => unawaited(_setAdvancedMode(value)),
|
onChanged: (value) => unawaited(_setAdvancedMode(value)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
ListTile(
|
_link(
|
||||||
contentPadding: EdgeInsets.zero,
|
const Icon(Icons.sync, semanticLabel: 'Sync settings: Firebase'),
|
||||||
title: const Text('Sync settings'),
|
_openSyncSettings,
|
||||||
subtitle: const Text('Firebase sync and notes backup'),
|
),
|
||||||
trailing: const Icon(Icons.chevron_right),
|
ValueListenableBuilder<bool>(
|
||||||
onTap: () => unawaited(_openSyncSettings()),
|
valueListenable: e2eLocked,
|
||||||
|
builder: (context, locked, _) => ListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
leading: E2ePassphraseButton(
|
||||||
|
locked: locked,
|
||||||
|
// A new passphrase is only proven by a sync that unlocks.
|
||||||
|
onSaved: () => unawaited(_syncNow()),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
CloudImagesTile(httpClient: widget.httpClient),
|
CloudImagesTile(httpClient: widget.httpClient),
|
||||||
ListTile(
|
_link(
|
||||||
contentPadding: EdgeInsets.zero,
|
Icon(
|
||||||
title: const Text('Advanced sync (GitHub)'),
|
Icons.cloud_sync,
|
||||||
subtitle: const Text('Cutover mirror — not recommended'),
|
color: Theme.of(context).colorScheme.outline,
|
||||||
trailing: const Icon(Icons.chevron_right),
|
semanticLabel: 'Advanced sync (GitHub): not recommended',
|
||||||
onTap: () => unawaited(_openGitHubMirror()),
|
),
|
||||||
|
_openGitHubMirror,
|
||||||
|
),
|
||||||
|
// kuhy's credit closes the list; its panel opens above the logo.
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: KuhyCredit(alignStart: true),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spoken only: what the advanced switch turns on.
|
||||||
|
static const _advanced = 'Enable advanced: priority, status, view modes';
|
||||||
|
|
||||||
|
/// A row that opens a sub-screen: its glyph (muted = not recommended).
|
||||||
|
Widget _link(Icon icon, Future<void> Function() open) => ListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
leading: icon,
|
||||||
|
trailing: const Icon(Icons.chevron_right),
|
||||||
|
onTap: () => unawaited(open()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
89
lib/ui/settings_screen_actions.dart
Normal file
89
lib/ui/settings_screen_actions.dart
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/// The settings screen's actions: Markdown export/import, sync now, and the
|
||||||
|
/// routes to the two sync screens.
|
||||||
|
///
|
||||||
|
/// A `part` of `settings_screen.dart` because they read the screen's
|
||||||
|
/// private state; split out for file size.
|
||||||
|
part of 'settings_screen.dart';
|
||||||
|
|
||||||
|
extension _SettingsActions on _SettingsScreenState {
|
||||||
|
/// Exports every note to a single Markdown file. On mobile this opens the
|
||||||
|
/// system share sheet; on desktop it writes the canonical `~/src/todo/
|
||||||
|
/// BACKLOG.md` so a future tool/agent has a stable path to read.
|
||||||
|
Future<void> _export() async {
|
||||||
|
final notes = await widget.repository.listNotes();
|
||||||
|
final markdown = NotesMarkdown.export(notes);
|
||||||
|
await exportBacklog(markdown, notes.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Imports notes from a user-picked Markdown file, merging by id so a
|
||||||
|
/// stale backup never clobbers a newer local edit (see
|
||||||
|
/// [NoteRepository.importNotes]).
|
||||||
|
Future<void> _import() async {
|
||||||
|
const group = XTypeGroup(
|
||||||
|
label: 'Markdown',
|
||||||
|
extensions: ['md', 'markdown', 'txt'],
|
||||||
|
// UTIs/MIME so the picker accepts the file on iOS/Android too.
|
||||||
|
uniformTypeIdentifiers: ['net.daringfireball.markdown', 'public.text'],
|
||||||
|
mimeTypes: ['text/markdown', 'text/plain'],
|
||||||
|
);
|
||||||
|
final file = await openFile(acceptedTypeGroups: const [group]);
|
||||||
|
if (file == null) return; // user cancelled
|
||||||
|
final content = await file.readAsString();
|
||||||
|
final notes = NotesMarkdown.parse(content);
|
||||||
|
await widget.repository.importNotes(notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retries the sync after a passphrase is entered; the lock tile follows
|
||||||
|
/// [e2eLocked], which the run updates.
|
||||||
|
Future<void> _syncNow() async {
|
||||||
|
try {
|
||||||
|
await runSync(
|
||||||
|
widget.repository,
|
||||||
|
widget.initial,
|
||||||
|
httpClient: widget.httpClient,
|
||||||
|
firebaseFactory: widget.firebaseFactory,
|
||||||
|
stateStore: widget.stateStore,
|
||||||
|
);
|
||||||
|
} on Exception {
|
||||||
|
// The capture screen's status line reports sync failures.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _openSyncSettings() async {
|
||||||
|
await Navigator.of(context).push<void>(
|
||||||
|
appRoute(
|
||||||
|
context,
|
||||||
|
(_) => SyncSettingsScreen(
|
||||||
|
accountLoader: widget.accountLoader ?? loadAccount,
|
||||||
|
accountSaver: widget.accountSaver ?? saveAccount,
|
||||||
|
accountClearer: widget.accountClearer ?? clearAccount,
|
||||||
|
sessionProbe: widget.sessionProbe ?? isFirebaseConfigured,
|
||||||
|
firebaseFactory: widget.firebaseFactory ?? openFirebase,
|
||||||
|
googleFirebaseFactory:
|
||||||
|
widget.googleFirebaseFactory ?? openFirebaseWithGoogle,
|
||||||
|
googleAvailable: widget.googleAvailable ?? googleSignInSupported,
|
||||||
|
backup: BackupSlot(label: 'notes', export: _export, import: _import),
|
||||||
|
),
|
||||||
|
name: '/settings/sync',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _openGitHubMirror() async {
|
||||||
|
await Navigator.of(context).push<SyncSettings>(
|
||||||
|
appRoute(
|
||||||
|
context,
|
||||||
|
(_) => GitHubMirrorScreen(
|
||||||
|
initial: widget.initial,
|
||||||
|
repository: widget.repository,
|
||||||
|
appSettings: widget.appSettings,
|
||||||
|
analytics: widget.analytics,
|
||||||
|
httpClient: widget.httpClient,
|
||||||
|
firebaseFactory: widget.firebaseFactory,
|
||||||
|
stateStore: widget.stateStore,
|
||||||
|
),
|
||||||
|
name: '/settings/github',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
lib/ui/status_cue.dart
Normal file
49
lib/ui/status_cue.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/// A screen's latest result as a glyph in place of a status sentence.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
/// One result: what to paint, whether it is a failure, and the old
|
||||||
|
/// sentence, kept as the spoken label only.
|
||||||
|
class StatusCue {
|
||||||
|
/// Creates a cue.
|
||||||
|
const StatusCue(this.icon, this.spoken, {this.error = false});
|
||||||
|
|
||||||
|
/// A success: a check glyph in the accent colour.
|
||||||
|
const StatusCue.ok(this.spoken) : icon = Icons.check_circle, error = false;
|
||||||
|
|
||||||
|
/// A failure: an error glyph in the danger hue.
|
||||||
|
const StatusCue.failed(this.spoken) : icon = Icons.error, error = true;
|
||||||
|
|
||||||
|
/// The glyph painted.
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
/// What a screen reader says.
|
||||||
|
final String spoken;
|
||||||
|
|
||||||
|
/// Whether this is a failure (danger hue) rather than a success.
|
||||||
|
final bool error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Paints [cue] as a large glyph; colour is the second channel.
|
||||||
|
class StatusCueView extends StatelessWidget {
|
||||||
|
/// Creates the view.
|
||||||
|
const StatusCueView(this.cue, {super.key});
|
||||||
|
|
||||||
|
/// The result shown.
|
||||||
|
final StatusCue cue;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Icon(
|
||||||
|
cue.icon,
|
||||||
|
size: 32,
|
||||||
|
color: cue.error ? scheme.error : scheme.primary,
|
||||||
|
semanticLabel: cue.spoken,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
lib/ui/template_glyphs.dart
Normal file
30
lib/ui/template_glyphs.dart
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/// Glyphs standing for note templates and their sections in the editor.
|
||||||
|
///
|
||||||
|
/// The section labels stay in `note_template.dart`: they are the note's own
|
||||||
|
/// `## heading` format, read by `parse()`, BACKLOG.md and the CLI. Only what
|
||||||
|
/// the editor paints around them is a glyph; the label and helper are spoken.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
import 'package:todo/data/note_template.dart';
|
||||||
|
|
||||||
|
/// The glyph for template [t]: a structured form, or a blank page.
|
||||||
|
IconData templateIcon(NoteTemplate t) =>
|
||||||
|
t.isFreeform ? Icons.note_outlined : Icons.assignment_outlined;
|
||||||
|
|
||||||
|
/// [t] as its glyph, spoken as its label.
|
||||||
|
Widget templateGlyph(NoteTemplate t) =>
|
||||||
|
Icon(templateIcon(t), semanticLabel: t.label);
|
||||||
|
|
||||||
|
/// The glyph heading a guided step, keyed by the section's stable `key`.
|
||||||
|
IconData sectionIcon(TemplateSection s) => switch (s.key) {
|
||||||
|
'title' => Icons.title,
|
||||||
|
'what' => Icons.lightbulb_outline,
|
||||||
|
'where' => Icons.place_outlined,
|
||||||
|
'must' => Icons.rule,
|
||||||
|
'done' => Icons.emoji_events_outlined,
|
||||||
|
'verify' => Icons.devices,
|
||||||
|
'refs' => Icons.menu_book_outlined,
|
||||||
|
_ => Icons.notes,
|
||||||
|
};
|
||||||
55
lib/ui/text_free_localizations.dart
Normal file
55
lib/ui/text_free_localizations.dart
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/// Framework strings the app paints without asking for them.
|
||||||
|
///
|
||||||
|
/// Material's own buttons (the app bar back arrow, a dialog's close, the
|
||||||
|
/// drawer, the overflow menu) carry tooltips from [MaterialLocalizations],
|
||||||
|
/// and a tooltip is painted on long-press and hover. kuhy's textgate rule
|
||||||
|
/// says nothing he sees has words he did not ask for, so these tooltips are
|
||||||
|
/// blanked: an empty tooltip is not built at all. Screen readers still get
|
||||||
|
/// the button's semantics from the icon itself.
|
||||||
|
library;
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
|
||||||
|
/// English Material strings with every button tooltip blanked.
|
||||||
|
class TextFreeMaterialLocalizations extends DefaultMaterialLocalizations {
|
||||||
|
/// Creates the localizations.
|
||||||
|
const TextFreeMaterialLocalizations();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get backButtonTooltip => '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get closeButtonTooltip => '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get openAppDrawerTooltip => '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get showMenuTooltip => '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get moreButtonTooltip => '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get deleteButtonTooltip => '';
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Delegate extends LocalizationsDelegate<MaterialLocalizations> {
|
||||||
|
const _Delegate();
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool isSupported(Locale locale) => locale.languageCode == 'en';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<MaterialLocalizations> load(Locale locale) =>
|
||||||
|
SynchronousFuture(const TextFreeMaterialLocalizations());
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldReload(_Delegate old) => false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pass as `MaterialApp.localizationsDelegates`.
|
||||||
|
const List<LocalizationsDelegate<dynamic>> kTextFreeLocalizations = [
|
||||||
|
_Delegate(),
|
||||||
|
];
|
||||||
@ -23,6 +23,10 @@ task (`id8 status priority repo title created_by`); `get_task` prints
|
|||||||
| Log, node id, session copy (0600) | `~/.local/share/todo-mcp/` |
|
| Log, node id, session copy (0600) | `~/.local/share/todo-mcp/` |
|
||||||
| Binary | `~/.local/lib/todo-mcp/todo_mcp` |
|
| Binary | `~/.local/lib/todo-mcp/todo_mcp` |
|
||||||
|
|
||||||
|
Reads (`list_tasks`, `search_tasks`, `get_task`) reuse a Firebase sync that finished within
|
||||||
|
the last 2 s (`TaskService.readFreshness`); every write pulls and pushes. One board fetch
|
||||||
|
makes about 15 calls, each used to be a 0.5-1 s sync.
|
||||||
|
|
||||||
## One-time setup
|
## One-time setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -33,4 +37,8 @@ systemctl --user enable --now todo-mcp.service
|
|||||||
```
|
```
|
||||||
|
|
||||||
Deploy a new build: `mcp/install.sh` (restarts a running unit).
|
Deploy a new build: `mcp/install.sh` (restarts a running unit).
|
||||||
Revoke a token: delete its line in `tokens`; no restart needed.
|
Revoke a token: delete its line in `tokens`; no restart needed. The file is
|
||||||
|
loaded once and re-read when its mtime or size changes; a read error (or a
|
||||||
|
deleted file) keeps the last good set, and before any good load the answer is
|
||||||
|
503, not 403. A POST open for 90 s gets 503 and its socket closed; sync HTTP
|
||||||
|
calls time out after 30 s; the unit sets `LimitNOFILE=65536`.
|
||||||
|
|||||||
@ -7,6 +7,8 @@ Wants=network-online.target
|
|||||||
ExecStart=%h/.local/lib/todo-mcp/todo_mcp
|
ExecStart=%h/.local/lib/todo-mcp/todo_mcp
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=30
|
RestartSec=30
|
||||||
|
# The default soft limit is 1024; leaked sockets once used every one of them.
|
||||||
|
LimitNOFILE=65536
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|||||||
215
pubspec.lock
215
pubspec.lock
@ -5,10 +5,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: android_file_picker
|
name: android_file_picker
|
||||||
sha256: "868183c959e754e915954d8074c20cfa4cfdb4684b35ecc08378437be1a542d8"
|
sha256: ec3cf2a2c7a9b2bd56747e85f80efdd994e563049dfb0981a23903acfdd58cb5
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3"
|
version: "2.2.0"
|
||||||
archive:
|
archive:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -77,10 +77,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: clock
|
name: clock
|
||||||
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
|
sha256: e51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.2"
|
version: "1.1.3"
|
||||||
code_assets:
|
code_assets:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -109,11 +109,20 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: crdt_sync_dart
|
path: crdt_sync_dart
|
||||||
ref: "crdt_sync_dart-v0.12.1"
|
ref: "crdt_sync_dart-v0.14.1"
|
||||||
resolved-ref: "6641d85f0550ca60433fc8e0d13a3dafdbb664d6"
|
resolved-ref: edd0f7a7882cb1d3904932ba94faa282d08165df
|
||||||
url: "https://github.com/kuhyx/utils"
|
url: "https://github.com/kuhyx/utils"
|
||||||
source: git
|
source: git
|
||||||
version: "0.12.1"
|
version: "0.14.1"
|
||||||
|
crdt_sync_flutter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: crdt_sync_flutter
|
||||||
|
ref: "crdt_sync_flutter-v0.9.1"
|
||||||
|
resolved-ref: "48dc28ad97b97c787aba4479c3ce51aade6e86b5"
|
||||||
|
url: "https://github.com/kuhyx/utils"
|
||||||
|
source: git
|
||||||
|
version: "0.9.1"
|
||||||
cross_file:
|
cross_file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -130,6 +139,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.8"
|
version: "3.0.8"
|
||||||
|
cryptography:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: cryptography
|
||||||
|
sha256: "3eda3029d34ec9095a27a198ac9785630fe525c0eb6a49f3d575272f8e792ef0"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.9.0"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -138,15 +155,23 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
cupertino_ui:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: cupertino_ui
|
||||||
|
sha256: c3eaf7f5bdfee36deb0b14a4cbf7602f1b6b8d8b8576b81f38fc08c25881c94c
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.7"
|
||||||
data_transfer_flutter:
|
data_transfer_flutter:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
path: data_transfer_flutter
|
path: data_transfer_flutter
|
||||||
ref: "data_transfer_flutter-v0.2.1"
|
ref: "data_transfer_flutter-v0.2.4"
|
||||||
resolved-ref: d4fca83c9f2ed33b3315cd838b9ca532ae8e559c
|
resolved-ref: "5c2effe7d1148830c9e273e47a272791dc17509e"
|
||||||
url: "https://github.com/kuhyx/utils"
|
url: "https://github.com/kuhyx/utils"
|
||||||
source: git
|
source: git
|
||||||
version: "0.2.1"
|
version: "0.2.4"
|
||||||
dbus:
|
dbus:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -159,11 +184,11 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: design_system
|
path: design_system
|
||||||
ref: "design_system-v0.3.1"
|
ref: "design_system-v0.5.1"
|
||||||
resolved-ref: "8dfc4fb55ff5f5091e34e118f3134138cc83b8a3"
|
resolved-ref: "7252ba0a7637f08dba09a79426817e423643c62f"
|
||||||
url: "https://github.com/kuhyx/utils"
|
url: "https://github.com/kuhyx/utils"
|
||||||
source: git
|
source: git
|
||||||
version: "0.3.1"
|
version: "0.5.1"
|
||||||
dev_build:
|
dev_build:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -208,10 +233,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: file_picker
|
name: file_picker
|
||||||
sha256: c64036857780d7125f011d543f89eedcb5df61da473668bace4eee9ab875284d
|
sha256: "5b99250437a4d34ee2cdc0686924452103540eaa1c248094b63f07f9d7216f6c"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "13.3.2"
|
version: "13.4.1"
|
||||||
file_picker_darwin:
|
file_picker_darwin:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -224,26 +249,26 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: file_picker_linux
|
name: file_picker_linux
|
||||||
sha256: c6562fc7d426db2fb85ea66fe2627953d2709932df5584ceaacf0aa5e39cf4da
|
sha256: cf3889644e8e54551f5c3a4f98b6b6ef5f0ef85c07d2a0c1a969538983be2f9b
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.2"
|
version: "2.0.5"
|
||||||
file_picker_platform_interface:
|
file_picker_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: file_picker_platform_interface
|
name: file_picker_platform_interface
|
||||||
sha256: "336e7168306834a2b68e6168ed768e00d3fabeac23154d5793e277ca9f97cf20"
|
sha256: a2ef71c4628f92a4471d424576e3bf7042b40a2683c9f9a0e3033a7fc7f7763c
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.0"
|
version: "4.3.0"
|
||||||
file_picker_web:
|
file_picker_web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: file_picker_web
|
name: file_picker_web
|
||||||
sha256: a2288008280aabe371aff029466b3405e60838e0a1d714767488c59b926c8b8c
|
sha256: "50749a6da2984fc29609e102ad4d80fd1d07e6895150f8e4922086167d9d45d8"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.0"
|
version: "4.2.1"
|
||||||
file_selector:
|
file_selector:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -329,6 +354,11 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.14.4"
|
version: "0.14.4"
|
||||||
|
flutter_localizations:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
flutter_plugin_android_lifecycle:
|
flutter_plugin_android_lifecycle:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -385,6 +415,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.2"
|
version: "4.2.2"
|
||||||
|
flutter_svg:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_svg
|
||||||
|
sha256: "4565a66f0a968f2e1ab4197854686990258aadab9572eb80a7655053a01dc302"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.5.0"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -399,11 +437,11 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: github_device_auth
|
path: github_device_auth
|
||||||
ref: "github_device_auth-v0.3.2"
|
ref: "github_device_auth-v0.5.1"
|
||||||
resolved-ref: "4ccaba1bb3e495ef72d70c6a7e7d7ec98d755792"
|
resolved-ref: da1d7c0692e2e402ae4944f2425b36a55ad43e9c
|
||||||
url: "https://github.com/kuhyx/utils"
|
url: "https://github.com/kuhyx/utils"
|
||||||
source: git
|
source: git
|
||||||
version: "0.3.2"
|
version: "0.5.1"
|
||||||
glob:
|
glob:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -449,18 +487,18 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: idb_shim
|
name: idb_shim
|
||||||
sha256: "60965b556624f7018ec26205283e32670bc78c6fe1388d4b90bdfe6b2311b87b"
|
sha256: "507d8f3154fa4e41165941c5aa8509c6bf155bb30f76ba25a00d1e7ba1dd64c9"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.11.2"
|
version: "2.11.3"
|
||||||
image:
|
image:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: image
|
name: image
|
||||||
sha256: "89ed75b2f8231fe676808c5564f9590d728024ded7ac782a7ed8474f1c95b72a"
|
sha256: bc13f61f0f5cb77936e78ae5dae3800f442718dac5d2bc4654f03c239230ed0c
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.12.0"
|
version: "4.13.1"
|
||||||
image_picker:
|
image_picker:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -525,6 +563,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.2"
|
version: "0.2.2"
|
||||||
|
intl:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: intl
|
||||||
|
sha256: "1ca20c894b1717686a2319b8548763d812bc0aabdac580420a44c5178c57a867"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.20.3"
|
||||||
jni:
|
jni:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -549,6 +595,15 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.12.0"
|
version: "4.12.0"
|
||||||
|
kuhy_credit:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: "kuhy_credit/flutter"
|
||||||
|
ref: "kuhy-credit-v0.3.2"
|
||||||
|
resolved-ref: adeb40f68e1d6c701da43e396fc46bffa3ef10c7
|
||||||
|
url: "https://github.com/kuhyx/utils"
|
||||||
|
source: git
|
||||||
|
version: "0.3.2"
|
||||||
leak_tracker:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -573,6 +628,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.2"
|
version: "3.0.2"
|
||||||
|
listen:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: listen
|
||||||
|
sha256: "47501a08016a43fcad79252439d723f50f14f88fa7bfd8a177e0a417e5c9e1f2"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.1"
|
||||||
logging:
|
logging:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -597,14 +660,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.13.0"
|
version: "0.13.0"
|
||||||
|
material_ui:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: material_ui
|
||||||
|
sha256: a6b19012df437a356cbc01f8ea22a105e07194c47c9a6009da0032a0ce35c4ab
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.11.1"
|
||||||
mcp_dart:
|
mcp_dart:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: mcp_dart
|
name: mcp_dart
|
||||||
sha256: af0b2e25412f70440c881314a0b70a56ef87fd090b3eb71f31c356313096e6f5
|
sha256: "0fdd953006edb8bce24d31f2d36d5c4acc89009e1331417955d3e77560cdb77b"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.3"
|
version: "2.4.4"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -709,6 +780,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.0"
|
version: "2.2.0"
|
||||||
|
package_info_plus:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: package_info_plus
|
||||||
|
sha256: "73ef2cd5c11a7548f9b7f6fc2a4f6113de2e64aa2a70de63feede95548822908"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "10.2.2"
|
||||||
|
package_info_plus_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: package_info_plus_platform_interface
|
||||||
|
sha256: db762cb2f4f25ee60fb6359773861b0f199e00b90d237bd85a76a1e806b46ef4
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.1.0"
|
||||||
path:
|
path:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -717,6 +804,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.1"
|
version: "1.9.1"
|
||||||
|
path_parsing:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_parsing
|
||||||
|
sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0"
|
||||||
path_provider:
|
path_provider:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -833,10 +928,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: sembast
|
name: sembast
|
||||||
sha256: "35775a26edbdf0d891bab304929a712e103c9d9a6e2fb5ebbd8437bb3139615a"
|
sha256: "4f71f8c95105918fa207065429c913f38d0fb05fec9f3a745bbf4c113f5d482b"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.10.0"
|
version: "3.10.1"
|
||||||
share_plus:
|
share_plus:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -934,10 +1029,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: sqflite_common_ffi
|
name: sqflite_common_ffi
|
||||||
sha256: "119d730460264a1f11f414d9eaa43fb686789357e81ce35f9e8ccb66ddd040e4"
|
sha256: "9aad7a63bb8de6fe4c1e5367e8dcd8dfc89d491f44a526edf8e58a5a1fb1feed"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.5"
|
version: "2.4.7"
|
||||||
sqflite_common_ffi_web:
|
sqflite_common_ffi_web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -982,10 +1077,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stack_trace
|
name: stack_trace
|
||||||
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
|
sha256: "277654b3034d17ac6f9f1cb5595db011b1d5d41e8806866db28e0abaa101c490"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.12.1"
|
version: "1.12.2"
|
||||||
stream_channel:
|
stream_channel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1006,11 +1101,11 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: sync_settings_ui
|
path: sync_settings_ui
|
||||||
ref: "sync_settings_ui-v0.6.2"
|
ref: "sync_settings_ui-v0.8.5"
|
||||||
resolved-ref: "95cd3731ede686114353d32ae6c286ad1694b488"
|
resolved-ref: abfb596d7ce2f28acfefbd55e7b3227257325261
|
||||||
url: "https://github.com/kuhyx/utils"
|
url: "https://github.com/kuhyx/utils"
|
||||||
source: git
|
source: git
|
||||||
version: "0.6.2"
|
version: "0.8.5"
|
||||||
synchronized:
|
synchronized:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1031,10 +1126,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: "2a122cbe059f8b610d3a5415f42e255b6c17b1f21eee1d960f31080237fb4f11"
|
sha256: "0a10344e901e5b2e63819567951cb6a06673ed6b84f40462188ff5a0c41f371f"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.12"
|
version: "0.7.14"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1115,14 +1210,38 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.6.0"
|
version: "4.6.0"
|
||||||
|
vector_graphics:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_graphics
|
||||||
|
sha256: "06081e4f2d8f17c306aa58989520694b463ad411bc7c7b93e76afa3e41ca17ac"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.1"
|
||||||
|
vector_graphics_codec:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_graphics_codec
|
||||||
|
sha256: "023f3afd1b08d040406e7ccc324f5173c04762a59e374f29d04cef00a4940742"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.0"
|
||||||
|
vector_graphics_compiler:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_graphics_compiler
|
||||||
|
sha256: "4c9d2e7121eea8b4f160e6e435900a0ae7214cfc97c2d6cf84c25532b789b50d"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.4"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vector_math
|
name: vector_math
|
||||||
sha256: f36f9f3be64c6198714492bb455c11056e33e2f85d9a0b676a48301e44fdcf47
|
sha256: fa49e1674cb84acb900141714e6c6e1f9ae099827c24d141430ff6819db4e1bc
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.2"
|
version: "2.4.4"
|
||||||
very_good_analysis:
|
very_good_analysis:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -1159,10 +1278,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: windows_file_picker
|
name: windows_file_picker
|
||||||
sha256: "18452aa293de3b6961c6d05b0e71b4be7bb90c67635abdd3aa5c4e75dd875072"
|
sha256: cd1be37ada0abcfaa55bddb7410e8515844e35cd77669c35d9a28a15722299d8
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.0.2"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1175,10 +1294,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: xml
|
name: xml
|
||||||
sha256: "0fe8cc98946def31cbcbc8734aa4067031e6f65ea3a78a508060bfed2200bfeb"
|
sha256: "67f0aff7be013d107995e9b75bf4e7f2c3ef2dfdb2c8e68024bba0a7fd5756a4"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.1.0"
|
version: "7.0.1"
|
||||||
yaml:
|
yaml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1189,4 +1308,4 @@ packages:
|
|||||||
version: "3.1.3"
|
version: "3.1.3"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.13.0 <4.0.0"
|
dart: ">=3.13.0 <4.0.0"
|
||||||
flutter: ">=3.44.0"
|
flutter: ">=3.47.0"
|
||||||
|
|||||||
36
pubspec.yaml
36
pubspec.yaml
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.0.70+1
|
version: 1.0.106+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.12.2
|
sdk: ^3.12.2
|
||||||
@ -33,8 +33,13 @@ dependencies:
|
|||||||
crdt_sync:
|
crdt_sync:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/kuhyx/utils
|
url: https://github.com/kuhyx/utils
|
||||||
ref: crdt_sync_dart-v0.12.1
|
ref: crdt_sync_dart-v0.14.1
|
||||||
path: crdt_sync_dart
|
path: crdt_sync_dart
|
||||||
|
crdt_sync_flutter:
|
||||||
|
git:
|
||||||
|
url: https://github.com/kuhyx/utils
|
||||||
|
ref: crdt_sync_flutter-v0.9.1
|
||||||
|
path: crdt_sync_flutter
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
@ -45,9 +50,9 @@ dependencies:
|
|||||||
design_system:
|
design_system:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/kuhyx/utils
|
url: https://github.com/kuhyx/utils
|
||||||
ref: design_system-v0.3.1
|
ref: design_system-v0.5.1
|
||||||
path: design_system
|
path: design_system
|
||||||
file_picker: 13.3.2
|
file_picker: 13.4.1
|
||||||
file_selector: 1.1.0
|
file_selector: 1.1.0
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
@ -59,7 +64,7 @@ dependencies:
|
|||||||
github_device_auth:
|
github_device_auth:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/kuhyx/utils
|
url: https://github.com/kuhyx/utils
|
||||||
ref: github_device_auth-v0.3.2
|
ref: github_device_auth-v0.5.1
|
||||||
path: github_device_auth
|
path: github_device_auth
|
||||||
# One-tap Google ID token via the framework AccountManager chooser (FOSS,
|
# One-tap Google ID token via the framework AccountManager chooser (FOSS,
|
||||||
# no Play Services sign-in SDK). Used by the sync backend in lib/sync/.
|
# no Play Services sign-in SDK). Used by the sync backend in lib/sync/.
|
||||||
@ -69,15 +74,25 @@ dependencies:
|
|||||||
ref: google_account_token-v0.1.0
|
ref: google_account_token-v0.1.0
|
||||||
path: google_account_token
|
path: google_account_token
|
||||||
http: 1.6.0
|
http: 1.6.0
|
||||||
idb_shim: 2.11.2
|
idb_shim: 2.11.3
|
||||||
# Re-encodes attached images (resize, EXIF strip) in pure Dart, so the
|
# Re-encodes attached images (resize, EXIF strip) in pure Dart, so the
|
||||||
# phone and the desktop wrapper share one code path.
|
# phone and the desktop wrapper share one code path.
|
||||||
image: 4.12.0
|
image: 4.13.1
|
||||||
# Camera + gallery picks for image attachments on Android.
|
# Camera + gallery picks for image attachments on Android.
|
||||||
image_picker: 1.2.4
|
image_picker: 1.2.4
|
||||||
|
# kuhy's logo credit, shown at the end of Settings.
|
||||||
|
kuhy_credit:
|
||||||
|
git:
|
||||||
|
url: https://github.com/kuhyx/utils
|
||||||
|
ref: kuhy-credit-v0.3.2
|
||||||
|
path: kuhy_credit/flutter
|
||||||
|
# Flutter 3.50 deprecates package:flutter/material.dart; the shared UI
|
||||||
|
# packages (design_system, sync_settings_ui) sit on material_ui, so the app
|
||||||
|
# must too or their widgets lose MaterialLocalizations.
|
||||||
|
material_ui: 1.11.1
|
||||||
# The todo MCP server (lib/mcp/): Streamable HTTP transport + tool
|
# The todo MCP server (lib/mcp/): Streamable HTTP transport + tool
|
||||||
# registry. Only mcp/todo_mcp.dart imports it; the app never does.
|
# registry. Only mcp/todo_mcp.dart imports it; the app never does.
|
||||||
mcp_dart: 2.4.3
|
mcp_dart: 2.4.4
|
||||||
# Hands an attached non-image file to whichever Android app opens its
|
# Hands an attached non-image file to whichever Android app opens its
|
||||||
# type (FileProvider intent). Adds no permissions to the manifest.
|
# type (FileProvider intent). Adds no permissions to the manifest.
|
||||||
open_file: 4.0.0
|
open_file: 4.0.0
|
||||||
@ -85,11 +100,10 @@ dependencies:
|
|||||||
path_provider: 2.1.6
|
path_provider: 2.1.6
|
||||||
share_plus: 13.3.1
|
share_plus: 13.3.1
|
||||||
shared_preferences: 2.5.6
|
shared_preferences: 2.5.6
|
||||||
sqflite_common_ffi: 2.4.5
|
sqflite_common_ffi: 2.4.7
|
||||||
# Retained only to read the legacy on-device DB during the one-time
|
# Retained only to read the legacy on-device DB during the one-time
|
||||||
# migration in NoteRepository.open; remove once all devices are migrated.
|
# migration in NoteRepository.open; remove once all devices are migrated.
|
||||||
sqlite_crdt: 3.0.4
|
sqlite_crdt: 3.0.4
|
||||||
|
|
||||||
# Shared "Sync settings" screen (Firebase + local backup), reused across
|
# Shared "Sync settings" screen (Firebase + local backup), reused across
|
||||||
# every kuhy app that syncs. GitHub mirror stays app-local (see
|
# every kuhy app that syncs. GitHub mirror stays app-local (see
|
||||||
# lib/ui/github_mirror_screen.dart) since here it also triggers a note
|
# lib/ui/github_mirror_screen.dart) since here it also triggers a note
|
||||||
@ -97,7 +111,7 @@ dependencies:
|
|||||||
sync_settings_ui:
|
sync_settings_ui:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/kuhyx/utils
|
url: https://github.com/kuhyx/utils
|
||||||
ref: sync_settings_ui-v0.6.2
|
ref: sync_settings_ui-v0.8.5
|
||||||
path: sync_settings_ui
|
path: sync_settings_ui
|
||||||
url_launcher: 6.3.3
|
url_launcher: 6.3.3
|
||||||
uuid: 4.6.0
|
uuid: 4.6.0
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# scripts/check_dependency_freshness.sh <file> [<file> ...] # pre-commit
|
# scripts/check_dependency_freshness.sh <file> [<file> ...] # pre-commit
|
||||||
# scripts/check_dependency_freshness.sh --all --strict # CI
|
# scripts/check_dependency_freshness.sh --all --strict # full local sweep
|
||||||
#
|
#
|
||||||
# Exit: 0 current | 1 behind | 2 allowlist wrong | 3 undeterminable (offline)
|
# Exit: 0 current | 1 behind | 2 allowlist wrong | 3 undeterminable (offline)
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
204
scripts/deploy.sh
Executable file
204
scripts/deploy.sh
Executable file
@ -0,0 +1,204 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Deploy todo everywhere it runs, then prove each one is live.
|
||||||
|
#
|
||||||
|
# scripts/deploy.sh # all targets: mcp desktop phone
|
||||||
|
# scripts/deploy.sh mcp desktop # only the named targets
|
||||||
|
#
|
||||||
|
# Targets (each has its own health check; any failure makes the exit non-zero,
|
||||||
|
# but the remaining targets still deploy so one unplugged phone does not leave
|
||||||
|
# the desktop on old code):
|
||||||
|
# mcp frozen binary + todo-mcp.service (mcp/install.sh), restart, then a
|
||||||
|
# real initialize + list_tasks against :8735 (mcp/verify_mcp.py).
|
||||||
|
# desktop web build + pacman package todo-flutter (install_arch.sh); health
|
||||||
|
# = installed package and bundled web version.json match pubspec.
|
||||||
|
# phone release APK via phone_deploy.sh (adb install -r only; it has no
|
||||||
|
# uninstall / pm clear path); health = versionName on the Pixel
|
||||||
|
# matches pubspec and the app process is running.
|
||||||
|
#
|
||||||
|
# Idempotent: desktop and phone skip the build when the installed version
|
||||||
|
# already equals pubspec's (every commit bumps the patch version, so an equal
|
||||||
|
# version means equal code); the MCP binary is cheap and always rebuilt.
|
||||||
|
#
|
||||||
|
# Nothing live runs from ~/src/todo (the MCP is a frozen binary, the desktop
|
||||||
|
# app lives in /opt/todo), but phone_deploy refuses a production install
|
||||||
|
# from a worktree (exit 49). So a run from anywhere else (the board runs it
|
||||||
|
# in its worktree) fast-forwards ~/src/todo, checks it now holds this
|
||||||
|
# commit, and re-executes from there. A pull blocked by kuhy's own edits
|
||||||
|
# fails with git's message, which the board recognises and reports.
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
readonly ROOT
|
||||||
|
readonly CHECKOUT="${TODO_CHECKOUT:-${HOME}/src/todo}"
|
||||||
|
readonly SERIAL="${ADB_SERIAL:-23181JEGR08034}"
|
||||||
|
readonly APP_ID="dev.kuhy.todo"
|
||||||
|
readonly MCP_UNIT="todo-mcp.service"
|
||||||
|
readonly MCP_URL="http://127.0.0.1:8735/mcp"
|
||||||
|
readonly MCP_TOKEN="${HOME}/.config/todo-mcp-client/token"
|
||||||
|
readonly PHONE_DEPLOY="${HOME}/.claude/scripts/phone_deploy.sh"
|
||||||
|
readonly CAPPED="${HOME}/.claude/scripts/capped.sh"
|
||||||
|
readonly WEB_VERSION_JSON="/opt/todo/web/version.json"
|
||||||
|
readonly KEY_PROPS="$ROOT/android/key.properties"
|
||||||
|
readonly SHARED_KEY_PROPS="${HOME}/.android/release/key.properties"
|
||||||
|
|
||||||
|
# systemd units and Ship do not source ~/.zshenv; phone_deploy needs the SDK
|
||||||
|
# for its apksigner check.
|
||||||
|
export ANDROID_HOME="${ANDROID_HOME:-${HOME}/sdk/foss-android-sdk}"
|
||||||
|
export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-$ANDROID_HOME}"
|
||||||
|
|
||||||
|
FAILED=()
|
||||||
|
|
||||||
|
say() { echo "[deploy:$1] $2"; }
|
||||||
|
fail() {
|
||||||
|
echo "[deploy:$1] FAIL: $2" >&2
|
||||||
|
FAILED+=("$1")
|
||||||
|
}
|
||||||
|
|
||||||
|
# pubspec `version: 1.0.77+1` -> `1.0.77` (the +build part is CI's).
|
||||||
|
pubspec_version() {
|
||||||
|
sed -n 's/^version:[[:space:]]*\([^+[:space:]]*\).*/\1/p' "$ROOT/pubspec.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Builds run under the shared resource cap when it exists on this machine.
|
||||||
|
heavy() {
|
||||||
|
if [[ -x "$CAPPED" ]]; then
|
||||||
|
CAP_MEM=4G CAP_CPU_PCT=20 "$CAPPED" "$@"
|
||||||
|
else
|
||||||
|
"$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mcp_pid() { systemctl --user show -p MainPID --value "$MCP_UNIT" 2>/dev/null || echo 0; }
|
||||||
|
|
||||||
|
deploy_mcp() {
|
||||||
|
local old_pid new_pid out
|
||||||
|
old_pid="$(mcp_pid)"
|
||||||
|
heavy "$ROOT/mcp/install.sh" || { fail mcp "mcp/install.sh failed"; return; }
|
||||||
|
# install.sh only restarts a running unit; make sure it is enabled + up.
|
||||||
|
systemctl --user enable --now "$MCP_UNIT" >/dev/null 2>&1 ||
|
||||||
|
{ fail mcp "cannot start $MCP_UNIT"; return; }
|
||||||
|
systemctl --user is-active --quiet "$MCP_UNIT" ||
|
||||||
|
{ fail mcp "$MCP_UNIT not active"; return; }
|
||||||
|
new_pid="$(mcp_pid)"
|
||||||
|
if [[ "$new_pid" == 0 || "$new_pid" == "$old_pid" ]]; then
|
||||||
|
fail mcp "$MCP_UNIT was not restarted (pid $old_pid -> $new_pid)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
[[ -s "$MCP_TOKEN" ]] || { fail mcp "no client token at $MCP_TOKEN"; return; }
|
||||||
|
out="$(python3 "$ROOT/mcp/verify_mcp.py" "$MCP_URL" \
|
||||||
|
--token-file "$MCP_TOKEN" --wait 20 2>&1)" ||
|
||||||
|
{ fail mcp "live check: $out"; return; }
|
||||||
|
say mcp "ok: pid $new_pid, ${out//$'\n'/, }"
|
||||||
|
}
|
||||||
|
|
||||||
|
desktop_versions_match() {
|
||||||
|
local want="$1" pkg web
|
||||||
|
pkg="$(pacman -Q todo-flutter 2>/dev/null | awk '{print $2}')"
|
||||||
|
web="$(sed -n 's/.*"version":"\([^"]*\)".*/\1/p' "$WEB_VERSION_JSON" 2>/dev/null)"
|
||||||
|
[[ "${pkg%-*}" == "$want" && "$web" == "$want" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
deploy_desktop() {
|
||||||
|
local want
|
||||||
|
want="$(pubspec_version)"
|
||||||
|
if desktop_versions_match "$want"; then
|
||||||
|
say desktop "ok: todo-flutter $want already installed"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
sudo -n true 2>/dev/null ||
|
||||||
|
{ fail desktop "sudo needs a password; run: ! $ROOT/install_arch.sh"; return; }
|
||||||
|
heavy "$ROOT/install_arch.sh" || { fail desktop "install_arch.sh failed"; return; }
|
||||||
|
if desktop_versions_match "$want"; then
|
||||||
|
say desktop "ok: todo-flutter $want installed"
|
||||||
|
else
|
||||||
|
fail desktop "installed version is not $want ($(pacman -Q todo-flutter 2>&1))"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
phone_version() {
|
||||||
|
adb -s "$SERIAL" shell dumpsys package "$APP_ID" 2>/dev/null |
|
||||||
|
sed -n 's/^[[:space:]]*versionName=\([^[:space:]]*\).*/\1/p' | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
phone_health() {
|
||||||
|
local want="$1" got
|
||||||
|
got="$(phone_version)"
|
||||||
|
[[ "$got" == "$want" ]] || { fail phone "versionName on phone is '$got', want $want"; return; }
|
||||||
|
adb -s "$SERIAL" shell pidof "$APP_ID" >/dev/null 2>&1 ||
|
||||||
|
adb -s "$SERIAL" shell monkey -p "$APP_ID" -c android.intent.category.LAUNCHER 1 >/dev/null 2>&1 || true
|
||||||
|
sleep 2
|
||||||
|
adb -s "$SERIAL" shell pidof "$APP_ID" >/dev/null 2>&1 ||
|
||||||
|
{ fail phone "$APP_ID is installed but not running"; return; }
|
||||||
|
say phone "ok: $APP_ID $want running on $SERIAL"
|
||||||
|
}
|
||||||
|
|
||||||
|
deploy_phone() {
|
||||||
|
local want rc=0
|
||||||
|
want="$(pubspec_version)"
|
||||||
|
if [[ "$(adb -s "$SERIAL" get-state 2>/dev/null)" != device ]]; then
|
||||||
|
fail phone "phone unreachable: $SERIAL not attached (plug it in, enable USB debugging)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [[ "$(phone_version)" == "$want" ]]; then
|
||||||
|
say phone "already at $want, skipping build"
|
||||||
|
else
|
||||||
|
# A fresh checkout has no (gitignored) key.properties; without it the
|
||||||
|
# build signs with the debug key and cannot install over a CI build.
|
||||||
|
[[ -f "$KEY_PROPS" || ! -f "$SHARED_KEY_PROPS" ]] ||
|
||||||
|
install -m 600 "$SHARED_KEY_PROPS" "$KEY_PROPS"
|
||||||
|
# Outside a Claude session each phone_lease call would name its own
|
||||||
|
# pid as owner, so phone_deploy's launch step blocked on the lease its
|
||||||
|
# own install step took (exit 35). One owner for the whole run.
|
||||||
|
# Exit 48 = load too high right now; wait it out (up to 15 min).
|
||||||
|
local tries=0
|
||||||
|
while :; do
|
||||||
|
rc=0
|
||||||
|
PHONE_LEASE_OWNER="${PHONE_LEASE_OWNER:-deploy:$$}" ADB_SERIAL="$SERIAL" \
|
||||||
|
heavy "$PHONE_DEPLOY" "$ROOT" --release || rc=$?
|
||||||
|
((rc == 48 && ++tries <= 30)) || break
|
||||||
|
say phone "machine busy, retrying in 30 s ($tries/30)"
|
||||||
|
sleep 30
|
||||||
|
done
|
||||||
|
((rc == 0)) || { fail phone "phone_deploy.sh exited $rc (see its exit-code table)"; return; }
|
||||||
|
fi
|
||||||
|
phone_health "$want"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Deploy from kuhy's main checkout, never from a worktree (see header).
|
||||||
|
run_from_checkout() {
|
||||||
|
local here want have
|
||||||
|
here="$(realpath -m -- "$ROOT")"
|
||||||
|
[[ $here == "$(realpath -m -- "$CHECKOUT")" ]] && return 0
|
||||||
|
want="$(git -C "$ROOT" rev-parse HEAD)"
|
||||||
|
echo "[deploy] running from $CHECKOUT, not $here"
|
||||||
|
git -C "$CHECKOUT" pull --ff-only
|
||||||
|
have="$(git -C "$CHECKOUT" rev-parse HEAD)"
|
||||||
|
if [[ $have != "$want" ]]; then
|
||||||
|
echo "[deploy] FAILED: $CHECKOUT is at $have after the pull, not $want" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exec "$CHECKOUT/scripts/deploy.sh" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local targets=("$@") t
|
||||||
|
((${#targets[@]})) || targets=(mcp desktop phone)
|
||||||
|
for t in "${targets[@]}"; do
|
||||||
|
case "$t" in
|
||||||
|
mcp | desktop | phone) "deploy_$t" ;;
|
||||||
|
*) echo "usage: $0 [mcp] [desktop] [phone]" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if ((${#FAILED[@]})); then
|
||||||
|
echo "[deploy] FAILED: ${FAILED[*]}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[deploy] all healthy: ${targets[*]} at $(pubspec_version)"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_from_checkout "$@"
|
||||||
|
main "$@"
|
||||||
@ -47,8 +47,9 @@ void main() {
|
|||||||
expect(pubspec, contains('google_account_token-v0.1.0'));
|
expect(pubspec, contains('google_account_token-v0.1.0'));
|
||||||
expect(pubspec, isNot(contains('google_sign_in')));
|
expect(pubspec, isNot(contains('google_sign_in')));
|
||||||
expect(
|
expect(
|
||||||
File('android/app/src/main/kotlin/dev/kuhy/todo/AccountTokenChannel.kt')
|
File(
|
||||||
.existsSync(),
|
'android/app/src/main/kotlin/dev/kuhy/todo/AccountTokenChannel.kt',
|
||||||
|
).existsSync(),
|
||||||
isFalse,
|
isFalse,
|
||||||
);
|
);
|
||||||
expect(File('lib/sync/account_token.dart').existsSync(), isFalse);
|
expect(File('lib/sync/account_token.dart').existsSync(), isFalse);
|
||||||
|
|||||||
@ -95,10 +95,7 @@ void main() {
|
|||||||
const service = AnalyticsService(nodeId: 'device-a');
|
const service = AnalyticsService(nodeId: 'device-a');
|
||||||
for (var i = 0; i < AnalyticsService.maxBufferedEvents + 5; i++) {
|
for (var i = 0; i < AnalyticsService.maxBufferedEvents + 5; i++) {
|
||||||
await service.logEvent(
|
await service.logEvent(
|
||||||
AnalyticsEvent(
|
AnalyticsEvent(name: 'event_$i', timestamp: DateTime.now()),
|
||||||
name: 'event_$i',
|
|
||||||
timestamp: DateTime.now(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -135,42 +135,39 @@ void main() {
|
|||||||
expect((remaining.single as Map)['name'], 'mid_flush_event');
|
expect((remaining.single as Map)['name'], 'mid_flush_event');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('restores the claimed batch ahead of events logged mid-flush on '
|
||||||
'restores the claimed batch ahead of events logged mid-flush on '
|
'failure', () async {
|
||||||
'failure',
|
// The HTTP handler runs mid-`putFileText`, strictly after flush()
|
||||||
() async {
|
// has already claimed (cleared) the buffer, so writing here is a
|
||||||
// The HTTP handler runs mid-`putFileText`, strictly after flush()
|
// genuine race rather than something that could instead land before
|
||||||
// has already claimed (cleared) the buffer, so writing here is a
|
// or after `flush()` depending on scheduling.
|
||||||
// genuine race rather than something that could instead land before
|
final client = _fakeClient((_) async {
|
||||||
// or after `flush()` depending on scheduling.
|
|
||||||
final client = _fakeClient((_) async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setString(
|
|
||||||
'analytics.buffer',
|
|
||||||
jsonEncode([
|
|
||||||
AnalyticsEvent(
|
|
||||||
name: 'mid_flush_event',
|
|
||||||
timestamp: DateTime(2026),
|
|
||||||
).toJson(),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
return http.Response('error', 500);
|
|
||||||
});
|
|
||||||
const service = AnalyticsService(nodeId: 'device-a');
|
|
||||||
await service.logEvent(
|
|
||||||
AnalyticsEvent(name: 'app_open', timestamp: DateTime(2026)),
|
|
||||||
);
|
|
||||||
|
|
||||||
await service.flush(client);
|
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final remaining =
|
await prefs.setString(
|
||||||
jsonDecode(prefs.getString('analytics.buffer')!) as List;
|
'analytics.buffer',
|
||||||
expect(remaining, hasLength(2));
|
jsonEncode([
|
||||||
expect((remaining[0] as Map)['name'], 'app_open');
|
AnalyticsEvent(
|
||||||
expect((remaining[1] as Map)['name'], 'mid_flush_event');
|
name: 'mid_flush_event',
|
||||||
},
|
timestamp: DateTime(2026),
|
||||||
);
|
).toJson(),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
return http.Response('error', 500);
|
||||||
|
});
|
||||||
|
const service = AnalyticsService(nodeId: 'device-a');
|
||||||
|
await service.logEvent(
|
||||||
|
AnalyticsEvent(name: 'app_open', timestamp: DateTime(2026)),
|
||||||
|
);
|
||||||
|
|
||||||
|
await service.flush(client);
|
||||||
|
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final remaining =
|
||||||
|
jsonDecode(prefs.getString('analytics.buffer')!) as List;
|
||||||
|
expect(remaining, hasLength(2));
|
||||||
|
expect((remaining[0] as Map)['name'], 'app_open');
|
||||||
|
expect((remaining[1] as Map)['name'], 'mid_flush_event');
|
||||||
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'a RemoteSyncError from an expired session restores the buffer',
|
'a RemoteSyncError from an expired session restores the buffer',
|
||||||
|
|||||||
85
test/app_errors_probe_test.dart
Normal file
85
test/app_errors_probe_test.dart
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// Proves the shared app-errors reporter end to end inside the test runner:
|
||||||
|
// one uncaught error and one wait over a second each become exactly one
|
||||||
|
// uploaded entry, and both carry the build. The sink writes to a file in
|
||||||
|
// place of RTDB so the probe needs no network.
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late FlutterExceptionHandler? savedFlutter;
|
||||||
|
late ErrorCallback? savedAsync;
|
||||||
|
late Directory dir;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
savedFlutter = FlutterError.onError;
|
||||||
|
savedAsync = PlatformDispatcher.instance.onError;
|
||||||
|
dir = Directory.systemTemp.createTempSync('app_errors_probe');
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
FlutterError.onError = savedFlutter;
|
||||||
|
PlatformDispatcher.instance.onError = savedAsync;
|
||||||
|
AppErrors.instance = null;
|
||||||
|
dir.deleteSync(recursive: true);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('one error and one 2 s wait upload with the build', (t) async {
|
||||||
|
// The deliberate error must not fail the test, so the handler the
|
||||||
|
// reporter chains to is a no-op.
|
||||||
|
FlutterError.onError = (_) {};
|
||||||
|
final errors = await installAppErrors(
|
||||||
|
const AppErrorsConfig(
|
||||||
|
app: 'todo',
|
||||||
|
repo: 'kuhyx/todo-app',
|
||||||
|
package: 'todo',
|
||||||
|
build: 4242,
|
||||||
|
version: '1.2.3',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final out = File('${dir.path}/sink.jsonl');
|
||||||
|
final uploader = errors.connect(
|
||||||
|
sink: () async =>
|
||||||
|
(path, values) async => out.writeAsStringSync(
|
||||||
|
'${jsonEncode({'path': path, 'values': values})}\n',
|
||||||
|
mode: FileMode.append,
|
||||||
|
),
|
||||||
|
deviceId: () async => 'probe-device',
|
||||||
|
startDelay: Duration.zero,
|
||||||
|
);
|
||||||
|
|
||||||
|
FlutterError.onError!(
|
||||||
|
FlutterErrorDetails(exception: StateError('probe boom')),
|
||||||
|
);
|
||||||
|
|
||||||
|
await t.pumpWidget(
|
||||||
|
const WaitWatch(operation: 'probe.wait', child: SizedBox()),
|
||||||
|
);
|
||||||
|
await t.runAsync(() => Future<void>.delayed(const Duration(seconds: 2)));
|
||||||
|
await t.pumpWidget(const SizedBox());
|
||||||
|
|
||||||
|
await t.runAsync(uploader.flush);
|
||||||
|
uploader.dispose();
|
||||||
|
|
||||||
|
final entries = [
|
||||||
|
for (final line in out.readAsLinesSync())
|
||||||
|
for (final v
|
||||||
|
in ((jsonDecode(line) as Map)['values'] as Map).values.cast<Map>())
|
||||||
|
v,
|
||||||
|
];
|
||||||
|
final kinds = entries.map((e) => e['kind']).toList()..sort();
|
||||||
|
expect(kinds, ['perf.slow', 'uncaught.flutter']);
|
||||||
|
expect(entries.map((e) => e['build']).toSet(), {4242});
|
||||||
|
expect(entries.map((e) => e['repo']).toSet(), {'kuhyx/todo-app'});
|
||||||
|
final slow = entries.firstWhere((e) => e['kind'] == 'perf.slow');
|
||||||
|
expect(slow['operation'], 'probe.wait');
|
||||||
|
expect(slow['durationMs'] as int, greaterThanOrEqualTo(2000));
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -91,9 +91,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('swallows a push failure and keeps the local write', () async {
|
test('swallows a push failure and keeps the local write', () async {
|
||||||
final client = _fakeClient(
|
final client = _fakeClient((_) async => http.Response('error', 500));
|
||||||
(_) async => http.Response('error', 500),
|
|
||||||
);
|
|
||||||
const initial = AppSettings(advancedMode: false);
|
const initial = AppSettings(advancedMode: false);
|
||||||
|
|
||||||
final updated = await initial.withAdvancedMode(
|
final updated = await initial.withAdvancedMode(
|
||||||
@ -107,22 +105,19 @@ void main() {
|
|||||||
expect(reloaded.advancedMode, isTrue);
|
expect(reloaded.advancedMode, isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('swallows a FirebaseAuthError (expired session) and keeps the local '
|
||||||
'swallows a FirebaseAuthError (expired session) and keeps the local '
|
'write', () async {
|
||||||
'write',
|
const initial = AppSettings(advancedMode: false);
|
||||||
() async {
|
|
||||||
const initial = AppSettings(advancedMode: false);
|
|
||||||
|
|
||||||
final updated = await initial.withAdvancedMode(
|
final updated = await initial.withAdvancedMode(
|
||||||
value: true,
|
value: true,
|
||||||
client: _authFailingClient(),
|
client: _authFailingClient(),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(updated.advancedMode, isTrue);
|
expect(updated.advancedMode, isTrue);
|
||||||
final reloaded = await AppSettings.load();
|
final reloaded = await AppSettings.load();
|
||||||
expect(reloaded.advancedMode, isTrue);
|
expect(reloaded.advancedMode, isTrue);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
group('reconcileWithRemote', () {
|
group('reconcileWithRemote', () {
|
||||||
@ -220,9 +215,7 @@ void main() {
|
|||||||
() async {
|
() async {
|
||||||
const initial = AppSettings(advancedMode: false);
|
const initial = AppSettings(advancedMode: false);
|
||||||
|
|
||||||
final result = await initial.reconcileWithRemote(
|
final result = await initial.reconcileWithRemote(_authFailingClient());
|
||||||
_authFailingClient(),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(identical(result, initial), isTrue);
|
expect(identical(result, initial), isTrue);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:crdt_sync/crdt_sync.dart';
|
import 'package:crdt_sync/crdt_sync.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:http/testing.dart';
|
import 'package:http/testing.dart';
|
||||||
@ -20,60 +20,59 @@ import 'fake_note_repository.dart';
|
|||||||
import 'fake_secure_storage.dart';
|
import 'fake_secure_storage.dart';
|
||||||
|
|
||||||
import 'capture_screen_harness.dart';
|
import 'capture_screen_harness.dart';
|
||||||
|
import 'e2e_github_header.dart';
|
||||||
|
import 'text_free_guard.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets(
|
testWidgets('auto-sync adopts a newer advancedMode value from Firebase', (
|
||||||
'auto-sync adopts a newer advancedMode value from Firebase',
|
tester,
|
||||||
(tester) async {
|
) async {
|
||||||
final remoteTime = DateTime(2026, 6);
|
final remoteTime = DateTime(2026, 6);
|
||||||
final firebase = FirebaseRestClient(
|
final firebase = FirebaseRestClient(
|
||||||
databaseUrl: 'https://x-rtdb.europe-west1.firebasedatabase.app',
|
databaseUrl: 'https://x-rtdb.europe-west1.firebasedatabase.app',
|
||||||
auth: FirebaseTokenProvider(
|
auth: FirebaseTokenProvider(
|
||||||
apiKey: 'AIzaKey',
|
apiKey: 'AIzaKey',
|
||||||
store: InMemoryCredentialStore(
|
store: InMemoryCredentialStore(
|
||||||
FirebaseCredentials(
|
FirebaseCredentials(
|
||||||
idToken: 'id',
|
idToken: 'id',
|
||||||
refreshToken: 'refresh',
|
refreshToken: 'refresh',
|
||||||
expiresAt: DateTime.now().add(const Duration(hours: 1)),
|
expiresAt: DateTime.now().add(const Duration(hours: 1)),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
httpClient: MockClient((request) async {
|
),
|
||||||
if (request.url.path == '/settings/advancedMode.json') {
|
httpClient: e2eMock((request) async {
|
||||||
return http.Response(
|
if (request.url.path == '/settings/advancedMode.json') {
|
||||||
'{"value": "true", '
|
return http.Response(
|
||||||
'"updatedAtMillis": "${remoteTime.millisecondsSinceEpoch}"}',
|
'{"value": "true", '
|
||||||
200,
|
'"updatedAtMillis": "${remoteTime.millisecondsSinceEpoch}"}',
|
||||||
);
|
200,
|
||||||
}
|
);
|
||||||
if (request.method == 'PUT') return http.Response(request.body, 200);
|
}
|
||||||
return http.Response('null', 200);
|
if (request.method == 'PUT') return http.Response(request.body, 200);
|
||||||
}),
|
return http.Response('null', 200);
|
||||||
);
|
}),
|
||||||
final appSettings = ValueNotifier(
|
);
|
||||||
AppSettings(
|
final appSettings = ValueNotifier(
|
||||||
advancedMode: false,
|
AppSettings(
|
||||||
// Older than remoteTime, and non-null, so the reconciliation
|
advancedMode: false,
|
||||||
// guard's `currentAt != null && !reconciledAt.isAfter(currentAt)`
|
// Older than remoteTime, and non-null, so the reconciliation
|
||||||
// check actually evaluates both operands.
|
// guard's `currentAt != null && !reconciledAt.isAfter(currentAt)`
|
||||||
advancedModeUpdatedAt: remoteTime.subtract(
|
// check actually evaluates both operands.
|
||||||
const Duration(days: 1),
|
advancedModeUpdatedAt: remoteTime.subtract(const Duration(days: 1)),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
await pumpCapture(
|
await pumpCapture(
|
||||||
tester,
|
tester,
|
||||||
prefs: configuredPrefs,
|
prefs: configuredPrefs,
|
||||||
firebaseFactory: () async => firebase,
|
firebaseFactory: () async => firebase,
|
||||||
appSettings: appSettings,
|
appSettings: appSettings,
|
||||||
);
|
);
|
||||||
await tester.pump(); // settings load → auto-sync (pull) …
|
await tester.pump(); // settings load → auto-sync (pull) …
|
||||||
await tester.pump(); // … then push, then reconcile
|
await tester.pump(); // … then push, then reconcile
|
||||||
|
|
||||||
expect(appSettings.value.advancedMode, isTrue);
|
expect(appSettings.value.advancedMode, isTrue);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
testWidgets('logs app_open when analytics is injected', (tester) async {
|
testWidgets('logs app_open when analytics is injected', (tester) async {
|
||||||
const analytics = AnalyticsService(nodeId: 'device-a');
|
const analytics = AnalyticsService(nodeId: 'device-a');
|
||||||
@ -140,7 +139,7 @@ void main() {
|
|||||||
// Capture must never be interrupted by a snackbar…
|
// Capture must never be interrupted by a snackbar…
|
||||||
expect(find.byType(SnackBar), findsNothing);
|
expect(find.byType(SnackBar), findsNothing);
|
||||||
// …but the failure is no longer swallowed: the status line shows it.
|
// …but the failure is no longer swallowed: the status line shows it.
|
||||||
expect(find.textContaining('Sync failed at'), findsOneWidget);
|
expect(spoken('Sync failed at'), findsOneWidget);
|
||||||
expect(find.textContaining('offline'), findsOneWidget);
|
expect(spoken('offline'), findsOneWidget);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// A note typed into the app is stamped created_by kuhy.
|
// A note typed into the app is stamped created_by kuhy.
|
||||||
import 'package:flutter/material.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'capture_screen_harness.dart';
|
import 'capture_screen_harness.dart';
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user