Skip to content

Commit

Permalink
feat: allow to override the mime source factory
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Mar 16, 2024
1 parent 5b729d8 commit 1db52f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'keys/service.dart';
import 'localization/app_localizations.g.dart';
import 'lock/provider.dart';
import 'logger.dart';
import 'mail/service.dart';
import 'models/async_mime_source_factory.dart';
import 'notification/service.dart';
import 'routes/provider.dart';
import 'routes/routes.dart';
Expand All @@ -29,12 +31,19 @@ class EnoughMailApp extends HookConsumerWidget {
const EnoughMailApp({
super.key,
required this.appName,
this.mimeSourceFactory =
const AsyncMimeSourceFactory(isOfflineModeSupported: false),
});

/// The name of the app
final String appName;

final AsyncMimeSourceFactory mimeSourceFactory;

@override
Widget build(BuildContext context, WidgetRef ref) {
EmailService.mimeSourceFactory = mimeSourceFactory;

useOnAppLifecycleStateChange((previous, current) {
logger.d('raw AppLifecycleState changed from $previous to $current');
ref.read(rawAppLifecycleStateProvider.notifier).state = current;
Expand Down
8 changes: 5 additions & 3 deletions lib/src/mail/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class EmailService {
/// Retrieves the singleton instance
static EmailService get instance => _instance;

static const _clientId = Id(name: 'Maily', version: '1.0');
final _mimeSourceFactory =
/// The used mime source factory
static AsyncMimeSourceFactory mimeSourceFactory =
const AsyncMimeSourceFactory(isOfflineModeSupported: false);

static const _clientId = Id(name: 'Maily', version: '1.0');

/// Creates a mime source for the given account
Future<AsyncMimeSource> createMimeSource({
required MailClient mailClient,
Expand All @@ -33,7 +35,7 @@ class EmailService {
} else {
await mailClient.selectMailbox(mailbox);
}
final source = _mimeSourceFactory.createMailboxMimeSource(
final source = mimeSourceFactory.createMailboxMimeSource(
mailClient,
mailbox,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/screens/compose_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
return;
}
}
if (context.mounted) {
if (mounted) {
context.pop();
}
final mailClient = _getMailClient();
Expand Down Expand Up @@ -807,7 +807,7 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
Future<void> _showSourceCode() async {
final mailClient = _getMailClient();
final mime = await _buildMimeMessage(mailClient);
if (context.mounted) {
if (mounted) {
unawaited(context.pushNamed(Routes.sourceCode, extra: mime));
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/screens/message_source_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,12 @@ class _MessageSourceScreenState extends ConsumerState<MessageSourceScreen>
//message.updateMime(mime);
final builder = MessageBuilder.prepareFromDraft(mime);
final data = ComposeData([message], builder, ComposeAction.newMessage);
if (context.mounted) {
if (mounted) {
unawaited(context.pushNamed(Routes.mailCompose, extra: data));
}
} else {
// move to mail details:
if (context.mounted) {
if (mounted) {
unawaited(context.pushNamed(Routes.mailDetails, extra: message));
}
}
Expand Down

0 comments on commit 1db52f8

Please sign in to comment.