Parcourir la source

release 1.0.9+9

guoziyun il y a 4 mois
Parent
commit
746790edac

+ 2 - 1
CHANGELOG.md

@@ -24,4 +24,5 @@
 - download优化,增加防抖;缓存文件写入优化, 先写入tmp文件,再重命名,保证是原子操作,避免写入“半截”文件的可能性
 - "下一关"按钮防抖和安全pop up优化(根据firebase报错的修改)
 - 内存分级, 低内存设备不展示banner广告
-- 启动优化, 启动main中所有堵塞性的await, 改为立即启动ui,后台并行初始化firebase,本地存储等await动作 -资源竞争优化: 关卡结束点击next, 立即pop up返回主页, 不再等待插屏广告结果再次回到play页面, 这样的好处是可以立即释放play界面资源,为插屏广告腾出内存空间。 用户体验也会更好,广告结束直接就在首页,不会闪
+- 启动优化, 启动main中所有堵塞性的await, 改为立即启动ui,后台并行初始化firebase,本地存储等await动作
+- 资源竞争优化: 关卡结束点击next, 立即pop up返回主页, 不再等待插屏广告结果再次回到play页面, 这样的好处是可以立即释放play界面资源,为插屏广告腾出内存空间。 用户体验也会更好,广告结束直接就在首页,不会闪

+ 0 - 1
lib/config/config.dart

@@ -13,4 +13,3 @@ class Config {
 
   Config(BuildContext context, Directory baseDir) : device = Device(context, baseDir);
 }
-

+ 1 - 2
lib/homepage/home_screen.dart

@@ -382,8 +382,6 @@ class _HomeScreen extends AdsState<HomeScreen> with TickerProviderStateMixin {
             style: TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 24),
           ),
         ),
