From 5984137bdcaa3456c23db922719d7a09e27557d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCttler?= Date: Wed, 22 Apr 2026 10:52:45 +0200 Subject: [PATCH] refactor: use open_filex instead of open_file with xdg-open workaround - Replace open_file + manual xdg-open with open_filex (maintained fork) - open_filex has better Linux support built-in - Removes platform-specific code, cleaner implementation Co-authored-by: Qwen-Coder --- lib/ui/screens/compose_screen.dart | 17 ++--------------- lib/ui/screens/email_detail_screen.dart | 18 ++---------------- pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/lib/ui/screens/compose_screen.dart b/lib/ui/screens/compose_screen.dart index b0faa54..0a48d2d 100644 --- a/lib/ui/screens/compose_screen.dart +++ b/lib/ui/screens/compose_screen.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:mime/mime.dart'; -import 'package:open_file/open_file.dart'; +import 'package:open_filex/open_filex.dart'; import '../../core/models/account.dart'; import '../../core/models/email.dart'; @@ -187,20 +187,7 @@ class _ComposeScreenState extends ConsumerState { setState(() => _opening = true); try { final path = _attachments[index].path; - - // On Linux, OpenFile.open may fail with "file type not supported". - // Use xdg-open directly for better compatibility. - if (Platform.isLinux) { - final result = await Process.run('xdg-open', [path]); - if (result.exitCode != 0 && mounted) { - throw Exception( - 'xdg-open failed: ${result.stderr}\n' - 'File path: $path', - ); - } - } else { - await OpenFile.open(path); - } + await OpenFilex.open(path); } catch (e) { if (!mounted) return; ScaffoldMessenger.of(context).showSnackBar( diff --git a/lib/ui/screens/email_detail_screen.dart b/lib/ui/screens/email_detail_screen.dart index 53a27e2..9faa2fa 100644 --- a/lib/ui/screens/email_detail_screen.dart +++ b/lib/ui/screens/email_detail_screen.dart @@ -1,11 +1,10 @@ import 'dart:async'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; +import 'package:open_filex/open_filex.dart'; import '../../core/models/email.dart'; import '../../core/utils/format_utils.dart'; @@ -162,20 +161,7 @@ class _EmailDetailScreenState extends ConsumerState { final path = await ref .read(emailRepositoryProvider) .downloadAttachment(widget.emailId, att); - - // On Linux, OpenFile.open may fail with "file type not supported". - // Use xdg-open directly for better compatibility. - if (Platform.isLinux) { - final result = await Process.run('xdg-open', [path]); - if (result.exitCode != 0 && mounted) { - throw Exception( - 'xdg-open failed: ${result.stderr}\n' - 'File saved to: $path', - ); - } - } else { - await OpenFile.open(path); - } + await OpenFilex.open(path); } catch (e) { if (!mounted) return; ScaffoldMessenger.of(context).showSnackBar( diff --git a/pubspec.yaml b/pubspec.yaml index 77ae76f..3ca7c32 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,7 +34,7 @@ dependencies: # File picking (compose attachments) and opening downloaded attachments file_picker: ^8.0.0 - open_file: ^3.3.2 + open_filex: ^4.6.0 mime: ^2.0.0 dev_dependencies: