mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
pass bytes around instead
This commit is contained in:
parent
fe0155edc7
commit
c713de3e79
5 changed files with 11 additions and 19 deletions
|
@ -198,7 +198,8 @@ void main() async {
|
|||
level: LogLevel.Info,
|
||||
);
|
||||
final lightZip = await rootBundle.load("assets/default_themes/light.zip");
|
||||
await ThemeService.instance.install(themeArchive: lightZip);
|
||||
await ThemeService.instance
|
||||
.install(themeArchiveData: lightZip.buffer.asUint8List());
|
||||
Logging.instance.log(
|
||||
"Installing default light theme... finished",
|
||||
level: LogLevel.Info,
|
||||
|
@ -210,7 +211,8 @@ void main() async {
|
|||
level: LogLevel.Info,
|
||||
);
|
||||
final darkZip = await rootBundle.load("assets/default_themes/dark.zip");
|
||||
await ThemeService.instance.install(themeArchive: darkZip);
|
||||
await ThemeService.instance
|
||||
.install(themeArchiveData: darkZip.buffer.asUint8List());
|
||||
Logging.instance.log(
|
||||
"Installing default dark theme... finished",
|
||||
level: LogLevel.Info,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -34,9 +33,7 @@ class _InstallThemeFromFileDialogState
|
|||
final timedFuture = Future<void>.delayed(const Duration(seconds: 2));
|
||||
final installFuture = File(controller.text).readAsBytes().then(
|
||||
(fileBytes) => ref.read(pThemeService).install(
|
||||
themeArchive: ByteData.view(
|
||||
fileBytes.buffer,
|
||||
),
|
||||
themeArchiveData: fileBytes,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class _StackThemeCardState extends ConsumerState<StackThemeCard> {
|
|||
themeMetaData: widget.data,
|
||||
);
|
||||
|
||||
await service.install(themeArchive: data);
|
||||
await service.install(themeArchiveData: data);
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:desktop_drop/desktop_drop.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -37,9 +35,7 @@ class _DesktopInstallThemeState extends ConsumerState<DesktopInstallTheme> {
|
|||
final timedFuture = Future<void>.delayed(const Duration(seconds: 2));
|
||||
final installFuture = _selectedFile!.readAsBytes().then(
|
||||
(fileBytes) => ref.read(pThemeService).install(
|
||||
themeArchive: ByteData.view(
|
||||
fileBytes.buffer,
|
||||
),
|
||||
themeArchiveData: fileBytes,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -28,11 +28,10 @@ class ThemeService {
|
|||
|
||||
void init(MainDB db) => _db ??= db;
|
||||
|
||||
Future<void> install({required ByteData themeArchive}) async {
|
||||
Future<void> install({required Uint8List themeArchiveData}) async {
|
||||
final themesDir = await StackFileSystem.applicationThemesDirectory();
|
||||
|
||||
final byteStream = InputStream(themeArchive);
|
||||
final archive = ZipDecoder().decodeBuffer(byteStream);
|
||||
final archive = ZipDecoder().decodeBytes(themeArchiveData);
|
||||
|
||||
final themeJsonFiles = archive.files.where((e) => e.name == "theme.json");
|
||||
|
||||
|
@ -138,7 +137,7 @@ class ThemeService {
|
|||
}
|
||||
}
|
||||
|
||||
Future<ByteData> fetchTheme({
|
||||
Future<Uint8List> fetchTheme({
|
||||
required StackThemeMetaData themeMetaData,
|
||||
}) async {
|
||||
try {
|
||||
|
@ -150,9 +149,7 @@ class ThemeService {
|
|||
// verify hash
|
||||
final digest = sha256.convert(bytes);
|
||||
if (digest.toString() == themeMetaData.sha256) {
|
||||
final result = ByteData.view(bytes.buffer);
|
||||
|
||||
return result;
|
||||
return bytes;
|
||||
} else {
|
||||
throw Exception(
|
||||
"Fetched theme archive sha256 hash ($digest) does not"
|
||||
|
|
Loading…
Reference in a new issue