-        // title: // Release模式下显示内存信息
-        //     MemoryMonitor.getMemoryWidget(),
         actions: [
           IconButton(
             onPressed: () {
@@ -397,6 +395,7 @@ class _HomeScreen extends AdsState<HomeScreen> with TickerProviderStateMixin {
       body: Column(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
         children: [
+          if (Config.isDebug) MemoryMonitor.getMemoryWidget(),
           Expanded(
             child: Column(
               mainAxisAlignment: MainAxisAlignment.spaceEvenly,

+ 8 - 5
lib/main.dart

@@ -30,6 +30,7 @@ import 'package:puzzleweave/utils/utils.dart';
 import 'package:puzzleweave/utils/memory_monitor.dart';
 
 import 'config/config.dart' as cfg;
+import 'config/config.dart';
 import 'config/device.dart';
 
 Logger _log = Logger('main.dart');
@@ -104,11 +105,13 @@ class _MyAppState extends State<MyApp> {
       });
 
       // 启动内存监控
-      MemoryMonitor().startMonitoring(
-        interval: const Duration(seconds: 3),
-        onHighMemory: () => _log.warning('High memory detected'),
-        onCriticalMemory: () => _log.severe('Critical memory - emergency cleanup triggered'),
-      );
+      if (Config.isDebug) {
+        MemoryMonitor().startMonitoring(
+          interval: const Duration(seconds: 3),
+          onHighMemory: () => _log.warning('High memory detected'),
+          onCriticalMemory: () => _log.severe('Critical memory - emergency cleanup triggered'),
+        );
+      }
 
       _log.info('App initialization completed successfully');
     } catch (e, stack) {

+ 2 - 1
lib/play/board_play.dart

@@ -34,6 +34,7 @@ import 'package:puzzleweave/utils/memory_monitor.dart';
 import 'package:vector_math/vector_math.dart' as vmath;
 import 'package:vibration/vibration.dart';
 import '../ads/ads_state.dart';
+import '../config/config.dart';
 
 final Logger _log = Logger('board_play.dart');
 
@@ -769,7 +770,7 @@ class _BoardPlayState extends AdsState<BoardPlay> with TickerProviderStateMixin
             successBanner,
             nextButton,
             // Release模式下显示内存信息
-            // Positioned(top: 100, right: 10, child: MemoryMonitor.getMemoryWidget()),
+            if (Config.isDebug) Positioned(top: 100, right: 10, child: MemoryMonitor.getMemoryWidget()),
             if (_isLoading)
               Positioned.fill(
                 child: Container(

+ 0 - 135
lib/play/overlayer.bak.dart

@@ -1,135 +0,0 @@
-import 'dart:ui' as ui;
-
-import 'package:flutter/material.dart';
-import 'package:logging/logging.dart';
-import 'package:puzzleweave/play/board.dart';
-
-final _log = Logger('overlayer.dart');
-
-class HintItem {
-  final ui.Image finger;
-  final Rect srcRect;
-  final Rect destRect;
-  final CurveTween tween;
-
-  HintItem(this.finger, this.srcRect, this.destRect) : tween = CurveTween(curve: Curves.easeInOut);
-
-  Rect getCurrent(double t) {
-    return Rect.lerp(srcRect, destRect, tween.transform(t))!;
-  }
-
-  // 动画的前 10% 和后 10% 渐入渐出,中间 80% 完全不透明
-  double getOpacity(double t) {
-    if (t < 0.1) {
-      return t * 10;
-    } else if (t >= 0.1 && t <= 0.9) {
-      return 1;
-    } else {
-      return (1 - t) * 10;
-    }
-  }
-}
-
-class OverLayer {
-  final Board board;
-  final TickerProvider tickerProvider;
-  OverlayEntry? _overlayEntry;
-  bool _isDisposed = false;
-
-  final ValueNotifier<int> _notifier = ValueNotifier(0);
-
-  late AnimationController hintAnimation;
-  Listenable get notifiers => Listenable.merge([_notifier, hintAnimation]);
-
-  OverLayer(this.board, this.tickerProvider) {
-    hintAnimation = AnimationController(value: 0, vsync: tickerProvider, duration: const Duration(milliseconds: 1200));
-  }
-
-  void invalidate() {
-    _notifier.value++;
-  }
-
-  void setup(BuildContext context) {
-    if (_overlayEntry != null) return;
-
-    // 创建并插入 OverlayEntry
-    _overlayEntry = OverlayEntry(
-      builder: (context) {
-        return Positioned.fill(
-          // 关键:IgnorePointer 确保手势引导动画不会阻碍底层的 BoardPlay 交互
-          child: IgnorePointer(
-            child: RepaintBoundary(child: CustomPaint(painter: OverLayerPainter(this))),
-          ),
-        );
-      },
-    );
-    Overlay.of(context).insert(_overlayEntry!);
-  }
-
-  HintItem? _hintItem;
-  HintItem? get hintItem => _hintItem;
-
-  void doHint(HintItem hintItem) {
-    ///上一次hint没有完成
-    if (_isDisposed || _hintItem != null) {
-      return;
-    }
-
-    _hintItem = hintItem;
-    hintAnimation.reset();
-    hintAnimation.repeat(); // 重复播放动画
-  }
-
-  void stopHint() {
-    if (!_isDisposed && _hintItem != null) {
-      hintAnimation.stop();
-      _hintItem = null;
-
-      invalidate();
-    }
-  }
-
-  bool get isHinting => _hintItem != null && hintAnimation.isAnimating;
-
-  destroy() {
-    _isDisposed = true; // 标记已销毁
-    _overlayEntry?.remove();
-    _overlayEntry = null;
-    hintAnimation.dispose();
-  }
-}
-
-class OverLayerPainter extends CustomPainter {
-  final OverLayer overLayer;
-
-  OverLayerPainter(this.overLayer) : super(repaint: overLayer.notifiers);
-
-  @override
-  void paint(Canvas canvas, Size size) {
-    // canvas.clipRect(Offset.zero & size);
-    if (overLayer.hintItem != null) {
-      _paintHintItem(canvas, overLayer.hintItem!);
-    }
-  }
-
-  void _paintHintItem(Canvas canvas, HintItem hintItem) {
-    Rect srcRect = Offset.zero & Size(hintItem.finger.width.toDouble(), hintItem.finger.height.toDouble());
-    Rect currentRect = hintItem.getCurrent(overLayer.hintAnimation.value);
-
-    // 完善点: 计算并应用透明度
-    double opacity = hintItem.getOpacity(overLayer.hintAnimation.value);
-
-    // 创建 Paint,通过 color.withOpacity 控制透明度
-    final paint = Paint()
-      ..color = Colors.white.withOpacity(opacity)
-      ..isAntiAlias = true;
-
-    // 绘制图片
-    canvas.drawImageRect(hintItem.finger, srcRect, currentRect, paint);
-  }
-
-  @override
-  bool shouldRepaint(covariant CustomPainter oldDelegate) {
-    return false;
-  }
-}

+ 9 - 11
lib/utils/memory_monitor.dart

@@ -9,6 +9,8 @@ import 'package:logging/logging.dart';
 import 'package:puzzleweave/firebase/firebase_helper.dart';
 import 'package:puzzleweave/models/download.dart';
 
+import '../config/config.dart';
+
 final Logger _log = Logger('MemoryMonitor');
 
 /// 内存阶段定义
@@ -32,7 +34,7 @@ class MemoryMonitor with WidgetsBindingObserver {
 
   VoidCallback? _onHighMemory;
   VoidCallback? _onCriticalMemory;
-  
+
   // Release模式下的内存显示
   static final ValueNotifier<String> memoryDisplay = ValueNotifier<String>('Memory: 0MB');
 
@@ -110,7 +112,7 @@ class MemoryMonitor with WidgetsBindingObserver {
 
     try {
       final memoryMB = getCurrentMemoryMB();
-      
+
       // 更新UI显示
       memoryDisplay.value = 'Memory: ${memoryMB.toStringAsFixed(1)}MB';
 
@@ -185,15 +187,17 @@ class MemoryMonitor with WidgetsBindingObserver {
 
   /// 供外部在关键节点(如播广告前)手动清理
   void manualCleanup() {
+    if (!Config.isDebug) return;
     _emergencyCleanup(reason: 'manual_call');
   }
 
   static void logMemoryUsage(String label) {
+    if (!Config.isDebug) return;
     final memoryMB = getCurrentMemoryMB();
     memoryDisplay.value = '[$label] ${memoryMB.toStringAsFixed(1)}MB';
     _log.info('[$label] RSS Memory: ${memoryMB.toStringAsFixed(1)} MB');
   }
-  
+
   /// 获取内存显示组件(供Release模式使用)
   static Widget getMemoryWidget() {
     return ValueListenableBuilder<String>(
@@ -201,14 +205,8 @@ class MemoryMonitor with WidgetsBindingObserver {
       builder: (context, value, child) {
         return Container(
           padding: EdgeInsets.all(4),
-          decoration: BoxDecoration(
-            color: Colors.black54,
-            borderRadius: BorderRadius.circular(4),
-          ),
-          child: Text(
-            value,
-            style: TextStyle(color: Colors.white, fontSize: 12),
-          ),
+          decoration: BoxDecoration(color: Colors.black54, borderRadius: BorderRadius.circular(4)),
+          child: Text(value, style: TextStyle(color: Colors.white, fontSize: 12)),
         );
       },
     );

+ 1 - 1
pubspec.yaml

@@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
 # In Windows, build-name is used as the major, minor, and patch parts
 # of the product and file versions while build-number is used as the build suffix.
-version: 1.0.8+8
+version: 1.0.9+9
 
 environment:
   sdk: ^3.8.1