mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 06:13:42 +00:00
fix(windows): persist PNG icon for download notifications
This commit is contained in:
1 parent
b991482617
commit
c4ae3330b8
1 file changed
+16
-6
@@ -10,6 +10,7 @@ import 'package:path_provider/path_provider.dart';
|
|||||||
import '../../core/common/task_event.dart';
|
import '../../core/common/task_event.dart';
|
||||||
import '../../core/libgopeed_boot.dart';
|
import '../../core/libgopeed_boot.dart';
|
||||||
import '../../l10n/l10n.dart';
|
import '../../l10n/l10n.dart';
|
||||||
|
import '../../util/log_util.dart';
|
||||||
import '../../util/util.dart';
|
import '../../util/util.dart';
|
||||||
import 'app_runtime_controller.dart';
|
import 'app_runtime_controller.dart';
|
||||||
|
|
||||||
@@ -56,13 +57,22 @@ class AppNotificationController extends AsyncNotifier<AppNotificationState> {
|
|||||||
String? windowsIconPath;
|
String? windowsIconPath;
|
||||||
try {
|
try {
|
||||||
if (Util.isWindows()) {
|
if (Util.isWindows()) {
|
||||||
final byteData = await rootBundle.load('assets/icon/icon.ico');
|
// Windows reads the toast header icon through the registered IconUri.
|
||||||
final tempDir = await getTemporaryDirectory();
|
// Use a PNG in persistent storage so notification history can still
|
||||||
final file = File('${tempDir.path}/notification_icon.ico');
|
// resolve it after the app exits or temporary files are cleaned up.
|
||||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
final byteData = await rootBundle.load('assets/icon/icon_512.png');
|
||||||
windowsIconPath = file.path;
|
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,
|
||||||
|
);
|
||||||
|
windowsIconPath = file.absolute.path;
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (error, stackTrace) {
|
||||||
|
logger.w('prepare Windows notification icon failed', error, stackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
final windows = WindowsInitializationSettings(
|
final windows = WindowsInitializationSettings(
|
||||||
appName: 'Gopeed',
|
appName: 'Gopeed',
|
||||||
|
|||||||
Reference in new issue
Block a user