2
This commit is contained in:
1 parent
5ac164b407
commit
f93f6095af
94 files changed
+7877
-4018
No files matched your search
@@ -1,12 +1,10 @@
|
||||
import 'dart:io';
|
||||
import 'package:code_editor/models/distro_manifest.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../services/distro_installer.dart';
|
||||
import '../services/distro_manager.dart';
|
||||
|
||||
/// 终端多系统状态与默认系统持久化管理器
|
||||
/// 终端系统状态管理器(单一内置 Ubuntu 环境)
|
||||
class DistroProvider with ChangeNotifier {
|
||||
static const String _prefKeyDefaultSystem = 'terminal_default_system';
|
||||
|
||||
final DistroManager _manager = DistroManager();
|
||||
|
||||
@@ -37,42 +35,27 @@ class DistroProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 重新扫描已安装的系统并校准当前默认选中项
|
||||
/// 重新扫描已安装的系统并校准状态
|
||||
Future<void> refreshSystems() async {
|
||||
final systems = await _manager.listInstalledSystems();
|
||||
_installedSystems = systems;
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final savedSystem = prefs.getString(_prefKeyDefaultSystem);
|
||||
|
||||
if (savedSystem != null && _installedSystems.contains(savedSystem)) {
|
||||
_selectedSystem = savedSystem;
|
||||
} else if (_installedSystems.isNotEmpty) {
|
||||
_selectedSystem = _installedSystems.first;
|
||||
await prefs.setString(_prefKeyDefaultSystem, _selectedSystem!);
|
||||
final isInstalled = await _manager.isSystemInstalled(DistroRepository.defaultSystemName);
|
||||
if (isInstalled) {
|
||||
_installedSystems = [DistroRepository.defaultSystemName];
|
||||
_selectedSystem = DistroRepository.defaultSystemName;
|
||||
} else {
|
||||
_installedSystems = [];
|
||||
_selectedSystem = null;
|
||||
await prefs.remove(_prefKeyDefaultSystem);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 选择指定系统为当前活跃系统并持久化为默认系统
|
||||
/// 选择指定系统为当前活跃系统(仅支持默认 Ubuntu)
|
||||
Future<void> selectSystem(String systemName) async {
|
||||
if (!_installedSystems.contains(systemName)) return;
|
||||
|
||||
if (_selectedSystem != systemName) {
|
||||
_selectedSystem = systemName;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_prefKeyDefaultSystem, systemName);
|
||||
notifyListeners();
|
||||
}
|
||||
await refreshSystems();
|
||||
}
|
||||
|
||||
/// 从应用内置资源导入 Ubuntu 24.04 系统实例
|
||||
Future<void> importBuiltinUbuntu({
|
||||
required String systemName,
|
||||
String systemName = DistroRepository.defaultSystemName,
|
||||
InstallProgressCallback? onProgress,
|
||||
bool Function()? isCancelled,
|
||||
}) async {
|
||||
@@ -82,51 +65,7 @@ class DistroProvider with ChangeNotifier {
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
|
||||
// 导入成功后刷新列表并自动选为当前系统
|
||||
await refreshSystems();
|
||||
await selectSystem(systemName);
|
||||
}
|
||||
|
||||
/// 从应用内置资源导入 Alpine 系统实例(保留备用)
|
||||
Future<void> importBuiltinAlpine({
|
||||
required String systemName,
|
||||
InstallProgressCallback? onProgress,
|
||||
bool Function()? isCancelled,
|
||||
}) async {
|
||||
await _manager.importBuiltinAlpine(
|
||||
systemName: systemName,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
|
||||
// 导入成功后刷新列表并自动选为当前系统
|
||||
await refreshSystems();
|
||||
await selectSystem(systemName);
|
||||
}
|
||||
|
||||
/// 从外部 .tar.gz 压缩包导入自定义系统实例
|
||||
Future<void> importFromCustomTarGz({
|
||||
required String systemName,
|
||||
required File tarGzFile,
|
||||
InstallProgressCallback? onProgress,
|
||||
bool Function()? isCancelled,
|
||||
}) async {
|
||||
await _manager.importFromCustomTarGz(
|
||||
systemName: systemName,
|
||||
tarGzFile: tarGzFile,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
|
||||
// 导入成功后刷新列表并自动选为当前系统
|
||||
await refreshSystems();
|
||||
await selectSystem(systemName);
|
||||
}
|
||||
|
||||
/// 高危操作:删除指定系统实例
|
||||
Future<void> deleteSystem(String systemName) async {
|
||||
await _manager.deleteSystem(systemName);
|
||||
onSystemDeleted?.call(systemName);
|
||||
// 导入成功后刷新列表
|
||||
await refreshSystems();
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,20 @@ class RunProvider extends ChangeNotifier {
|
||||
void _resolveLastRunTask() {
|
||||
_lastRunTask = null;
|
||||
if (_lastRunTaskId == null) return;
|
||||
|
||||
// 单文件任务联动:如果上一次执行的任务是单文件任务(以 detected_single_ 开头)
|
||||
if (_lastRunTaskId!.startsWith('detected_single_')) {
|
||||
final singleTasks = _taskTable.tasksOf(RunTaskType.singleFile);
|
||||
if (singleTasks.isNotEmpty) {
|
||||
// 当前文件支持单文件运行,自动联动为当前文件的单文件任务
|
||||
_lastRunTask = singleTasks.first;
|
||||
_lastRunTaskId = singleTasks.first.id;
|
||||
return;
|
||||
}
|
||||
// 当前文件不支持单文件运行,清除当前可执行的 _lastRunTask(保留 _lastRunTaskId 以便切回可运行文件时恢复)
|
||||
return;
|
||||
}
|
||||
|
||||
for (final task in allTasks) {
|
||||
if (task.id == _lastRunTaskId) {
|
||||
_lastRunTask = task;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'package:code_editor/models/app_font.dart';
|
||||
import 'package:code_editor/models/distro_manifest.dart';
|
||||
import 'package:code_editor/models/editor_theme.dart';
|
||||
import 'package:code_editor/models/virtual_keyboard_config.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -34,8 +33,8 @@ class SettingsProvider extends ChangeNotifier {
|
||||
//项目配置
|
||||
static const String _keyShowHiddenFiles = 'show_hidden_files'; //显示隐藏文件
|
||||
|
||||
//下载配置
|
||||
static const String _keyDownloadMirrorId = 'download_mirror_id'; //下载源镜像ID
|
||||
//代码补全
|
||||
static const String _keyEnableLspCompletion = 'enable_lsp_completion'; //LSP智能代码补全启用
|
||||
|
||||
//语言
|
||||
static const String _keyAppLocale = 'app_locale';
|
||||
@@ -60,12 +59,13 @@ class SettingsProvider extends ChangeNotifier {
|
||||
String _terminalKeyboardConfigJson = VirtualKeyboardConfig.defaultTerminalJsonPretty();
|
||||
VirtualKeyboardConfig _terminalKeyboardConfig = VirtualKeyboardConfig.defaultTerminalConfiguration();
|
||||
bool _showHiddenFiles = true;
|
||||
String _downloadMirrorId = 'tsinghua'; // 默认清华源
|
||||
bool _enableLspCompletion = true;
|
||||
Locale? _locale;
|
||||
|
||||
bool get showHiddenFiles => _showHiddenFiles;
|
||||
String get downloadMirrorId => _downloadMirrorId;
|
||||
DistroMirror get downloadMirror => DistroRepository.getMirrorById(_downloadMirrorId);
|
||||
@Deprecated('本地补全已完全移除')
|
||||
bool get enableLocalCompletion => false;
|
||||
bool get enableLspCompletion => _enableLspCompletion;
|
||||
|
||||
ThemeMode get appThemeMode => _appThemeMode;
|
||||
Color get appThemeColor => _appThemeColor;
|
||||
@@ -291,10 +291,10 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_showHiddenFiles = savedShowHiddenFiles;
|
||||
}
|
||||
|
||||
//设置下载源镜像配置
|
||||
final savedMirrorId = prefs.getString(_keyDownloadMirrorId);
|
||||
if (savedMirrorId != null && savedMirrorId.isNotEmpty) {
|
||||
_downloadMirrorId = savedMirrorId;
|
||||
//设置代码补全
|
||||
final savedEnableLspCompletion = prefs.getBool(_keyEnableLspCompletion);
|
||||
if (savedEnableLspCompletion != null) {
|
||||
_enableLspCompletion = savedEnableLspCompletion;
|
||||
}
|
||||
|
||||
//设置语言
|
||||
@@ -482,14 +482,18 @@ class SettingsProvider extends ChangeNotifier {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 设置系统安装包下载镜像源
|
||||
Future<void> setDownloadMirrorId(String mirrorId) async {
|
||||
if (_downloadMirrorId == mirrorId) return;
|
||||
_downloadMirrorId = mirrorId;
|
||||
/// 设置是否启用本地基础补全(本地补全已移除,保留此方法仅作向后兼容)
|
||||
@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.setString(_keyDownloadMirrorId, mirrorId);
|
||||
await prefs.setBool(_keyEnableLspCompletion, enable);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user