Files
clide/app/lib/kernel/src/notify.dart
T
jpmschweitzerandClaude b13483e2d5 scaffold Flutter app — kernel, extensions, widgets, Tier 0 built-ins
First real content under app/. Lays the whole Tier 0 foundation in one
commit because the pieces depend on each other circularly (kernel →
extension → widgets → built-ins all reference types from the layer
below); splitting would leave intermediate commits that don't compile.

Key shapes:

  * bare WidgetsApp root — no Material, no Cupertino, no Scaffold.
    ClideTheme InheritedWidget is the only source of tokens.
  * ClideKernel InheritedWidget aggregates 18 services (settings,
    project, extensions, theme, panels, events, ipc, commands +
    palette + keybindings, clipboard, files, notify, dialog, tray,
    secrets, os, net, focus, log, i18n). ExtensionContext exposes
    them through a stable interface.
  * ClideExtension + sealed ContributionPoint hierarchy (Tab,
    StatusItem, Toolbar, Command, TrayItem, LayoutPreset). One
    manifest ships N contributions into kernel slots.
  * Three-tier theme pipeline: palette (named colors) → semantic
    roles → ~60 surface tokens. Defaults at each layer so legacy
    palette-only themes produce a complete SurfaceTokens.
  * A11y baked in from day one — every interactive primitive wraps
    in Semantics(label:, hint:, button:); ensureSemantics() at boot;
    theme/contrast.dart helper exposes token pairs for the WCAG
    gate in the a11y test suite.
  * i18n ported from fframe's L10n pattern (text-driven, namespaced
    JSON catalogs, caller-supplied placeholders) with a proper
    locale fallback chain (exact → language → default → placeholder)
    fframe lacks.
  * Four Tier-0 built-ins live (default-layout, welcome, ipc-status,
    theme-picker) plus 17 id-reserving stubs so later tiers fill in
    without rename churn.

.gitignore extended to cover app/ sub-package artefacts and the
Playwright harness scratch dirs.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-21 15:39:41 +02:00

78 lines
2.1 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
enum NotificationLevel { info, warning, error, success }
@immutable
class ClideNotification {
ClideNotification({
required this.id,
required this.level,
required this.message,
this.title,
this.duration = const Duration(seconds: 4),
}) : createdAt = DateTime.now().toUtc();
final String id;
final NotificationLevel level;
final String? title;
final String message;
final DateTime createdAt;
final Duration duration;
}
class Notifications extends ChangeNotifier {
final List<ClideNotification> _active = [];
final Map<String, Timer> _timers = {};
int _seq = 0;
List<ClideNotification> get active => List.unmodifiable(_active);
void info(String message, {String? title, Duration? duration}) =>
_push(NotificationLevel.info, message, title: title, duration: duration);
void warn(String message, {String? title, Duration? duration}) =>
_push(NotificationLevel.warning, message,
title: title, duration: duration);
void error(String message, {String? title, Duration? duration}) =>
_push(NotificationLevel.error, message, title: title, duration: duration);
void success(String message, {String? title, Duration? duration}) =>
_push(NotificationLevel.success, message,
title: title, duration: duration);
void dismiss(String id) {
_timers.remove(id)?.cancel();
final before = _active.length;
_active.removeWhere((n) => n.id == id);
if (_active.length != before) notifyListeners();
}
void _push(
NotificationLevel level,
String message, {
String? title,
Duration? duration,
}) {
final id = 'n${_seq++}';
final n = ClideNotification(
id: id,
level: level,
message: message,
title: title,
duration: duration ?? const Duration(seconds: 4),
);
_active.add(n);
_timers[id] = Timer(n.duration, () => dismiss(id));
notifyListeners();
}
@override
void dispose() {
for (final t in _timers.values) {
t.cancel();
}
_timers.clear();
super.dispose();
}
}