此版本包含多项功能优化与修复: 1. 新增鸿蒙分层图标生成脚本,完善鸿蒙应用图标适配 2. 重构多处FutureProvider为NotifierProvider,修复ElementWithFuture异常 3. 更新flutter_tts依赖为鸿蒙适配版本,调整pubspec配置 4. 优化运势卡片样式文案,更新引导页功能介绍详情 5. 修复在线TTS服务Path正则匹配问题,支持含点号的路径 6. 重构通知权限、崩溃监控等状态管理逻辑 7. 更新翻译覆盖率统计,支持手动标注真实翻译进度 8. 优化编辑器工具栏、会话流页面交互细节 9. 新增日志筛选、导出CSV等增强功能 10. 调整设置页面文案,优化用户操作体验
87 lines
2.8 KiB
Dart
87 lines
2.8 KiB
Dart
/// ============================================================
|
||
/// 闲言APP — 壁纸预加载服务
|
||
/// 创建时间: 2026-05-24
|
||
/// 更新时间: 2026-05-24
|
||
/// 作用: WiFi环境下预加载快速源缩略图,用户打开壁纸页面时秒出图
|
||
/// 上次更新: v5.10.0 DefaultCacheManager替换为CustomCacheManager.instance统一缓存入口
|
||
/// ============================================================
|
||
|
||
import 'dart:async';
|
||
|
||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||
|
||
import '../../../core/services/data/image_cache_manager.dart';
|
||
import '../../../core/storage/kv_storage.dart';
|
||
import '../../../core/utils/logger.dart';
|
||
import '../models/template_models.dart';
|
||
import 'wallpaper_service.dart';
|
||
|
||
class WallpaperPreloadService {
|
||
WallpaperPreloadService._();
|
||
|
||
static const _keyPreloadEnabled = 'wallpaper_preload_enabled';
|
||
static const _keyLastPreloadTime = 'wallpaper_last_preload_time';
|
||
static const _preloadInterval = Duration(hours: 6);
|
||
|
||
/// 预加载开关是否启用
|
||
static bool get isEnabled => KvStorage.getBool(_keyPreloadEnabled) ?? true;
|
||
|
||
/// 设置预加载开关
|
||
static void setEnabled(bool v) => KvStorage.setBool(_keyPreloadEnabled, v);
|
||
|
||
/// 判断是否需要预加载(开关+时间间隔)
|
||
static bool get _shouldPreload {
|
||
if (!isEnabled) return false;
|
||
final lastMs = KvStorage.getInt(_keyLastPreloadTime) ?? 0;
|
||
if (lastMs == 0) return true;
|
||
final last = DateTime.fromMillisecondsSinceEpoch(lastMs);
|
||
return DateTime.now().difference(last) > _preloadInterval;
|
||
}
|
||
|
||
/// 按需预加载:WiFi + 开关 + 间隔满足时才执行
|
||
static Future<void> preloadIfNeeded() async {
|
||
if (!_shouldPreload) return;
|
||
|
||
final connectivity = await Connectivity().checkConnectivity();
|
||
final isWifi = connectivity.contains(ConnectivityResult.wifi);
|
||
if (!isWifi) {
|
||
Log.i('壁纸预加载: 非WiFi环境,跳过');
|
||
return;
|
||
}
|
||
|
||
Log.i('壁纸预加载: 开始预加载快速源缩略图');
|
||
final fastSources = WallpaperSource.values.where((s) => s.isFast).toList();
|
||
|
||
try {
|
||
final results = await WallpaperService.fetchMultiSource(
|
||
sources: fastSources,
|
||
limitPerSource: 8,
|
||
);
|
||
|
||
var count = 0;
|
||
for (final item in results) {
|
||
final thumbUrl = item.thumbnailUrl;
|
||
if (thumbUrl.isEmpty) continue;
|
||
try {
|
||
await CustomCacheManager.instance.downloadFile(thumbUrl);
|
||
count++;
|
||
} catch (_) {}
|
||
}
|
||
|
||
KvStorage.setInt(
|
||
_keyLastPreloadTime,
|
||
DateTime.now().millisecondsSinceEpoch,
|
||
);
|
||
Log.i('壁纸预加载: 完成,预加载 $count 张缩略图');
|
||
} catch (e) {
|
||
Log.e('壁纸预加载失败', e);
|
||
}
|
||
}
|
||
|
||
/// 强制预加载(忽略时间间隔)
|
||
static Future<void> forcePreload() async {
|
||
KvStorage.setInt(_keyLastPreloadTime, 0);
|
||
await preloadIfNeeded();
|
||
}
|
||
}
|