Skip to content

Commit

Permalink
[Export] Initial share based implementation
Browse files Browse the repository at this point in the history
Starting to work on #7
  • Loading branch information
gargakshit committed Feb 9, 2021
1 parent a6eeee8 commit 52cfdb9
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 27 deletions.
Binary file added debugInfo/aab/aab.zip
Binary file not shown.
Binary file added debugInfo/aab/arm.symbols
Binary file not shown.
Binary file added debugInfo/aab/arm64.symbols
Binary file not shown.
Binary file added debugInfo/aab/x64.symbols
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/models/export.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum ExportType {
SHARE_UNENCRYPTED,
SAVE_TO_STORAGE_UNENCRYPTED,
}
3 changes: 2 additions & 1 deletion lib/redux/appstate.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/screens/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:autofill_service/autofill_service.dart';
import 'package:ez_localization/ez_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:passwd/widgets/export.dart';

import '../../utils/loggers.dart';
import '../../widgets/sync/settings_sync_widget.dart';
Expand All @@ -17,15 +18,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
final settingsItems = <Widget>[
if (Platform.isAndroid)
ListTile(
title: Text('Activate autofill service'),
title: Text('Activate autofill service'), // TODO: localize
onTap: () async {
// TODO: abstract autofill
final response = await AutofillService().requestSetAutofillService();
Loggers.mainLogger.info(
'Autofill requestSetAutofillService: ${response}',
);
},
),
SettingsSyncWidget(),
ExportSettingsWidget(),
];

@override
Expand Down
48 changes: 48 additions & 0 deletions lib/services/export/export_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'dart:convert';
import 'dart:io';

import 'package:injectable/injectable.dart';
import 'package:path/path.dart';
import 'package:share/share.dart';

import '../../models/export.dart';
import '../database/database_service.dart';
import '../locator.dart';
import '../path/path_service.dart';
import 'export_service.dart';

@Injectable(as: ExportService)
class ExportImpl implements ExportService {
final pathService = locator<PathService>();
final databaseService = locator<DatabaseService>();

@override
Future export(ExportType type) async {
switch (type) {
case ExportType.SHARE_UNENCRYPTED:
await share_unencrypted();
break;

case ExportType.SAVE_TO_STORAGE_UNENCRYPTED:
throw UnimplementedError();
}
}

Future share_unencrypted() async {
if (!Platform.isAndroid && !Platform.isIOS) {
throw UnsupportedError('Share is only available on mobile devices');
}

final tempDir = await pathService.getTempDir();
final tempDbPath = join(tempDir.path, 'passwd_db.json');
final file = File(tempDbPath);

await file.writeAsString(json.encode(databaseService.entries));
await Share.shareFiles(
[tempDbPath],
mimeTypes: ['text/json', 'application/json'],
);

await file.delete();
}
}
5 changes: 5 additions & 0 deletions lib/services/export/export_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../../models/export.dart';

abstract class ExportService {
Future export(ExportType type);
}
3 changes: 3 additions & 0 deletions lib/services/locator.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/services/path/path_path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class PathPathProvider implements PathService {
return (await getApplicationDocumentsDirectory());
}

@override
Future<Directory> getTempDir() async {
return (await getTemporaryDirectory());
}

@override
Future checkCacheDir() async {
if (!Platform.isAndroid || !Platform.isIOS) {
Expand Down
1 change: 1 addition & 0 deletions lib/services/path/path_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import 'dart:io';
abstract class PathService {
Future<Directory> getDocDir();
Future checkCacheDir();
Future<Directory> getTempDir();
}
58 changes: 58 additions & 0 deletions lib/widgets/export.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'dart:io';

import 'package:ez_localization/ez_localization.dart';
import 'package:flutter/material.dart';

import '../models/export.dart';
import '../services/export/export_service.dart';
import '../services/locator.dart';
import '../utils/loggers.dart';

class ExportSettingsWidget extends StatelessWidget {
Future<void> export(BuildContext context) async {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'), // TODO: localize
content:
Text('The database export will be unencrypted'), // TODO: localize
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(context.getString('no')),
),
TextButton(
onPressed: () async {
Loggers.mainLogger.info(
'Export Type SHARE_UNENCRYPTED',
);
Navigator.of(context).pop();
await locator<ExportService>()
.export(ExportType.SHARE_UNENCRYPTED);
},
child: Text(context.getString('yes')),
),
],
),
);
}

@override
Widget build(BuildContext context) {
if (Platform.isAndroid || Platform.isIOS) {
return ListTile(
title: Text('Export'), // TODO: localize
onTap: () async {
Loggers.mainLogger.info(
'Export exportService requested',
);
await export(context);
},
);
}

return Container();
}
}
41 changes: 17 additions & 24 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.0"
version: "12.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.39.17"
version: "0.40.6"
animations:
dependency: "direct main"
description:
Expand Down Expand Up @@ -114,14 +114,14 @@ packages:
name: build
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.6.2"
build_config:
dependency: transitive
description:
name: build_config
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.5"
build_daemon:
dependency: transitive
description:
Expand All @@ -135,21 +135,21 @@ packages:
name: build_resolvers
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.11"
version: "1.5.3"
build_runner:
dependency: "direct dev"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.2"
version: "1.11.1"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
version: "6.1.7"
built_collection:
dependency: transitive
description:
Expand Down Expand Up @@ -241,13 +241,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.1"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.2"
dart_otp:
dependency: "direct main"
description:
Expand All @@ -261,7 +254,7 @@ packages:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.6"
version: "1.3.10"
desktop_window:
dependency: "direct main"
description:
Expand Down Expand Up @@ -393,7 +386,7 @@ packages:
name: functional_data_generator
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.4"
version: "0.3.7"
get_it:
dependency: "direct main"
description:
Expand Down Expand Up @@ -422,13 +415,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+4"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -470,7 +456,7 @@ packages:
name: injectable_generator
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.0.6"
intl:
dependency: transitive
description:
Expand Down Expand Up @@ -744,6 +730,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.24.1"
share:
dependency: "direct main"
description:
name: share
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.5+4"
shared_preferences:
dependency: "direct main"
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
provider: ^4.3.2+2
provider_for_redux: ^1.1.3
responsive_builder: ^0.3.0
share: ^0.6.5+4
shared_preferences: ^0.5.12+4
supercharged: ^1.11.1
touch_bar: ^0.0.1-alpha.1
Expand All @@ -55,7 +56,7 @@ dev_dependencies:
sdk: flutter
build_runner: ^1.10.2
flutter_launcher_icons: ^0.8.1
functional_data_generator: ^0.3.4
functional_data_generator: ^0.3.7
injectable_generator: ^1.0.5
pedantic: ^1.9.2

Expand Down

0 comments on commit 52cfdb9

Please sign in to comment.