Skip to content

Commit

Permalink
feat: add 'timeout' sync config (indev)
Browse files Browse the repository at this point in the history
  • Loading branch information
FriesI23 committed Jan 24, 2025
1 parent 2e8b5ff commit 594833c
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 56 deletions.
1 change: 1 addition & 0 deletions lib/common/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const defaultSortDirection = HabitDisplaySortDirection.asc;
const defaultHabitsRecordScrollBehavior = HabitsRecordScrollBehavior.scrollable;
const defaultFirstDay = DateTime.monday;
const defaultAppReminder = AppReminderConfig.off;
const defaultAppSyncTimeout = Duration(seconds: 60);
//#endregion

//#region habit-field
Expand Down
100 changes: 60 additions & 40 deletions lib/model/app_sync_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@ part 'app_sync_server.g.dart';
enum AppSyncServerType implements EnumWithDBCode<AppSyncServerType> {
unknown(code: 0),
webdav(
code: 1,
includePathField: true,
includeUsernameField: true,
includePasswordField: true,
includeIgnoreSSLField: true,
),
code: 1,
includePathField: true,
includeUsernameField: true,
includePasswordField: true,
includeIgnoreSSLField: true,
includeConnTimeoutField: true,
includeRetryCountFIeld: true),
fake(code: 99);

final int code;
final bool includePathField;
final bool includeUsernameField;
final bool includePasswordField;
final bool includeIgnoreSSLField;

const AppSyncServerType({
required this.code,
this.includePathField = false,
this.includeUsernameField = false,
this.includePasswordField = false,
this.includeIgnoreSSLField = false,
});
final bool includeConnTimeoutField;
final bool includeRetryCountFIeld;

const AppSyncServerType(
{required this.code,
this.includePathField = false,
this.includeUsernameField = false,
this.includePasswordField = false,
this.includeIgnoreSSLField = false,
this.includeConnTimeoutField = false,
this.includeRetryCountFIeld = false});

