mirror of
https://github.com/krille-chan/fluffychat
synced 2024-10-05 15:12:44 +00:00
fix: desktop drop of HTTP content on linux
Signed-off-by: The one with the braid <the-one@with-the-braid.cf>
This commit is contained in:
parent
464206b581
commit
4b1734fb45
4 changed files with 64 additions and 5 deletions
|
@ -1,12 +1,14 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:desktop_drop/desktop_drop.dart';
|
||||
import 'package:flutter_app_lock/flutter_app_lock.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/utils/client_manager.dart';
|
||||
import 'package:fluffychat/utils/desktop_drop_downloader.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'config/setting_keys.dart';
|
||||
import 'utils/background_push.dart';
|
||||
|
@ -65,6 +67,9 @@ Future<void> startGui(List<Client> clients) async {
|
|||
}
|
||||
}
|
||||
|
||||
DesktopDropPlugin.onUnsupportedUriHandler =
|
||||
DesktopDropDownloader.unsupportedUriCallback;
|
||||
|
||||
// Start rendering the Flutter app and wrap it in an Applock.
|
||||
// We do this only for mobile applications as we saw routing
|
||||
// problems on other platforms if we wrap it always.
|
||||
|
|
48
lib/utils/desktop_drop_downloader.dart
Normal file
48
lib/utils/desktop_drop_downloader.dart
Normal file
|
@ -0,0 +1,48 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
abstract class DesktopDropDownloader {
|
||||
const DesktopDropDownloader._();
|
||||
|
||||
static Future<String?> unsupportedUriCallback(String url) async {
|
||||
if (kIsWeb) return null;
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri == null) return null;
|
||||
|
||||
if (!['http', 'https'].contains(uri.scheme)) return null;
|
||||
|
||||
Response response;
|
||||
|
||||
try {
|
||||
response = await get(uri);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Directory tmp;
|
||||
|
||||
// that's likely failing on many distros but future proof for upcoming
|
||||
// implementations
|
||||
try {
|
||||
tmp = await getTemporaryDirectory();
|
||||
} catch (_) {
|
||||
tmp =
|
||||
await getDownloadsDirectory() ?? await getApplicationCacheDirectory();
|
||||
}
|
||||
|
||||
try {
|
||||
await tmp.create(recursive: true);
|
||||
final file =
|
||||
File('${tmp.path}/desktop_drop_example/${uri.path.split('/').last}');
|
||||
await file.create(recursive: true);
|
||||
await file.writeAsBytes(response.bodyBytes);
|
||||
return file.path;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
11
pubspec.lock
11
pubspec.lock
|
@ -284,11 +284,12 @@ packages:
|
|||
desktop_drop:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: desktop_drop
|
||||
sha256: "4ca4d960f4b11c032e9adfd2a0a8ac615bc3fddb4cbe73dcf840dd8077582186"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.1"
|
||||
path: "packages/desktop_drop"
|
||||
ref: "braid/unsupported-uri-scheme-callback"
|
||||
resolved-ref: cbcea137c4f8209e2d229335278d06e16390f974
|
||||
url: "https://github.com/TheOneWithTheBraid/flutter-plugins.git"
|
||||
source: git
|
||||
version: "0.4.3"
|
||||
desktop_lifecycle:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -148,6 +148,11 @@ msix_config:
|
|||
install_certificate: false
|
||||
|
||||
dependency_overrides:
|
||||
desktop_drop:
|
||||
git:
|
||||
url: https://github.com/TheOneWithTheBraid/flutter-plugins.git
|
||||
path: packages/desktop_drop
|
||||
ref: braid/unsupported-uri-scheme-callback
|
||||
geolocator_android:
|
||||
hosted:
|
||||
name: geolocator_android
|
||||
|
|
Loading…
Reference in a new issue