Skip to content

Commit 0da2817

Browse files
authored
优化设置 -> 通用页面 (#6014)
1 parent be82266 commit 0da2817

5 files changed

Lines changed: 203 additions & 219 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727
import javafx.scene.control.ToggleGroup;
2828
import javafx.scene.layout.*;
2929
import org.jackhuang.hmcl.setting.DownloadProviders;
30+
import org.jackhuang.hmcl.setting.EnumCommonDirectory;
31+
import org.jackhuang.hmcl.setting.Settings;
3032
import org.jackhuang.hmcl.task.FetchTask;
3133
import org.jackhuang.hmcl.ui.FXUtils;
3234
import org.jackhuang.hmcl.ui.WeakListenerHolder;
3335
import org.jackhuang.hmcl.ui.construct.*;
3436
import org.jackhuang.hmcl.util.i18n.I18n;
37+
import org.jackhuang.hmcl.util.io.FileUtils;
3538
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
3639

3740
import java.net.Proxy;
41+
import java.nio.file.Path;
42+
import java.util.Arrays;
43+
import java.util.Optional;
3844
import java.util.concurrent.atomic.AtomicBoolean;
3945
import java.util.function.Function;
4046

@@ -98,9 +104,37 @@ public DownloadSettingsPage() {
98104
}
99105

100106
{
107+
var downloadList = new ComponentList();
108+
101109
VBox downloadThreads = new VBox(16);
102-
downloadThreads.getStyleClass().add("card-non-transparent");
110+
111+
ComponentSublist fileCommonLocationSublist = new ComponentSublist();
112+
103113
{
114+
{
115+
MultiFileItem<EnumCommonDirectory> fileCommonLocation = new MultiFileItem<>();
116+
fileCommonLocation.loadChildren(Arrays.asList(
117+
new MultiFileItem.Option<>(i18n("launcher.cache_directory.default"), EnumCommonDirectory.DEFAULT),
118+
new MultiFileItem.FileOption<>(i18n("settings.custom"), EnumCommonDirectory.CUSTOM)
119+
.setChooserTitle(i18n("launcher.cache_directory.choose"))
120+
.setSelectionMode(FileSelector.SelectionMode.DIRECTORY)
121+
.bindBidirectional(config().commonDirectoryProperty())
122+
));
123+
fileCommonLocation.selectedDataProperty().bindBidirectional(config().commonDirTypeProperty());
124+
125+
fileCommonLocationSublist.getContent().add(fileCommonLocation);
126+
fileCommonLocationSublist.setTitle(i18n("launcher.cache_directory"));
127+
fileCommonLocationSublist.setHasSubtitle(true);
128+
fileCommonLocationSublist.subtitleProperty().bind(
129+
Bindings.createObjectBinding(() -> Optional.ofNullable(Settings.instance().getCommonDirectory())
130+
.orElse(i18n("launcher.cache_directory.disabled")),
131+
config().commonDirectoryProperty(), config().commonDirTypeProperty()));
132+
133+
JFXButton cleanButton = FXUtils.newBorderButton(i18n("launcher.cache_directory.clean"));
134+
cleanButton.setOnAction(e -> clearCacheDirectory());
135+
fileCommonLocationSublist.setHeaderRight(cleanButton);
136+
}
137+
104138
{
105139
JFXCheckBox chkAutoDownloadThreads = new JFXCheckBox(i18n("settings.launcher.download.threads.auto"));
106140
VBox.setMargin(chkAutoDownloadThreads, new Insets(8, 0, 0, 0));
@@ -153,7 +187,8 @@ public DownloadSettingsPage() {
153187
}
154188
}
155189

156-
content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("download")), downloadThreads);
190+
downloadList.getContent().addAll(fileCommonLocationSublist, downloadThreads);
191+
content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("download")), downloadList);
157192
}
158193

159194
{
@@ -330,4 +365,11 @@ public DownloadSettingsPage() {
330365
}
331366

332367
}
368+
369+
private void clearCacheDirectory() {
370+
String commonDirectory = Settings.instance().getCommonDirectory();
371+
if (commonDirectory != null) {
372+
FileUtils.cleanDirectoryQuietly(Path.of(commonDirectory, "cache"));
373+
}
374+
}
333375
}

0 commit comments

Comments
 (0)