Skip to content

Commit

Permalink
allow export of static backup
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbabeck committed Sep 27, 2023
1 parent 9e6dcbc commit 1aa81d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/bloc/account/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
return _credentialsManager.exportCredentials();
}

void exportStaticChannelBackup() async {
_log.v("exportStaticChannelBackup");
return _credentialsManager.exportStaticChannelBackup();
}

void recursiveFolderCopySync(String path1, String path2) {
_log.v("recursiveFolderCopySync: $path1, $path2");
Directory dir1 = Directory(path1);
Expand Down
27 changes: 27 additions & 0 deletions lib/bloc/account/credentials_manager.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'dart:io';

import 'package:breez_sdk/bridge_generated.dart';
import 'package:c_breez/services/injector.dart';
import 'package:c_breez/services/keychain.dart';
import 'package:c_breez/widgets/flushbar.dart';
import 'package:fimber/fimber.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';

class CredentialsManager {
final _log = FimberLog("CredentialsManager");
Expand Down Expand Up @@ -50,4 +54,27 @@ class CredentialsManager {
throw e.toString();
}
}

void exportStaticChannelBackup() async {
try {
const name = "static_backup";
final breezLib = ServiceInjector().breezSDK;

Directory tempDir = await getTemporaryDirectory();

tempDir = await tempDir.createTemp(name);
final staticBakcup =
await breezLib.staticBackup(request: StaticBackupRequest(workingDir: tempDir.path));
if (staticBakcup.backup != null) {
final backup = staticBakcup.backup!.join();
String filePath = '${tempDir.path}/$name.db';
File file = File(filePath);
await file.writeAsString(backup, flush: true);
final xFile = XFile(filePath);
Share.shareXFiles([xFile]);
}
} catch (e) {
rethrow;
}
}
}
10 changes: 10 additions & 0 deletions lib/routes/dev/developers_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import 'package:archive/archive_io.dart';
import 'package:c_breez/bloc/account/account_bloc.dart';
import 'package:c_breez/logger.dart';
import 'package:c_breez/routes/dev/command_line_interface.dart';
import 'package:c_breez/routes/dev/static_backup.dart';
import 'package:c_breez/routes/ui_test/ui_test_page.dart';
import 'package:c_breez/widgets/back_button.dart' as back_button;
import 'package:c_breez/widgets/flushbar.dart';
import 'package:c_breez/widgets/route.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -72,6 +74,8 @@ class DevelopersView extends StatelessWidget {
icon: Icons.share,
function: (_) => shareLog(),
),
Choice(
title: "Export static backup", icon: Icons.charging_station, function: _exportStaticBackup)
]
.map((choice) => PopupMenuItem<Choice>(
value: choice,
Expand Down Expand Up @@ -109,4 +113,10 @@ class DevelopersView extends StatelessWidget {
final zipFile = XFile(zipFilePath);
Share.shareXFiles([zipFile]);
}

void _exportStaticBackup(BuildContext context) async {
final accBloc = context.read<AccountBloc>();

accBloc.exportStaticChannelBackup();
}
}

0 comments on commit 1aa81d1

Please sign in to comment.