Merge pull request 'Fix #330 - Multiple file browser windows are opened.' (#331) from sender_size into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #331
This commit is contained in:
commit
598251a624
|
@ -13,6 +13,7 @@ class AppState extends ChangeNotifier {
|
||||||
int _hoveredIndex = -1;
|
int _hoveredIndex = -1;
|
||||||
int? _selectedIndex;
|
int? _selectedIndex;
|
||||||
bool _unreadMessagesBelow = false;
|
bool _unreadMessagesBelow = false;
|
||||||
|
bool _disableFilePicker = false;
|
||||||
|
|
||||||
void SetCwtchInit() {
|
void SetCwtchInit() {
|
||||||
cwtchInit = true;
|
cwtchInit = true;
|
||||||
|
@ -47,6 +48,12 @@ class AppState extends ChangeNotifier {
|
||||||
notifyListeners();
|
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
|
// Never use this for message lookup - can be a non-indexed value
|
||||||
// e.g. -1
|
// e.g. -1
|
||||||
int get hoveredIndex => _hoveredIndex;
|
int get hoveredIndex => _hoveredIndex;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:cwtch/config.dart';
|
|
||||||
import 'package:cwtch/cwtch_icons_icons.dart';
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
||||||
import 'package:cwtch/models/appstate.dart';
|
import 'package:cwtch/models/appstate.dart';
|
||||||
import 'package:cwtch/models/chatmessage.dart';
|
import 'package:cwtch/models/chatmessage.dart';
|
||||||
|
@ -23,7 +22,6 @@ import 'package:flutter/services.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||||
import 'package:path/path.dart' show basename;
|
|
||||||
|
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
import '../settings.dart';
|
import '../settings.dart';
|
||||||
|
@ -89,11 +87,13 @@ class _MessageViewState extends State<MessageView> {
|
||||||
if (showFileSharing) {
|
if (showFileSharing) {
|
||||||
appBarButtons.add(IconButton(
|
appBarButtons.add(IconButton(
|
||||||
splashRadius: Material.defaultSplashRadius / 2,
|
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,
|
tooltip: AppLocalizations.of(context)!.tooltipSendFile,
|
||||||
onPressed: () {
|
onPressed: Provider.of<AppState>(context).disableFilePicker
|
||||||
_showFilePicker(context);
|
? null
|
||||||
},
|
: () {
|
||||||
|
_showFilePicker(context);
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
appBarButtons.add(IconButton(
|
appBarButtons.add(IconButton(
|
||||||
|
@ -392,9 +392,19 @@ class _MessageViewState extends State<MessageView> {
|
||||||
|
|
||||||
void _showFilePicker(BuildContext ctx) async {
|
void _showFilePicker(BuildContext ctx) async {
|
||||||
imagePreview = null;
|
imagePreview = null;
|
||||||
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
|
||||||
if (result != null) {
|
// only allow one file picker at a time
|
||||||
File file = File(result.files.first.path);
|
// 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;
|
||||||
|
// currently lockParentWindow only works on Windows...
|
||||||
|
FilePickerResult? result = await FilePicker.platform.pickFiles(lockParentWindow: true);
|
||||||
|
appstate.disableFilePicker = false;
|
||||||
|
if (result != null && result.files.first.path != null) {
|
||||||
|
File file = File(result.files.first.path!);
|
||||||
// We have a maximum number of bytes we can represent in terms of
|
// We have a maximum number of bytes we can represent in terms of
|
||||||
// a manifest (see : https://git.openprivacy.ca/cwtch.im/cwtch/src/branch/master/protocol/files/manifest.go#L25)
|
// a manifest (see : https://git.openprivacy.ca/cwtch.im/cwtch/src/branch/master/protocol/files/manifest.go#L25)
|
||||||
if (file.lengthSync() <= 10737418240) {
|
if (file.lengthSync() <= 10737418240) {
|
||||||
|
|
|
@ -112,14 +112,14 @@ packages:
|
||||||
name: file_picker
|
name: file_picker
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.1"
|
version: "4.3.2"
|
||||||
file_picker_desktop:
|
file_picker_desktop:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: file_picker_desktop
|
name: file_picker_desktop
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
|
@ -41,7 +41,7 @@ dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
scrollable_positioned_list: ^0.2.0-nullsafety.0
|
scrollable_positioned_list: ^0.2.0-nullsafety.0
|
||||||
file_picker: ^4.0.1
|
file_picker: ^4.3.2
|
||||||
file_picker_desktop: ^1.1.0
|
file_picker_desktop: ^1.1.0
|
||||||
url_launcher: ^6.0.12
|
url_launcher: ^6.0.12
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue