mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,3 @@
|
||||
class Breakpoints {
|
||||
static const double mobile = 720;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
abstract final class ByteSizeFormatter {
|
||||
static const _units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
static String format(int bytes) {
|
||||
if (bytes <= 0) return '0 B';
|
||||
|
||||
var value = bytes.toDouble();
|
||||
var unitIndex = 0;
|
||||
while (value >= 1024 && unitIndex < _units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
// Bytes are whole values. Scaled binary units keep at most two decimal
|
||||
// places and omit trailing zeroes (for example: 1.5 MB, 1.25 MB, 2 MB).
|
||||
final formattedValue = unitIndex == 0 ? value.round().toString() : _trimFraction(value.toStringAsFixed(2));
|
||||
return '$formattedValue ${_units[unitIndex]}';
|
||||
}
|
||||
|
||||
static String _trimFraction(String value) {
|
||||
return value.replaceFirst(RegExp(r'0+$'), '').replaceFirst(RegExp(r'\.$'), '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'content_uri_resolver_stub.dart' if (dart.library.io) 'content_uri_resolver_io.dart' as implementation;
|
||||
|
||||
/// Resolves a platform content URI into a local temporary file.
|
||||
abstract final class ContentUriResolver {
|
||||
static Future<String> copyToCache(Uri uri) => implementation.copyToCache(uri);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:uri_content/uri_content.dart';
|
||||
|
||||
Future<String> copyToCache(Uri uri) async {
|
||||
if (uri.scheme != 'content') {
|
||||
throw ArgumentError.value(uri, 'uri', 'Expected an Android content URI');
|
||||
}
|
||||
if (!Platform.isAndroid) {
|
||||
throw UnsupportedError('content URIs are only supported on Android');
|
||||
}
|
||||
|
||||
final importDirectory = Directory(path.join((await getTemporaryDirectory()).path, 'torrent-imports'));
|
||||
await importDirectory.create(recursive: true);
|
||||
final output = File(path.join(importDirectory.path, 'gopeed-${DateTime.now().microsecondsSinceEpoch}.torrent'));
|
||||
final sink = output.openWrite();
|
||||
|
||||
try {
|
||||
await sink.addStream(UriContent().getContentStream(uri));
|
||||
await sink.close();
|
||||
} catch (error) {
|
||||
await sink.close();
|
||||
if (await output.exists()) await output.delete();
|
||||
rethrow;
|
||||
}
|
||||
|
||||
return output.path;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Future<String> copyToCache(Uri uri) {
|
||||
throw UnsupportedError('content URIs are not supported on this platform');
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'file_explorer_stub.dart' if (dart.library.io) 'file_explorer_native.dart' as implementation;
|
||||
|
||||
abstract final class FileExplorer {
|
||||
static Future<bool> open(String filePath) => implementation.open(filePath);
|
||||
|
||||
static Future<bool> reveal(String filePath) => implementation.reveal(filePath);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:open_dir/open_dir.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
Future<bool> open(String filePath) async {
|
||||
try {
|
||||
if (!await FileSystemEntity.isFile(filePath) && !await FileSystemEntity.isDirectory(filePath)) {
|
||||
return false;
|
||||
}
|
||||
final result = await OpenFilex.open(filePath);
|
||||
return result.type == ResultType.done;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> reveal(String filePath) async {
|
||||
try {
|
||||
if (!(Platform.isWindows || Platform.isMacOS || Platform.isLinux)) {
|
||||
return open(filePath);
|
||||
}
|
||||
|
||||
if (await FileSystemEntity.isFile(filePath)) {
|
||||
return await OpenDir().openNativeDir(
|
||||
path: path.dirname(filePath),
|
||||
highlightedFileName: path.basename(filePath),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
if (await FileSystemEntity.isDirectory(filePath)) {
|
||||
return await OpenDir().openNativeDir(path: filePath) ?? false;
|
||||
}
|
||||
|
||||
final parentPath = path.dirname(filePath);
|
||||
if (await FileSystemEntity.isDirectory(parentPath)) {
|
||||
return await OpenDir().openNativeDir(path: parentPath) ?? false;
|
||||
}
|
||||
return false;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Future<bool> open(String filePath) async => false;
|
||||
|
||||
Future<bool> reveal(String filePath) async => false;
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'tcp_port_checker_stub.dart' if (dart.library.io) 'tcp_port_checker_native.dart' as implementation;
|
||||
|
||||
/// Returns whether a TCP connection can be established to [host]:[port].
|
||||
///
|
||||
/// The settings page uses this before saving a changed API listen address,
|
||||
/// matching the legacy UI's occupied-port check. Unsupported platforms return
|
||||
/// false so validation never blocks configuration that cannot be probed locally.
|
||||
Future<bool> isTcpPortInUse(String host, int port) => implementation.isTcpPortInUse(host, port);
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
Future<bool> isTcpPortInUse(String host, int port) async {
|
||||
try {
|
||||
final socket = await Socket.connect(host, port, timeout: const Duration(seconds: 3));
|
||||
await socket.close();
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Future<bool> isTcpPortInUse(String host, int port) async => false;
|
||||
@@ -0,0 +1,3 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
String softWrapAnywhere(String value) => value.characters.join('\u200B');
|
||||
@@ -0,0 +1,28 @@
|
||||
class FormattedTransferRate {
|
||||
const FormattedTransferRate({required this.value, required this.unit});
|
||||
|
||||
final String value;
|
||||
final String unit;
|
||||
|
||||
String get text => '$value $unit';
|
||||
}
|
||||
|
||||
abstract final class TransferRateFormatter {
|
||||
static const _units = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s'];
|
||||
|
||||
static FormattedTransferRate format(int bytesPerSecond) {
|
||||
var value = bytesPerSecond < 0 ? 0.0 : bytesPerSecond.toDouble();
|
||||
var unitIndex = 0;
|
||||
while (value >= 1024 && unitIndex < _units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex += 1;
|
||||
}
|
||||
|
||||
final formattedValue = unitIndex == 0 ? value.round().toString() : _trimFraction(value.toStringAsFixed(2));
|
||||
return FormattedTransferRate(value: formattedValue, unit: _units[unitIndex]);
|
||||
}
|
||||
|
||||
static String _trimFraction(String value) {
|
||||
return value.replaceFirst(RegExp(r'0+$'), '').replaceFirst(RegExp(r'\.$'), '');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user