11import 'dart:async' ;
22import 'dart:convert' ;
33import 'dart:io' ;
4- import 'dart:typed_data' ;
54
65import 'package:flutter/material.dart' ;
76import 'package:flutter_riverpod/flutter_riverpod.dart' ;
87import 'package:http/http.dart' as http;
9- import 'package:jovial_misc/io_utils.dart' ;
10- import 'package:jovial_svg/src/compact_noui.dart' ;
11- import 'package:jovial_svg/src/svg_parser.dart' ;
128import 'package:open_authenticator/model/settings/cache_totp_pictures.dart' ;
139import 'package:open_authenticator/model/totp/decrypted.dart' ;
1410import 'package:open_authenticator/model/totp/repository.dart' ;
1511import 'package:open_authenticator/model/totp/totp.dart' ;
1612import 'package:open_authenticator/utils/image_type.dart' ;
13+ import 'package:open_authenticator/utils/jovial_svg.dart' ;
1714import 'package:open_authenticator/utils/utils.dart' ;
1815import 'package:path/path.dart' ;
1916import 'package:path_provider/path_provider.dart' ;
@@ -46,7 +43,7 @@ class TotpImageCacheManager extends AutoDisposeAsyncNotifier<Map<String, CacheOb
4643 CacheObject newCacheObject = entry.value.copyWith (legacy: false );
4744 if (entry.value.imageType == ImageType .svg) {
4845 File ? cachedImage = (await cached.getCachedImage (entry.key, entry.value.url))? .$1;
49- if (cachedImage != null && cachedImage.existsSync () && (await _svgToSi (cachedImage.readAsStringSync (), cachedImage))) {
46+ if (cachedImage != null && cachedImage.existsSync () && (await JovialSvgUtils . svgToSi (cachedImage.readAsStringSync (), cachedImage))) {
5047 newCacheObject = entry.value.copyWith (imageType: ImageType .si);
5148 }
5249 }
@@ -87,7 +84,7 @@ class TotpImageCacheManager extends AutoDisposeAsyncNotifier<Map<String, CacheOb
8784 ImageType imageType;
8885 if (imageUrl.endsWith ('.svg' )) {
8986 imageType = ImageType .svg;
90- if (await _svgToSi (response.body, file)) {
87+ if (await JovialSvgUtils . svgToSi (response.body, file)) {
9188 imageType = ImageType .si;
9289 }
9390 } else {
@@ -107,23 +104,6 @@ class TotpImageCacheManager extends AutoDisposeAsyncNotifier<Map<String, CacheOb
107104 }
108105 }
109106
110- /// Compiles a SVG string into an SI file.
111- Future <bool > _svgToSi (String svg, File destinationFile) async {
112- IOSink ioSink = destinationFile.openWrite ();
113- try {
114- DataOutputSink outputSink = DataOutputSink (ioSink, Endian .big);
115- SICompactBuilderNoUI siCompactBuilder = SICompactBuilderNoUI (bigFloats: false , warn: (_) {});
116- StringSvgParser (svg, [], siCompactBuilder, warn: (_) {}).parse ();
117- siCompactBuilder.si.writeToFile (outputSink);
118- return true ;
119- } catch (ex, stacktrace) {
120- handleException (ex, stacktrace);
121- } finally {
122- await ioSink.close ();
123- }
124- return false ;
125- }
126-
127107 /// Deletes the cached image, if possible.
128108 Future <void > deleteCachedImage (String uuid) async {
129109 Map <String , CacheObject > cached = Map .from (await future);
0 commit comments