Rework file transfers

This commit is contained in:
crschnick 2024-05-06 03:04:30 +00:00
parent 8d6eb1051c
commit 4c7f91fec9
6 changed files with 21 additions and 20 deletions

View file

@ -43,7 +43,6 @@ dependencies {
api 'info.picocli:picocli:4.7.5'
api 'org.kohsuke:github-api:1.321'
api 'io.sentry:sentry:7.8.0'
api 'org.ocpsoft.prettytime:prettytime:5.0.7.Final'
api 'commons-io:commons-io:2.16.1'
api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "2.17.0"
api group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: "2.17.0"

View file

@ -1,5 +1,6 @@
package io.xpipe.app.browser;
import atlantafx.base.controls.Spacer;
import io.xpipe.app.browser.file.BrowserContextMenu;
import io.xpipe.app.browser.file.BrowserFileListCompEntry;
import io.xpipe.app.browser.fs.OpenFileSystemModel;
@ -11,16 +12,16 @@ import io.xpipe.app.fxcomps.augment.ContextMenuAugment;
import io.xpipe.app.fxcomps.impl.LabelComp;
import io.xpipe.app.fxcomps.util.BindingsHelper;
import io.xpipe.app.util.HumanReadableFormat;
import javafx.beans.binding.Bindings;
import javafx.scene.control.ToolBar;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Region;
import atlantafx.base.controls.Spacer;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
@Value
@EqualsAndHashCode(callSuper = true)
public class BrowserStatusBarComp extends SimpleComp {
@ -56,7 +57,9 @@ public class BrowserStatusBarComp extends SimpleComp {
var transferred = HumanReadableFormat.progressByteCount(p.getTransferred());
var all = HumanReadableFormat.byteCount(p.getTotal());
var name = (p.getName() != null ? " @ " + p.getName() + " " : "");
return transferred + " / " + all + name;
var time = p.getTotal() > 50_000_000 && p.elapsedTime().compareTo(Duration.of(200, ChronoUnit.MILLIS)) > 0 ? " | "
+ HumanReadableFormat.duration(p.expectedTimeRemaining()) : " | ...";
return transferred + " / " + all + name + time;
}
});
var progressComp = new LabelComp(text).styleClass("progress");

View file

@ -39,7 +39,7 @@ public class BrowserTransferProgress {
public Duration expectedTimeRemaining() {
var elapsed = elapsedTime();
var share = (double) transferred / total;
var rest = 1.0 - share;
var rest = (1.0 - share) / share;
var restMillis = (long) (elapsed.toMillis() * rest);
return Duration.of(restMillis, ChronoUnit.MILLIS);
}

View file

@ -6,21 +6,17 @@ import io.xpipe.app.fxcomps.impl.TooltipAugment;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.prefs.SupportedLocale;
import io.xpipe.app.util.OptionsBuilder;
import io.xpipe.app.util.Translatable;
import io.xpipe.core.util.ModuleHelper;
import io.xpipe.core.util.XPipeInstallation;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import lombok.SneakyThrows;
import lombok.Value;
import org.apache.commons.io.FilenameUtils;
import org.ocpsoft.prettytime.PrettyTime;
import java.io.IOException;
import java.io.InputStreamReader;
@ -131,7 +127,7 @@ public class AppI18n {
}
}
private LoadedTranslations getLoaded() {
public LoadedTranslations getLoaded() {
return currentLanguage.getValue() != null ? currentLanguage.getValue() : english;
}
@ -278,21 +274,15 @@ public class AppI18n {
});
}
var prettyTime = new PrettyTime(
AppPrefs.get() != null
? AppPrefs.get().language().getValue().getLocale()
: SupportedLocale.getEnglish().getLocale());
return new LoadedTranslations(l, translations, markdownDocumentations, prettyTime);
return new LoadedTranslations(l, translations, markdownDocumentations);
}
@Value
static class LoadedTranslations {
public static class LoadedTranslations {
Locale locale;
Map<String, String> translations;
Map<String, String> markdownDocumentations;
PrettyTime prettyTime;
}
@SuppressWarnings("removal")

View file

@ -2,6 +2,7 @@ package io.xpipe.app.util;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@ -80,4 +81,13 @@ public final class HumanReadableFormat {
private static int getWeekNumber(LocalDateTime date) {
return date.get(WeekFields.of(Locale.getDefault()).weekOfYear());
}
public static String duration(Duration duration) {
return duration.toString()
.substring(2)
.replaceAll("(\\d[HMS])(?!$)", "$1 ")
.replaceAll("\\.\\d+", "")
.toLowerCase();
}
}

View file

@ -49,7 +49,6 @@ open module io.xpipe.app {
requires org.slf4j;
requires org.slf4j.jdk.platform.logging;
requires atlantafx.base;
requires org.ocpsoft.prettytime;
requires com.vladsch.flexmark;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;