refactor(windows): use bundled notification icon path directly

This commit is contained in:
Levi committed 2026-09-10 23:07:14 +08:00
1 parent c4ae3330b8
commit f254a82d9c
1 file changed
+17 -13
@@ -2,10 +2,9 @@ import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path/path.dart' as path;
import '../../core/common/task_event.dart'; import '../../core/common/task_event.dart';
import '../../core/libgopeed_boot.dart'; import '../../core/libgopeed_boot.dart';
@@ -57,18 +56,23 @@ class AppNotificationController extends AsyncNotifier<AppNotificationState> {
String? windowsIconPath; String? windowsIconPath;
try { try {
if (Util.isWindows()) { if (Util.isWindows()) {
// Windows reads the toast header icon through the registered IconUri. // Windows requires a file path for IconUri, so use the bundled PNG
// Use a PNG in persistent storage so notification history can still // beside the executable rather than copying it to another directory.
// resolve it after the app exits or temporary files are cleaned up. final file = File(
final byteData = await rootBundle.load('assets/icon/icon_512.png'); path.join(
final supportDir = await getApplicationSupportDirectory(); path.dirname(Platform.resolvedExecutable),
final file = File('${supportDir.path}/notification_icon.png'); 'data',
await file.parent.create(recursive: true); 'flutter_assets',
await file.writeAsBytes( 'assets',
byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes), 'icon',
flush: true, 'icon_512.png',
),
); );
windowsIconPath = file.absolute.path; if (await file.exists()) {
windowsIconPath = file.absolute.path;
} else {
logger.w('Windows notification icon not found: ${file.path}');
}
} }
} catch (error, stackTrace) { } catch (error, stackTrace) {
logger.w('prepare Windows notification icon failed', error, stackTrace); logger.w('prepare Windows notification icon failed', error, stackTrace);