feat: show real download progress in the files sidebar
- the download dialog starts from the size fs/stat reported, so the bar is determinate even when the response has no Content-Length (the relay forwards the body chunked); the server's own total wins when it has one - the line reads "512.0 KB / 20.0 MB (2.5%)": below 10% one decimal shows that the transfer is moving - bump to 0.5.4
This commit is contained in:
1 parent
511c3b006b
commit
545778c6f3
4 files changed
+37
-6
No files matched your search
@@ -5,6 +5,16 @@
|
||||
|
||||
---
|
||||
|
||||
## 0.5.4 文件下载进度(分支 `flutter`)
|
||||
|
||||
| 项 | 结果 |
|
||||
| --- | --- |
|
||||
| 进度 | 下载对话框的进度条改为确定进度:用 `fs/stat` 取到的文件大小当总量,服务器给出 `Content-Length` 时以服务器为准;显示「已下载 / 总大小 (百分比)」。Relay 把响应体按 chunked 转发、不带 `Content-Length` 时也能看到百分比 |
|
||||
| 取消 | 取消仍然中断请求并丢弃已下载的数据;完全没有大小信息时保持不确定进度条,并显示已下载字节数 |
|
||||
| 版本 | **0.5.4(code 504)** |
|
||||
|
||||
---
|
||||
|
||||
## 0.5.3 英文为源、按范围选择文本(分支 `flutter`)
|
||||
|
||||
| 项 | 结果 |
|
||||
|
||||
@@ -5,7 +5,7 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
|
||||
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
||||
Flutter to compare mobile UI maturity.
|
||||
|
||||
Status: 0.5.3 — servers (passwordless / password login, HTTP/HTTPS and
|
||||
Status: 0.5.4 — servers (passwordless / password login, HTTP/HTTPS and
|
||||
SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link
|
||||
over the OpenChamber private relay with end-to-end encryption; the pairing
|
||||
link is pasted or scanned with the camera), session list with search and live
|
||||
|
||||
@@ -93,6 +93,11 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
bool _previewLoading = false;
|
||||
String? _previewError;
|
||||
Uint8List? _previewBytes;
|
||||
|
||||
/// The file's size from `fs/stat`, even when too large to preview: the
|
||||
/// download dialog shows a determinate bar against it when the response
|
||||
/// carries no Content-Length (the relay forwards bodies chunked).
|
||||
int? _previewSize;
|
||||
String? _previewText;
|
||||
bool _previewBinary = false;
|
||||
bool _previewImage = false;
|
||||
@@ -231,6 +236,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
_previewLoading = true;
|
||||
_previewError = null;
|
||||
_previewBytes = null;
|
||||
_previewSize = null;
|
||||
_previewText = null;
|
||||
_previewBinary = false;
|
||||
_previewImage = false;
|
||||
@@ -240,6 +246,9 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
if (client == null) return;
|
||||
try {
|
||||
final stat = await client.fsStat(entry.path, directory: _root);
|
||||
if (stat != null && stat.size > 0 && mounted) {
|
||||
setState(() => _previewSize = stat.size);
|
||||
}
|
||||
if (stat != null && stat.size > 2 * 1024 * 1024) {
|
||||
if (!mounted || _previewPath != entry.path) return;
|
||||
setState(() {
|
||||
@@ -305,6 +314,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
barrierDismissible: false,
|
||||
builder: (_) => _DownloadDialog(
|
||||
name: _previewName,
|
||||
expectedSize: _previewSize,
|
||||
start: (onProgress, cancel) => client.downloadFile(path,
|
||||
directory: _root, onProgress: onProgress, cancel: cancel),
|
||||
),
|
||||
@@ -941,11 +951,16 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
/// the dialog closes with no bytes, so nothing is saved.
|
||||
class _DownloadDialog extends StatefulWidget {
|
||||
final String name;
|
||||
|
||||
/// The file's size from `fs/stat`; the progress bar is determinate against
|
||||
/// it from the first byte when the response has no Content-Length.
|
||||
final int? expectedSize;
|
||||
final Future<Uint8List> Function(
|
||||
void Function(int received, int? total) onProgress,
|
||||
CancelToken cancel) start;
|
||||
|
||||
const _DownloadDialog({required this.name, required this.start});
|
||||
const _DownloadDialog(
|
||||
{required this.name, this.expectedSize, required this.start});
|
||||
|
||||
@override
|
||||
State<_DownloadDialog> createState() => _DownloadDialogState();
|
||||
@@ -962,6 +977,7 @@ class _DownloadDialogState extends State<_DownloadDialog> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_total = (widget.expectedSize ?? 0) > 0 ? widget.expectedSize : null;
|
||||
_run();
|
||||
}
|
||||
|
||||
@@ -969,14 +985,17 @@ class _DownloadDialogState extends State<_DownloadDialog> {
|
||||
try {
|
||||
final bytes = await widget.start((received, total) {
|
||||
if (!mounted) return;
|
||||
// The server's own total is more accurate than the stat we started
|
||||
// with; keep the latter when the response is chunked.
|
||||
if (total != null) _total = total;
|
||||
// Chunks arrive every few dozen KB; repaint a few times a second at
|
||||
// most, and always on the last one.
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
if (total != null && received < total && now - _lastPaint < 80) return;
|
||||
final known = _total;
|
||||
if (known != null && received < known && now - _lastPaint < 80) return;
|
||||
_lastPaint = now;
|
||||
setState(() {
|
||||
_received = received;
|
||||
_total = total;
|
||||
});
|
||||
}, _cancel);
|
||||
if (mounted) Navigator.of(context).pop(bytes);
|
||||
@@ -1020,7 +1039,9 @@ class _DownloadDialogState extends State<_DownloadDialog> {
|
||||
? trArgs('{0} / {1} ({2}%)', [
|
||||
_size(_received),
|
||||
_size(total),
|
||||
(fraction! * 100).toStringAsFixed(0),
|
||||
// Below 10% one decimal says the transfer is moving;
|
||||
// whole numbers are enough above it.
|
||||
(fraction! * 100).toStringAsFixed(fraction < 0.1 ? 1 : 0),
|
||||
])
|
||||
: trArgs('Downloaded {0}', [_size(_received)]),
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor),
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ name: openchamber
|
||||
description: "A lightweight OpenChamber client for phones."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.5.3+503
|
||||
version: 0.5.4+504
|
||||
|
||||
environment:
|
||||
sdk: ^3.14.0
|
||||
|
||||
Reference in new issue
Block a user