Fix #330 - Multiple file browser windows are opened. #331

Merged
dan merged 2 commits from sender_size into trunk 2022-01-21 21:42:41 +00:00
2 changed files with 22 additions and 6 deletions
Showing only changes of commit 748326e13f - Show all commits

View File

@ -13,6 +13,7 @@ class AppState extends ChangeNotifier {
int _hoveredIndex = -1;
int? _selectedIndex;
bool _unreadMessagesBelow = false;
bool _disableFilePicker = false;
void SetCwtchInit() {
cwtchInit = true;
@ -47,6 +48,12 @@ class AppState extends ChangeNotifier {
notifyListeners();
}
bool get disableFilePicker => _disableFilePicker;
set disableFilePicker(bool newVal) {
this._disableFilePicker = newVal;
notifyListeners();
}
// Never use this for message lookup - can be a non-indexed value
// e.g. -1
int get hoveredIndex => _hoveredIndex;

View File

@ -1,7 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:crypto/crypto.dart';
import 'package:cwtch/config.dart';
import 'package:cwtch/cwtch_icons_icons.dart';
import 'package:cwtch/models/appstate.dart';
import 'package:cwtch/models/chatmessage.dart';
@ -23,7 +22,6 @@ import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:path/path.dart' show basename;
import '../main.dart';
import '../settings.dart';
@ -89,11 +87,13 @@ class _MessageViewState extends State<MessageView> {
if (showFileSharing) {
appBarButtons.add(IconButton(
splashRadius: Material.defaultSplashRadius / 2,
icon: Icon(Icons.attach_file, size: 24),
icon: Icon(Icons.attach_file, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor),
tooltip: AppLocalizations.of(context)!.tooltipSendFile,
onPressed: () {
_showFilePicker(context);
},
onPressed: Provider.of<AppState>(context).disableFilePicker
Review

this is an unfun usage patern that might get missed on reuse. any way we can bundle it in a build widget that handles this and can be reused easily in 1 line?

this is an unfun usage patern that might get missed on reuse. any way we can bundle it in a build widget that handles this and can be reused easily in 1 line?
Review

The correct solution here is to fix file picker API properly modal.

Currently that behaviour is only supported on windows.

The correct solution here is to fix file picker API properly modal. Currently that behaviour is only supported on windows.
? null
: () {
_showFilePicker(context);
},
));
}
appBarButtons.add(IconButton(
@ -392,7 +392,16 @@ class _MessageViewState extends State<MessageView> {
void _showFilePicker(BuildContext ctx) async {
imagePreview = null;
// only allow one file picker at a time
// note: ideally we would destroy file picker when leaving a conversation
// but we don't currently have that option.
// we need to store AppState in a variable because ctx might be destroyed
// while awaiting for pickFiles.
var appstate = Provider.of<AppState>(ctx, listen: false);
appstate.disableFilePicker = true;
FilePickerResult? result = await FilePicker.platform.pickFiles();
appstate.disableFilePicker = false;
if (result != null) {
File file = File(result.files.first.path);
// We have a maximum number of bytes we can represent in terms of