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