@override
int get dbCode => code;
Expand Down Expand Up @@ -115,7 +119,7 @@ abstract interface class AppSyncServer implements JsonAdaptor {
Iterable<AppSyncServerMobileNetwork> get syncMobileNetworks;
bool get syncInLowData;
bool get ignoreSSL;
DateTime? get timeout;
Duration? get timeout;
bool get verified;
bool get configed;

Expand Down Expand Up @@ -143,7 +147,7 @@ final class AppWebDavSyncServer implements AppSyncServer {
@override
final bool syncInLowData;
@override
final DateTime? timeout;
final Duration? timeout;
@override
final bool verified;
@override
Expand All @@ -155,7 +159,7 @@ final class AppWebDavSyncServer implements AppSyncServer {
final String username;
final String password;
final int? maxRetryCount;
final DateTime? connectTimeout;
final Duration? connectTimeout;

const AppWebDavSyncServer({
required this.identity,
Expand Down Expand Up @@ -183,8 +187,8 @@ final class AppWebDavSyncServer implements AppSyncServer {
Iterable<AppSyncServerMobileNetwork>? syncMobileNetworks,
bool syncInLowData = true,
bool ignoreSSL = false,
DateTime? timeout,
DateTime? connectTimeout,
Duration? timeout,
Duration? connectTimeout,
int? maxRetryCount,
}) {
final now = DateTime.now();
Expand Down Expand Up @@ -246,14 +250,17 @@ final class AppWebDavSyncServer implements AppSyncServer {

@override
AppSyncServerForm toForm() => AppSyncServerForm(
uuid: UuidValue.fromString(identity),
createTime: createTime,
modifyTime: modifyTime,
type: type,
path: path.toString(),
username: username,
password: password,
);
uuid: UuidValue.fromString(identity),
createTime: createTime,
modifyTime: modifyTime,
type: type,
path: path.toString(),
username: username,
password: password,
ignoreSSL: ignoreSSL,
timeout: timeout,
connectTimeout: connectTimeout,
retryCount: maxRetryCount);

@override
String toDebugString() {
Expand Down Expand Up @@ -298,7 +305,7 @@ final class AppFakeSyncServer implements AppSyncServer {
@override
final bool syncInLowData;
@override
final DateTime? timeout;
final Duration? timeout;
@override
final bool verified;
@override
Expand Down Expand Up @@ -327,8 +334,8 @@ final class AppFakeSyncServer implements AppSyncServer {
List<AppSyncServerMobileNetwork>? syncMobileNetworks,
bool syncInLowData = true,
bool ignoreSSL = false,
DateTime? timeout,
DateTime? connectTimeout,
Duration? timeout,
Duration? connectTimeout,
int? maxRetryCount,
}) {
final now = DateTime.now();
Expand Down Expand Up @@ -379,11 +386,17 @@ final class AppFakeSyncServer implements AppSyncServer {

@override
AppSyncServerForm toForm() => AppSyncServerForm(
uuid: UuidValue.fromString(identity),
createTime: createTime,
modifyTime: modifyTime,
type: type,
);
uuid: UuidValue.fromString(identity),
createTime: createTime,
modifyTime: modifyTime,
type: type,
path: null,
username: null,
password: null,
ignoreSSL: ignoreSSL,
timeout: timeout,
connectTimeout: null,
retryCount: null);

@override
Map<String, dynamic> toJson() => _$AppFakeSyncServerToJson(this);
Expand All @@ -401,21 +414,28 @@ class AppSyncServerForm {
String? username;
String? password;
bool? ignoreSSL;
Duration? timeout;
Duration? connectTimeout;
int? retryCount;

AppSyncServerForm({
required this.uuid,
required this.type,
required this.createTime,
required this.modifyTime,
this.path,
this.username,
this.password,
this.ignoreSSL,
required this.path,
required this.username,
required this.password,
required this.ignoreSSL,
required this.timeout,
required this.connectTimeout,
required this.retryCount,
});

@override
String toString() => 'AppSyncServerForm(uuid=$uuid,type=$type,'
'createTime=$createTime,modifyTime=$modifyTime,'
'path=$path,username=$username,password=$password,'
'ignoreSSL=$ignoreSSL)';
'ignoreSSL=$ignoreSSL,timeout=$timeout,'
'connectTimeout=$connectTimeout,retryCount=$retryCount)';
}
42 changes: 30 additions & 12 deletions lib/model/app_sync_server.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/provider/app_sync_server_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ class AppSyncServerFormViewModel extends ChangeNotifier
notifyListeners();
}

Duration? get timeout => _form.timeout;
set timeout(Duration? value) {
assert((value?.inSeconds ?? 0) >= 0);
if (value == timeout) return;
final oldValue = timeout;
_form.timeout = value;
appLog.value.info('$runtimeType.timeout',
beforeVal: oldValue?.inSeconds, afterVal: value?.inSeconds);
notifyListeners();
}

Future<(String, String?)> getPassword({
Duration timeout = const Duration(seconds: 1),
bool changeController = true,
Expand Down
1 change: 1 addition & 0 deletions lib/view/for_app_sync_server_editor/_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
export './app_sync_server_ignoressl.dart';
export './app_sync_server_password.dart';
export './app_sync_server_path.dart';
export './app_sync_server_timeout.dart';
export './app_sync_server_type.dart';
export './app_sync_server_username.dart';
export './page_providers.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import 'package:provider/provider.dart';
import '../../model/app_sync_server.dart';
import '../../provider/app_sync_server_form.dart';

class AppSyncServerIgnoreSSL extends StatelessWidget {
class AppSyncServerIgnoreSSLTile extends StatelessWidget {
final EdgeInsetsGeometry? contentPadding;

const AppSyncServerIgnoreSSL({super.key, this.contentPadding});
const AppSyncServerIgnoreSSLTile({super.key, this.contentPadding});

@override
Widget build(BuildContext context) {
Expand Down
Loading

0 comments on commit 594833c

Please sign in to comment.