Files
LN-Code-Editor/lib/providers/settings_provider.dart
T

639 lines
24 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:convert';
import 'package:code_editor/models/app_font.dart';
import 'package:code_editor/models/editor_theme.dart';
import 'package:code_editor/models/virtual_keyboard_config.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// 容器运行模式
enum ContainerRuntimeMode {
/// 自动模式:检测到 Root 权限时优先启用 Chroot,无 Root 或挂载失败自动使用 PRoot
auto,
/// PRoot 模式:纯用户态沙箱运行,无需系统 Root 权限,安全兼容
proot,
/// Chroot 模式:Linux 原生内核执行,无 ptrace 开销,满血性能
chroot,
}
class SettingsProvider extends ChangeNotifier {
//外观
static const String _keyAppThemeMode = 'app_theme_mode'; //应用主题
static const String _keyAppThemeColor = 'app_theme_color'; //主题颜色
static const String _keyUiFont = 'app_ui_font'; //界面字体
//编辑区
static const String _keyEditorTheme = 'editor_theme_id'; //代码主题
static const String _keyEditorFontSize = 'editor_font_size'; //代码字体大小
static const String _keyEditorIndentSize = 'editor_indent_size'; //缩进大小
static const String _keyWordWrap = 'editor_word_wrap'; //自动换行
static const String _keyShowLineNumbers = 'editor_show_line_numbers'; //显示行号
static const String _keyPinLineNumbers = 'editor_pin_line_numbers'; //固定行号
static const String _keyEnableVirtualKeyboard = 'enable_virtual_keyboard'; //小键盘启用
static const String _keyVirtualKeyboardConfig = 'virtual_keyboard_config'; //小键盘配置JSON
static const String _keyEditorFont = 'editor_font_family'; //代码字体
//终端
static const String _keyTerminalFont = 'terminal_font_family'; //终端字体
static const String _keyTerminalFontSize = 'terminal_font_size'; //终端字号
static const String _keyTerminalBackgroundColor = 'terminal_background_color'; //终端背景颜色
static const String _keyEnableTerminalVirtualKeyboard = 'enable_terminal_virtual_keyboard'; //终端小键盘启用
static const String _keyTerminalKeyboardConfig = 'terminal_virtual_keyboard_config'; //终端小键盘配置JSON
//项目配置
static const String _keyShowHiddenFiles = 'show_hidden_files'; //显示隐藏文件
//代码补全
static const String _keyEnableLspCompletion = 'enable_lsp_completion'; //LSP智能代码补全总开关
static const String _keyEnableCodeCompletion = 'enable_code_completion'; //代码补全子开关
static const String _keyEnableCodeDiagnostics = 'enable_code_diagnostics'; //代码纠错子开关
//语言
static const String _keyAppLocale = 'app_locale';
//容器
static const String _keyContainerRuntimeMode = 'container_runtime_mode';
static const String _keyHasPromptedRootRequest = 'has_prompted_root_request';
//应用更新
static const String _keyAutoCheckUpdate = 'auto_check_update';
static const String _keySuppressedUpdateVersionCode = 'suppressed_update_version_code';
/// 字号配置常量(编辑区与终端统一)
static const double minFontSize = 8.0;
static const double maxFontSize = 30.0;
static const double defaultFontSize = 14.0;
static const double defaultTerminalFontSize = 13.0;
static const int fontSizeDivisions = 22; // (maxFontSize - minFontSize).toInt()
ThemeMode _appThemeMode = ThemeMode.system;
Color _appThemeColor = Colors.blue;
String _uiFontId = 'system_default';
EditorTheme _editorTheme = EditorTheme.atomOneDark;
String _editorFontId = 'jetbrains_mono';
String _terminalFontId = 'jetbrains_mono';
Color _terminalBackgroundColor = const Color(0xFF1E1E1E);
double _terminalFontSize = defaultTerminalFontSize;
double _fontSize = defaultFontSize;
int _indentSize = 4;
bool _wordWrap = false;
bool _showLineNumbers = true;
bool _pinLineNumbers = false;
bool _enableVirtualKeyboard = defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS;
String _virtualKeyboardConfigJson = VirtualKeyboardConfig.defaultJsonPretty();
VirtualKeyboardConfig _virtualKeyboardConfig = VirtualKeyboardConfig.defaultConfiguration();
bool _enableTerminalVirtualKeyboard = defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS;
String _terminalKeyboardConfigJson = VirtualKeyboardConfig.defaultTerminalJsonPretty();
VirtualKeyboardConfig _terminalKeyboardConfig = VirtualKeyboardConfig.defaultTerminalConfiguration();
bool _showHiddenFiles = true;
bool _enableLspCompletion = true;
bool _enableCodeCompletion = true;
bool _enableCodeDiagnostics = true;
ContainerRuntimeMode _containerRuntimeMode = ContainerRuntimeMode.auto;
bool _hasPromptedRootRequest = false;
bool _autoCheckUpdate = true;
int _suppressedUpdateVersionCode = 0;
Locale? _locale;
bool get showHiddenFiles => _showHiddenFiles;
@Deprecated('本地补全已完全移除')
bool get enableLocalCompletion => false;
bool get enableLspCompletion => _enableLspCompletion;
bool get enableCodeCompletion => _enableCodeCompletion;
bool get enableCodeDiagnostics => _enableCodeDiagnostics;
ContainerRuntimeMode get containerRuntimeMode => _containerRuntimeMode;
bool get hasPromptedRootRequest => _hasPromptedRootRequest;
bool get autoCheckUpdate => _autoCheckUpdate;
int get suppressedUpdateVersionCode => _suppressedUpdateVersionCode;
ThemeMode get appThemeMode => _appThemeMode;
Color get appThemeColor => _appThemeColor;
String get uiFontId => _uiFontId;
AppFontItem get uiFont => AppFonts.getUiFont(_uiFontId);
EditorTheme get editorTheme => _editorTheme;
String get editorFontId => _editorFontId;
AppFontItem get editorFont => AppFonts.getEditorFont(_editorFontId);
String get terminalFontId => _terminalFontId;
AppFontItem get terminalFont => AppFonts.getTerminalFont(_terminalFontId);
Color get terminalBackgroundColor => _terminalBackgroundColor;
double get terminalFontSize => _terminalFontSize;
double get fontSize => _fontSize;
int get indentSize => _indentSize;
bool get wordWrap => _wordWrap;
bool get showLineNumbers => _showLineNumbers;
bool get pinLineNumbers => _pinLineNumbers;
bool get enableVirtualKeyboard => _enableVirtualKeyboard;
String get virtualKeyboardConfigJson => _virtualKeyboardConfigJson;
VirtualKeyboardConfig get virtualKeyboardConfig => _virtualKeyboardConfig;
bool get enableTerminalVirtualKeyboard => _enableTerminalVirtualKeyboard;
String get terminalKeyboardConfigJson => _terminalKeyboardConfigJson;
VirtualKeyboardConfig get terminalKeyboardConfig => _terminalKeyboardConfig;
Locale? get locale => _locale;
// ==========================================
// 小键盘配置:按作用域(编辑区 / 终端)读写两份互不干扰的配置
// ==========================================
/// 读取指定作用域的键盘配置
VirtualKeyboardConfig keyboardConfigFor(KeyboardScope scope) =>
scope == KeyboardScope.terminal ? _terminalKeyboardConfig : _virtualKeyboardConfig;
/// 读取指定作用域的键盘配置 JSON
String keyboardConfigJsonFor(KeyboardScope scope) =>
scope == KeyboardScope.terminal ? _terminalKeyboardConfigJson : _virtualKeyboardConfigJson;
/// 指定作用域的小键盘是否启用(两个开关相互独立)
bool keyboardEnabledFor(KeyboardScope scope) =>
scope == KeyboardScope.terminal ? _enableTerminalVirtualKeyboard : _enableVirtualKeyboard;
static String _enablePrefKey(KeyboardScope scope) =>
scope == KeyboardScope.terminal ? _keyEnableTerminalVirtualKeyboard : _keyEnableVirtualKeyboard;
static String _configPrefKey(KeyboardScope scope) =>
scope == KeyboardScope.terminal ? _keyTerminalKeyboardConfig : _keyVirtualKeyboardConfig;
/// 设置指定作用域小键盘的启用状态
Future<void> setKeyboardEnabled(KeyboardScope scope, bool enable) async {
if (keyboardEnabledFor(scope) == enable) return;
if (scope == KeyboardScope.terminal) {
_enableTerminalVirtualKeyboard = enable;
} else {
_enableVirtualKeyboard = enable;
}
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_enablePrefKey(scope), enable);
} catch (_) {}
}
/// 保存指定作用域的键盘配置 JSON,校验失败返回 false
Future<bool> setKeyboardConfig(KeyboardScope scope, String jsonStr) async {
final err = VirtualKeyboardConfig.validateJson(jsonStr, scope);
if (err != null) {
return false;
}
try {
final decoded = jsonDecode(jsonStr) as Map<String, dynamic>;
final config = VirtualKeyboardConfig.fromJson(decoded);
if (scope == KeyboardScope.terminal) {
_terminalKeyboardConfig = config;
_terminalKeyboardConfigJson = jsonStr;
} else {
_virtualKeyboardConfig = config;
_virtualKeyboardConfigJson = jsonStr;
}
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_configPrefKey(scope), jsonStr);
return true;
} catch (_) {
return false;
}
}
/// 将指定作用域的键盘配置恢复为该作用域的默认预设
Future<void> resetKeyboardConfig(KeyboardScope scope) async {
if (scope == KeyboardScope.terminal) {
_terminalKeyboardConfig = VirtualKeyboardConfig.defaultTerminalConfiguration();
_terminalKeyboardConfigJson = VirtualKeyboardConfig.defaultTerminalJsonPretty();
} else {
_virtualKeyboardConfig = VirtualKeyboardConfig.defaultConfiguration();
_virtualKeyboardConfigJson = VirtualKeyboardConfig.defaultJsonPretty();
}
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_configPrefKey(scope));
} catch (_) {}
}
Future<void> init() async {
await _loadSettings();
}
Future<void> _loadSettings() async {
try {
final prefs = await SharedPreferences.getInstance();
//设置外观
final themeModeName = prefs.getString(_keyAppThemeMode);
if(themeModeName != null) {
_appThemeMode = ThemeMode.values.firstWhere(
(e) => e.name == themeModeName,
orElse: () => ThemeMode.system,
);
}
final savedThemeColor = prefs.getInt(_keyAppThemeColor);
if (savedThemeColor != null) {
_appThemeColor = Color(savedThemeColor);
}
//设置编辑区
final themeId = prefs.getString(_keyEditorTheme);
_editorTheme = EditorTheme.fromId(themeId);
final savedFontSize = prefs.getDouble(_keyEditorFontSize);
if(savedFontSize != null && savedFontSize >= minFontSize && savedFontSize <= maxFontSize) {
_fontSize = savedFontSize;
}
final savedIndentSize = prefs.getInt(_keyEditorIndentSize);
if (savedIndentSize != null && (savedIndentSize == 2 || savedIndentSize == 4 || savedIndentSize == 8)) {
_indentSize = savedIndentSize;
}
final savedWordWrap = prefs.getBool(_keyWordWrap);
if(savedWordWrap != null) {
_wordWrap = savedWordWrap;
}
final savedShowLineNumbers = prefs.getBool(_keyShowLineNumbers);
if (savedShowLineNumbers != null) {
_showLineNumbers = savedShowLineNumbers;
}
final savedPinLineNumbers = prefs.getBool(_keyPinLineNumbers);
if (savedPinLineNumbers != null) {
_pinLineNumbers = savedPinLineNumbers;
}
final savedEnableVirtualKeyboard = prefs.getBool(_keyEnableVirtualKeyboard);
if (savedEnableVirtualKeyboard != null) {
_enableVirtualKeyboard = savedEnableVirtualKeyboard;
}
final savedKeyboardConfig = prefs.getString(_keyVirtualKeyboardConfig);
if (savedKeyboardConfig != null && savedKeyboardConfig.trim().isNotEmpty) {
final err = VirtualKeyboardConfig.validateJson(savedKeyboardConfig, KeyboardScope.editor);
if (err == null) {
try {
final decoded = jsonDecode(savedKeyboardConfig) as Map<String, dynamic>;
_virtualKeyboardConfig = VirtualKeyboardConfig.fromJson(decoded);
_virtualKeyboardConfigJson = savedKeyboardConfig;
} catch (_) {}
}
}
//终端小键盘(独立开关 + 独立配置)
final savedEnableTerminalKeyboard = prefs.getBool(_keyEnableTerminalVirtualKeyboard);
if (savedEnableTerminalKeyboard != null) {
_enableTerminalVirtualKeyboard = savedEnableTerminalKeyboard;
}
final savedTerminalKeyboardConfig = prefs.getString(_keyTerminalKeyboardConfig);
if (savedTerminalKeyboardConfig != null && savedTerminalKeyboardConfig.trim().isNotEmpty) {
final err = VirtualKeyboardConfig.validateJson(savedTerminalKeyboardConfig, KeyboardScope.terminal);
if (err == null) {
try {
final decoded = jsonDecode(savedTerminalKeyboardConfig) as Map<String, dynamic>;
_terminalKeyboardConfig = VirtualKeyboardConfig.fromJson(decoded);
_terminalKeyboardConfigJson = savedTerminalKeyboardConfig;
} catch (_) {}
}
}
//设置字体
final savedUiFont = prefs.getString(_keyUiFont);
if (savedUiFont != null && savedUiFont.isNotEmpty) {
_uiFontId = savedUiFont;
}
final savedEditorFont = prefs.getString(_keyEditorFont);
if (savedEditorFont != null && savedEditorFont.isNotEmpty) {
_editorFontId = savedEditorFont;
}
final savedTerminalFont = prefs.getString(_keyTerminalFont);
if (savedTerminalFont != null && savedTerminalFont.isNotEmpty) {
_terminalFontId = savedTerminalFont;
}
final savedTerminalBackground = prefs.getInt(_keyTerminalBackgroundColor);
if (savedTerminalBackground != null) {
_terminalBackgroundColor = Color(savedTerminalBackground);
}
final savedTerminalFontSize = prefs.getDouble(_keyTerminalFontSize);
if (savedTerminalFontSize != null) {
_terminalFontSize = savedTerminalFontSize.clamp(minFontSize, maxFontSize);
}
//设置项目配置
final savedShowHiddenFiles = prefs.getBool(_keyShowHiddenFiles);
if (savedShowHiddenFiles != null) {
_showHiddenFiles = savedShowHiddenFiles;
}
//设置代码补全
final savedEnableLspCompletion = prefs.getBool(_keyEnableLspCompletion);
if (savedEnableLspCompletion != null) {
_enableLspCompletion = savedEnableLspCompletion;
}
final savedEnableCodeCompletion = prefs.getBool(_keyEnableCodeCompletion);
if (savedEnableCodeCompletion != null) {
_enableCodeCompletion = savedEnableCodeCompletion;
}
final savedEnableCodeDiagnostics = prefs.getBool(_keyEnableCodeDiagnostics);
if (savedEnableCodeDiagnostics != null) {
_enableCodeDiagnostics = savedEnableCodeDiagnostics;
}
//设置语言
final savedLocale = prefs.getString(_keyAppLocale);
if(savedLocale != null && savedLocale.isNotEmpty) {
_locale = Locale(savedLocale);
} else {
_locale = null;
}
//设置容器运行模式与 Root 提示标记
final savedRuntimeMode = prefs.getString(_keyContainerRuntimeMode);
if (savedRuntimeMode != null) {
_containerRuntimeMode = ContainerRuntimeMode.values.firstWhere(
(e) => e.name == savedRuntimeMode,
orElse: () => ContainerRuntimeMode.auto,
);
}
final savedPromptedRoot = prefs.getBool(_keyHasPromptedRootRequest);
if (savedPromptedRoot != null) {
_hasPromptedRootRequest = savedPromptedRoot;
}
//应用更新配置
final savedAutoCheckUpdate = prefs.getBool(_keyAutoCheckUpdate);
if (savedAutoCheckUpdate != null) {
_autoCheckUpdate = savedAutoCheckUpdate;
}
final savedSuppressedUpdateVersion = prefs.getInt(_keySuppressedUpdateVersionCode);
if (savedSuppressedUpdateVersion != null) {
_suppressedUpdateVersionCode = savedSuppressedUpdateVersion;
}
notifyListeners();
}catch (_) {}
}
/// 设置容器运行模式 (auto / proot / chroot)
Future<void> setContainerRuntimeMode(ContainerRuntimeMode mode) async {
if (_containerRuntimeMode == mode) return;
_containerRuntimeMode = mode;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyContainerRuntimeMode, mode.name);
} catch (_) {}
}
/// 设置是否已主动申请过 Root 权限标记
Future<void> setHasPromptedRootRequest(bool value) async {
if (_hasPromptedRootRequest == value) return;
_hasPromptedRootRequest = value;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyHasPromptedRootRequest, value);
} catch (_) {}
}
/// 设置是否启动时自动检查应用更新
Future<void> setAutoCheckUpdate(bool enabled) async {
if (_autoCheckUpdate == enabled) return;
_autoCheckUpdate = enabled;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyAutoCheckUpdate, enabled);
} catch (_) {}
}
/// 记录用户选择“不再提示”的版本号
Future<void> setSuppressedUpdateVersionCode(int versionCode) async {
if (_suppressedUpdateVersionCode == versionCode) return;
_suppressedUpdateVersionCode = versionCode;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_keySuppressedUpdateVersionCode, versionCode);
} catch (_) {}
}
Future<void> setAppThemeMode(ThemeMode mode) async {
if(_appThemeMode == mode) return;
_appThemeMode = mode;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyAppThemeMode, mode.name);
}catch (_) {}
}
/// 设置主题颜色(Material 3 的 seed color)
Future<void> setAppThemeColor(Color color) async {
if (_appThemeColor.toARGB32() == color.toARGB32()) return;
_appThemeColor = color;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_keyAppThemeColor, color.toARGB32());
} catch (_) {}
}
Future<void> setEditorTheme(EditorTheme theme) async {
if(_editorTheme.id == theme.id) return;
_editorTheme = theme;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyEditorTheme, theme.id);
}catch(_) {}
}
Future<void> setFontSize(double size) async {
final clamped = size.clamp(minFontSize, maxFontSize);
if(_fontSize == clamped) return;
_fontSize = clamped;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setDouble(_keyEditorFontSize, clamped);
}catch (_) {}
}
Future<void> setIndentSize(int size) async {
if (size != 2 && size != 4 && size != 8) return;
if (_indentSize == size) return;
_indentSize = size;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_keyEditorIndentSize, size);
} catch (_) {}
}
Future<void> setWordWrap(bool wrap) async {
if(_wordWrap == wrap) return;
_wordWrap = wrap;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyWordWrap, wrap);
}catch (_) {}
}
Future<void> setShowLineNumbers(bool show) async {
if (_showLineNumbers == show) return;
_showLineNumbers = show;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyShowLineNumbers, show);
} catch (_) {}
}
Future<void> setPinLineNumbers(bool pin) async {
if (_pinLineNumbers == pin) return;
_pinLineNumbers = pin;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyPinLineNumbers, pin);
} catch (_) {}
}
/// 编辑区小键盘开关(等价于 `setKeyboardEnabled(KeyboardScope.editor, ...)`)
Future<void> setEnableVirtualKeyboard(bool enable) =>
setKeyboardEnabled(KeyboardScope.editor, enable);
/// 编辑区小键盘配置(等价于 `setKeyboardConfig(KeyboardScope.editor, ...)`)
Future<bool> setVirtualKeyboardConfig(String jsonStr) =>
setKeyboardConfig(KeyboardScope.editor, jsonStr);
/// 编辑区小键盘恢复默认
Future<void> resetVirtualKeyboardConfig() =>
resetKeyboardConfig(KeyboardScope.editor);
Future<void> setLocale(Locale? newLocale) async {
if(_locale == newLocale) return;
_locale = newLocale;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
if(newLocale == null) {
await prefs.remove(_keyAppLocale);
} else {
await prefs.setString(_keyAppLocale, newLocale.languageCode);
}
}catch (_) {}
}
Future<void> setUiFontId(String fontId) async {
if (_uiFontId == fontId) return;
_uiFontId = fontId;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyUiFont, fontId);
} catch (_) {}
}
Future<void> setEditorFontId(String fontId) async {
if (_editorFontId == fontId) return;
_editorFontId = fontId;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyEditorFont, fontId);
} catch (_) {}
}
Future<void> setTerminalFontId(String fontId) async {
if (_terminalFontId == fontId) return;
_terminalFontId = fontId;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyTerminalFont, fontId);
} catch (_) {}
}
/// 设置终端背景颜色
Future<void> setTerminalBackgroundColor(Color color) async {
if (_terminalBackgroundColor.toARGB32() == color.toARGB32()) return;
_terminalBackgroundColor = color;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_keyTerminalBackgroundColor, color.toARGB32());
} catch (_) {}
}
/// 设置终端字体大小
Future<void> setTerminalFontSize(double size) async {
final clamped = size.clamp(minFontSize, maxFontSize);
if (_terminalFontSize == clamped) return;
_terminalFontSize = clamped;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setDouble(_keyTerminalFontSize, clamped);
} catch (_) {}
}
/// 设置是否显示隐藏文件
Future<void> setShowHiddenFiles(bool show) async {
if (_showHiddenFiles == show) return;
_showHiddenFiles = show;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyShowHiddenFiles, show);
} catch (_) {}
}
/// 设置是否启用本地基础补全(本地补全已移除,保留此方法仅作向后兼容)
@Deprecated('本地补全已完全移除')
Future<void> setEnableLocalCompletion(bool enable) async {}
/// 设置是否启用LSP后端代码补全(总开关)
Future<void> setEnableLspCompletion(bool enable) async {
if (_enableLspCompletion == enable) return;
_enableLspCompletion = enable;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyEnableLspCompletion, enable);
} catch (_) {}
}
/// 设置是否启用代码补全子功能
Future<void> setEnableCodeCompletion(bool enable) async {
if (_enableCodeCompletion == enable) return;
_enableCodeCompletion = enable;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyEnableCodeCompletion, enable);
} catch (_) {}
}
/// 设置是否启用代码纠错子功能
Future<void> setEnableCodeDiagnostics(bool enable) async {
if (_enableCodeDiagnostics == enable) return;
_enableCodeDiagnostics = enable;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_keyEnableCodeDiagnostics, enable);
} catch (_) {}
}
}