feat: support use server time for file creation (#359)

This commit is contained in:
Levi authored and GitHub committed 2024-01-30 09:08:01 +08:00
1 parent b89c7bc608
commit 62c22bc6b4
20 files changed
+192 -75

No files matched your search

@@ -95,6 +95,9 @@ class AppController extends GetxController with WindowListener, TrayListener {
_initForegroundTask().onError((error, stackTrace) =>
logger.w("initForegroundTask error", error, stackTrace));
_initTrackerUpdate().onError((error, stackTrace) =>
logger.w("initTrackerUpdate error", error, stackTrace));
}
@override
@@ -357,12 +360,13 @@ class AppController extends GetxController with WindowListener, TrayListener {
btConfig.trackers.toSet().toList();
}
Future<void> trackerUpdateOnStart() async {
Future<void> _initTrackerUpdate() async {
final btExtConfig = downloaderConfig.value.extra.bt;
final lastUpdateTime = btExtConfig.lastTrackerUpdateTime;
// if last update time is null or more than 1 day, update trackers
if (lastUpdateTime == null ||
lastUpdateTime.difference(DateTime.now()).inDays < 0) {
if (btExtConfig.autoUpdateTrackers &&
(lastUpdateTime == null ||
lastUpdateTime.difference(DateTime.now()).inDays < 0)) {
try {
await trackerUpdate();
} catch (e) {
@@ -386,9 +390,6 @@ class AppController extends GetxController with WindowListener, TrayListener {
_initDownloaderConfig() async {
final config = downloaderConfig.value;
if (config.protocolConfig.http.connections == 0) {
config.protocolConfig.http.connections = 16;
}
final extra = config.extra;
if (extra.themeMode.isEmpty) {
extra.themeMode = ThemeMode.dark.name;
@@ -138,6 +138,22 @@ class SettingView extends GetView<SettingController> {
],
);
});
final buildHttpUseServerCtime = _buildConfigItem(
'useServerCtime'.tr, () => httpConfig.useServerCtime.toString(),
(Key key) {
return Container(
alignment: Alignment.centerLeft,
child: Switch(
value: httpConfig.useServerCtime,
onChanged: (bool value) {
downloaderCfg.update((val) {
val!.protocolConfig.http.useServerCtime = value;
});
debounceSave();
},
),
);
});
// bt config items start
final btConfig = downloaderCfg.value.protocolConfig.bt;
@@ -207,8 +223,13 @@ class SettingView extends GetView<SettingController> {
Expanded(
child: SwitchListTile(
controlAffinity: ListTileControlAffinity.leading,
value: true,
onChanged: (bool value) {},
value: btExtConfig.autoUpdateTrackers,
onChanged: (bool value) {
downloaderCfg.update((val) {
val!.extra.bt.autoUpdateTrackers = value;
});
debounceSave();
},
title: Text('updateDaily'.tr)),
),
],
@@ -676,6 +697,7 @@ class SettingView extends GetView<SettingController> {
children: _addDivider([
buildHttpUa(),
buildHttpConnections(),
buildHttpUseServerCtime(),
]),
)),
const Text('BitTorrent'),