feat: a settings page, a server footer in the sidebar, and follow-up behaviour
- The sidebar's server switch moves to a footer bar: the connected server's name on the left (tap for the server sheet) and a settings key on the right, matching the first-party phone layout. - Settings has three groups: 外观 (theme mode and seed colour, stored on the device only in shared_preferences), 聊天 (the server's followUpBehavior: steer or queue) and a 宠物 placeholder. The app theme now reads the seed and mode. - The chat's short send while a turn runs uses the configured follow-up behaviour; the long-press sheet offers both and marks the default. The value is read from GET /api/config/settings?surface=mobile on connect, on resume and when the page opens, and written back with PUT. - Tests: settings page groups and choice, sidebar footer naming the server and opening settings, follow-up normalization. - 0.3.17 (317).
This commit is contained in:
1 parent
1aa84a53e5
commit
e646130d1f
13 files changed
+544
-15
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// Appearance preferences: theme mode and seed colour. Device-local — the
|
||||
// phone draws its own Material theme, so none of this is sent to the server.
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class AppearancePrefs extends ChangeNotifier {
|
||||
AppearancePrefs._();
|
||||
static final AppearancePrefs instance = AppearancePrefs._();
|
||||
|
||||
static const _modeKey = 'appearance.themeMode.v1';
|
||||
static const _seedKey = 'appearance.seedColor.v1';
|
||||
|
||||
/// The first-party client's colour; a fresh install starts here.
|
||||
static const defaultSeed = 0xFF6C5CE7;
|
||||
|
||||
ThemeMode _themeMode = ThemeMode.system;
|
||||
int _seed = defaultSeed;
|
||||
bool _loaded = false;
|
||||
|
||||
ThemeMode get themeMode => _themeMode;
|
||||
Color get seedColor => Color(_seed);
|
||||
|
||||
Future<void> ensureLoaded() async {
|
||||
if (_loaded) return;
|
||||
_loaded = true;
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_themeMode = switch (prefs.getString(_modeKey)) {
|
||||
'light' => ThemeMode.light,
|
||||
'dark' => ThemeMode.dark,
|
||||
_ => ThemeMode.system,
|
||||
};
|
||||
_seed = prefs.getInt(_seedKey) ?? defaultSeed;
|
||||
notifyListeners();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> setThemeMode(ThemeMode mode) async {
|
||||
if (mode == _themeMode) return;
|
||||
_themeMode = mode;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_modeKey, mode.name);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> setSeedColor(int value) async {
|
||||
if (value == _seed) return;
|
||||
_seed = value;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_seedKey, value);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
/// The colours the appearance section offers; the first is the default.
|
||||
const appearanceSeeds = <int>[
|
||||
0xFF6C5CE7,
|
||||
0xFF2F80ED,
|
||||
0xFF00A884,
|
||||
0xFF0FA3B1,
|
||||
0xFFF2994A,
|
||||
0xFFEB5757,
|
||||
0xFFE84393,
|
||||
0xFF6B7280,
|
||||
];
|
||||
Reference in new issue
Block a user