Fix bugs across app + server, optimize UI/UX, add Gitea CI
Bug fixes (Flutter): - Wrap multi-statement DB writes (insert/update/delete note, deleteDocument, deletePageData, OCR FTS merge, migrations) in transactions to prevent data loss on interruption and a read-modify-write FTS race. - Fix PdfDocument leaks on exception (try/finally dispose) and preserve image aspect ratio when stamping images onto PDF pages. - Guard file-picker against empty selection (was .single -> crash). - Fix eraser ConcurrentModificationError and unmodifiable-list crash on PDF pages; capture page synchronously on save to stop wrong-page data loss. - Fix Riverpod DB-not-ready races, broken pull-to-refresh, settings load race, and search N+1; transform stored annotations on PDF page rotation. - Normalize pen pressure for devices without a pressure range. - PPT: single source of truth for slide strokes so ink displays and exports. UI/UX: - Material 3 typography, theme-aware colors (dark-mode fixes), hover cursors and right-click/visible actions on desktop, keyboard shortcuts (undo/redo/ save/find), toolbar overflow handling, friendlier empty states, semantic OCR status badges, relative timestamps, 1-based page indicators, large-deck PPT navigation, and a scratchpad-scope label in split view. Server (optional backend): - Persist JWT secret (was per-process random), block path traversal in storage, fix CORS '*'+credentials, add OCR job ownership checks, last-writer-wins sync guard, constant-time login, and split out heavy OCR deps so the API/tests run without them. CI: Gitea workflows for format+analyze+test (Linux, system sqlite) and a Windows release build; pristine `flutter analyze`, all Flutter and server tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
146
lib/providers/settings_provider.dart
Normal file
146
lib/providers/settings_provider.dart
Normal file
@@ -0,0 +1,146 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../models/pen_tool.dart';
|
||||
import '../models/pressure_curve.dart';
|
||||
import '../utils/stroke_stabilizer.dart';
|
||||
|
||||
final settingsProvider = ChangeNotifierProvider<SettingsNotifier>(
|
||||
(ref) => SettingsNotifier(),
|
||||
);
|
||||
|
||||
/// Persists user settings across sessions using SharedPreferences.
|
||||
class SettingsNotifier extends ChangeNotifier {
|
||||
late SharedPreferences _prefs;
|
||||
|
||||
/// Completes once [_load] has assigned [_prefs]. Setters await this before
|
||||
/// touching [_prefs] to avoid a LateInitializationError when invoked before
|
||||
/// the fire-and-forget load from the constructor finishes.
|
||||
late final Future<void> _ready;
|
||||
|
||||
PenTool _defaultTool = PenTool.pen;
|
||||
Color _defaultColor = Colors.black;
|
||||
double _defaultStrokeWidth = 2.0;
|
||||
PressureCurveType _defaultPressureCurve = PressureCurveType.linear;
|
||||
StabilizationLevel _defaultStabilization = StabilizationLevel.none;
|
||||
ThemeMode _themeMode = ThemeMode.system;
|
||||
Color _colorSchemeSeed = Colors.blue;
|
||||
|
||||
SettingsNotifier() {
|
||||
_ready = _load();
|
||||
}
|
||||
|
||||
PenTool get defaultTool => _defaultTool;
|
||||
Color get defaultColor => _defaultColor;
|
||||
double get defaultStrokeWidth => _defaultStrokeWidth;
|
||||
PressureCurveType get defaultPressureCurve => _defaultPressureCurve;
|
||||
StabilizationLevel get defaultStabilization => _defaultStabilization;
|
||||
ThemeMode get themeMode => _themeMode;
|
||||
Color get colorSchemeSeed => _colorSchemeSeed;
|
||||
|
||||
Future<void> setDefaultTool(PenTool tool) async {
|
||||
_defaultTool = tool;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setString('defaultTool', tool.name);
|
||||
}
|
||||
|
||||
Future<void> setDefaultColor(Color color) async {
|
||||
_defaultColor = color;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setInt('defaultColor', color.toARGB32());
|
||||
}
|
||||
|
||||
Future<void> setDefaultStrokeWidth(double width) async {
|
||||
_defaultStrokeWidth = width;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setDouble('defaultStrokeWidth', width);
|
||||
}
|
||||
|
||||
Future<void> setDefaultPressureCurve(PressureCurveType curve) async {
|
||||
_defaultPressureCurve = curve;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setString('defaultPressureCurve', curve.name);
|
||||
}
|
||||
|
||||
Future<void> setDefaultStabilization(StabilizationLevel level) async {
|
||||
_defaultStabilization = level;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setString('defaultStabilization', level.name);
|
||||
}
|
||||
|
||||
Future<void> setThemeMode(ThemeMode mode) async {
|
||||
_themeMode = mode;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setString('themeMode', mode.name);
|
||||
}
|
||||
|
||||
Future<void> setColorSchemeSeed(Color color) async {
|
||||
_colorSchemeSeed = color;
|
||||
notifyListeners();
|
||||
await _ready;
|
||||
await _prefs.setInt('colorSchemeSeed', color.toARGB32());
|
||||
}
|
||||
|
||||
Future<void> clearAllData() async {
|
||||
await _ready;
|
||||
await _prefs.clear();
|
||||
_defaultTool = PenTool.pen;
|
||||
_defaultColor = Colors.black;
|
||||
_defaultStrokeWidth = 2.0;
|
||||
_defaultPressureCurve = PressureCurveType.linear;
|
||||
_defaultStabilization = StabilizationLevel.none;
|
||||
_themeMode = ThemeMode.system;
|
||||
_colorSchemeSeed = Colors.blue;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
|
||||
final toolName = _prefs.getString('defaultTool');
|
||||
if (toolName != null) {
|
||||
_defaultTool = PenTool.values.asNameMap()[toolName] ?? PenTool.pen;
|
||||
}
|
||||
|
||||
final colorValue = _prefs.getInt('defaultColor');
|
||||
if (colorValue != null) {
|
||||
_defaultColor = Color(colorValue);
|
||||
}
|
||||
|
||||
_defaultStrokeWidth =
|
||||
_prefs.getDouble('defaultStrokeWidth') ?? _defaultStrokeWidth;
|
||||
|
||||
final curveName = _prefs.getString('defaultPressureCurve');
|
||||
if (curveName != null) {
|
||||
_defaultPressureCurve =
|
||||
PressureCurveType.values.asNameMap()[curveName] ??
|
||||
PressureCurveType.linear;
|
||||
}
|
||||
|
||||
final stabName = _prefs.getString('defaultStabilization');
|
||||
if (stabName != null) {
|
||||
_defaultStabilization =
|
||||
StabilizationLevel.values.asNameMap()[stabName] ??
|
||||
StabilizationLevel.none;
|
||||
}
|
||||
|
||||
final themeName = _prefs.getString('themeMode');
|
||||
if (themeName != null) {
|
||||
_themeMode = ThemeMode.values.asNameMap()[themeName] ?? ThemeMode.system;
|
||||
}
|
||||
|
||||
final seedValue = _prefs.getInt('colorSchemeSeed');
|
||||
if (seedValue != null) {
|
||||
_colorSchemeSeed = Color(seedValue);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user