fix: linux snap notification avatar

This commit is contained in:
Krille Fear 2022-01-28 17:53:13 +01:00
parent 12e9637ddc
commit 227869d84d

View File

@ -3,9 +3,10 @@ import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:desktop_notifications/desktop_notifications.dart'; import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:http/http.dart' as http;
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';
import 'package:universal_html/html.dart' as html; import 'package:universal_html/html.dart' as html;
import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/app_config.dart';
@ -45,14 +46,23 @@ extension LocalNotificationsExtension on MatrixState {
icon: icon.toString(), icon: icon.toString(),
); );
} else if (Platform.isLinux) { } else if (Platform.isLinux) {
final appIconUrl = room.avatar final appIconUrl = room.avatar?.getThumbnail(
?.getThumbnail( room.client,
room.client, width: 56,
width: 56, height: 56,
height: 56, );
) File appIconFile;
.toString(); if (appIconUrl != null) {
final appIconFile = await DefaultCacheManager().getSingleFile(appIconUrl); final tempDirectory = await getApplicationSupportDirectory();
final avatarDirectory =
await Directory('${tempDirectory.path}/notiavatars/').create();
appIconFile = File(
'${avatarDirectory.path}/${Uri.encodeComponent(appIconUrl.toString())}');
if (await appIconFile.exists() == false) {
final response = await http.get(appIconUrl);
await appIconFile.writeAsBytes(response.bodyBytes);
}
}
final notification = await linuxNotifications.notify( final notification = await linuxNotifications.notify(
title, title,
body: body, body: body,