refactor some more

This commit is contained in:
Christien Rioux 2023-12-27 22:56:24 -05:00
parent 2adc958128
commit c516323e7d
91 changed files with 1237 additions and 748 deletions

View file

@ -4,7 +4,7 @@ import 'package:bloc/bloc.dart';
import '../../tools/tools.dart';
import '../init.dart';
import '../../veilid_support/veilid_support.dart';
import '../../packages/veilid_support/veilid_support.dart';
abstract class AsyncTableDBBackedCubit<State> extends Cubit<AsyncValue<State>>
with TableDBBacked<State> {

View file

@ -8,7 +8,7 @@ import 'package:intl/intl.dart';
import 'package:loggy/loggy.dart';
import '../old_to_refactor/pages/developer.dart';
import '../veilid_support/veilid_support.dart';
import '../../packages/veilid_support/veilid_support.dart';
import 'state_logger.dart';
String wrapWithLogColor(LogLevel? level, String text) {

View file

@ -1,46 +0,0 @@
import 'dart:typed_data';
import '../local_accounts/local_account.dart';
import '../init.dart';
import '../veilid_support/veilid_support.dart';
Future<Uint8List> encryptSecretToBytes(
{required SecretKey secret,
required CryptoKind cryptoKind,
EncryptionKeyType encryptionKeyType = EncryptionKeyType.none,
String encryptionKey = ''}) async {
final veilid = await eventualVeilid.future;
late final Uint8List secretBytes;
switch (encryptionKeyType) {
case EncryptionKeyType.none:
secretBytes = secret.decode();
case EncryptionKeyType.pin:
case EncryptionKeyType.password:
final cs = await veilid.getCryptoSystem(cryptoKind);
secretBytes =
await cs.encryptAeadWithPassword(secret.decode(), encryptionKey);
}
return secretBytes;
}
Future<SecretKey> decryptSecretFromBytes(
{required Uint8List secretBytes,
required CryptoKind cryptoKind,
EncryptionKeyType encryptionKeyType = EncryptionKeyType.none,
String encryptionKey = ''}) async {
final veilid = await eventualVeilid.future;
late final SecretKey secret;
switch (encryptionKeyType) {
case EncryptionKeyType.none:
secret = SecretKey.fromBytes(secretBytes);
case EncryptionKeyType.pin:
case EncryptionKeyType.password:
final cs = await veilid.getCryptoSystem(cryptoKind);
secret = SecretKey.fromBytes(
await cs.decryptAeadWithPassword(secretBytes, encryptionKey));
}
return secret;
}

View file

@ -5,6 +5,6 @@ export 'loggy.dart';
export 'phono_byte.dart';
export 'responsive.dart';
export 'scanner_error_widget.dart';
export 'secret_crypto.dart';
export 'state_logger.dart';
export 'widget_helpers.dart';
export 'window_control.dart';

View file

@ -0,0 +1,65 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
import '../../tools/responsive.dart';
export 'package:window_manager/window_manager.dart' show TitleBarStyle;
enum OrientationCapability {
normal,
portraitOnly,
landscapeOnly,
}
// Window Control
Future<void> initializeWindowControl() async {
if (isDesktop) {
await windowManager.ensureInitialized();
const windowOptions = WindowOptions(
size: Size(768, 1024),
//minimumSize: Size(480, 480),
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
);
await windowManager.waitUntilReadyToShow(windowOptions, () async {
await _doWindowSetup(TitleBarStyle.hidden, OrientationCapability.normal);
await windowManager.show();
await windowManager.focus();
});
}
}
Future<void> _doWindowSetup(TitleBarStyle titleBarStyle,
OrientationCapability orientationCapability) async {
if (isDesktop) {
await windowManager.setTitleBarStyle(titleBarStyle);
} else {
switch (orientationCapability) {
case OrientationCapability.normal:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
case OrientationCapability.portraitOnly:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
case OrientationCapability.landscapeOnly:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
}
}
Future<void> changeWindowSetup(TitleBarStyle titleBarStyle,
OrientationCapability orientationCapability) async {
await _doWindowSetup(titleBarStyle, orientationCapability);
}