mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-07 00:50:27 +00:00
refactor(windows): use bundled notification icon path directly
This commit is contained in:
1 parent
c4ae3330b8
commit
f254a82d9c
1 file changed
+17
-13
@@ -2,10 +2,9 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.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/libgopeed_boot.dart';
|
||||
@@ -57,18 +56,23 @@ class AppNotificationController extends AsyncNotifier<AppNotificationState> {
|
||||
String? windowsIconPath;
|
||||
try {
|
||||
if (Util.isWindows()) {
|
||||
// Windows reads the toast header icon through the registered IconUri.
|
||||
// Use a PNG in persistent storage so notification history can still
|
||||
// resolve it after the app exits or temporary files are cleaned up.
|
||||
final byteData = await rootBundle.load('assets/icon/icon_512.png');
|
||||
final supportDir = await getApplicationSupportDirectory();
|
||||
final file = File('${supportDir.path}/notification_icon.png');
|
||||
await file.parent.create(recursive: true);
|
||||
await file.writeAsBytes(
|
||||
byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes),
|
||||
flush: true,
|
||||
// Windows requires a file path for IconUri, so use the bundled PNG
|
||||
// beside the executable rather than copying it to another directory.
|
||||
final file = File(
|
||||
path.join(
|
||||
path.dirname(Platform.resolvedExecutable),
|
||||
'data',
|
||||
'flutter_assets',
|
||||
'assets',
|
||||
'icon',
|
||||
'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) {
|
||||
logger.w('prepare Windows notification icon failed', error, stackTrace);
|
||||
|
||||
Reference in new issue
Block a user