Compare commits
4 Commits
462ea165f7
...
d6b30e11b2
Author | SHA1 | Date | |
---|---|---|---|
d6b30e11b2 | |||
ba884245b8 | |||
5f713b1f9c | |||
b017aeec12 |
@ -11,7 +11,8 @@ class MountConfig {
|
||||
|
||||
String get name => _name;
|
||||
String get path => _path;
|
||||
UnmodifiableMapView get settings => UnmodifiableMapView(_settings);
|
||||
UnmodifiableMapView<String, dynamic> get settings =>
|
||||
UnmodifiableMapView<String, dynamic>(_settings);
|
||||
IconData get state => _state;
|
||||
String get type => _type;
|
||||
|
||||
|
@ -16,44 +16,299 @@ class MountSettingsWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
||||
MountConfig? config;
|
||||
Map<String, dynamic>? _settings;
|
||||
|
||||
void _addBooleanSetting(list, root, key, value) {
|
||||
list.add(
|
||||
SettingsTile.switchTile(
|
||||
leading: Icon(Icons.check),
|
||||
title: Text(key),
|
||||
initialValue: (value as bool),
|
||||
onPressed: (_) {
|
||||
setState(() {
|
||||
root?[key] = !value;
|
||||
});
|
||||
},
|
||||
onToggle: (bool nextValue) {
|
||||
setState(() {
|
||||
root?[key] = nextValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _addIntSetting(list, root, key, value) {
|
||||
list.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(Icons.onetwothree),
|
||||
title: Text(key),
|
||||
value: Text((value as int).toString()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _addPasswordSetting(list, root, key, value) {
|
||||
list.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(Icons.password),
|
||||
title: Text(key),
|
||||
value: Text('*' * (value as String).length),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _addStringSetting(list, root, key, value, icon) {
|
||||
list.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(icon),
|
||||
title: Text(key),
|
||||
value: Text(value),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<SettingsTile> commonSettings = [];
|
||||
config?.settings.forEach((key, value) {
|
||||
List<SettingsTile> encryptConfigSettings = [];
|
||||
List<SettingsTile> hostConfigSettings = [];
|
||||
List<SettingsTile> remoteMountSettings = [];
|
||||
List<SettingsTile> s3ConfigSettings = [];
|
||||
List<SettingsTile> siaConfigSettings = [];
|
||||
|
||||
_settings?.forEach((key, value) {
|
||||
if (key == "ApiAuth") {
|
||||
commonSettings.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(Icons.password),
|
||||
title: Text(key),
|
||||
value: Text('*' * (value as String).length),
|
||||
),
|
||||
);
|
||||
_addPasswordSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "ApiPort") {
|
||||
commonSettings.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(Icons.onetwothree),
|
||||
title: Text(key),
|
||||
value: Text((value as int).toString()),
|
||||
),
|
||||
);
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "ApiUser") {
|
||||
commonSettings.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(Icons.person),
|
||||
title: Text(key),
|
||||
value: Text(value),
|
||||
),
|
||||
);
|
||||
_addStringSetting(commonSettings, _settings, key, value, Icons.person);
|
||||
} else if (key == "DatabaseType") {
|
||||
commonSettings.add(
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(Icons.dataset),
|
||||
title: Text(key),
|
||||
value: Text(value),
|
||||
),
|
||||
_addStringSetting(commonSettings, _settings, key, value, Icons.dataset);
|
||||
} else if (key == "DownloadTimeoutSeconds") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "EnableDownloadTimeout") {
|
||||
_addBooleanSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "EnableDriveEvents") {
|
||||
_addBooleanSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "EventLevel") {
|
||||
_addStringSetting(commonSettings, _settings, key, value, Icons.event);
|
||||
} else if (key == "EvictionDelayMinutes") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "EvictionUseAccessedTime") {
|
||||
_addBooleanSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "MaxCacheSizeBytes") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "MaxUploadCount") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "OnlineCheckRetrySeconds") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "PreferredDownloadType") {
|
||||
_addStringSetting(
|
||||
commonSettings,
|
||||
_settings,
|
||||
key,
|
||||
value,
|
||||
Icons.download,
|
||||
);
|
||||
} else if (key == "RetryReadCount") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "RingBufferFileSize") {
|
||||
_addIntSetting(commonSettings, _settings, key, value);
|
||||
} else if (key == "EncryptConfig") {
|
||||
value.forEach((subKey, subValue) {
|
||||
if (subKey == "EncryptionToken") {
|
||||
_addPasswordSetting(
|
||||
encryptConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "Path") {
|
||||
_addStringSetting(
|
||||
encryptConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.folder,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (key == "HostConfig") {
|
||||
value.forEach((subKey, subValue) {
|
||||
if (subKey == "AgentString") {
|
||||
_addStringSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.support_agent,
|
||||
);
|
||||
} else if (subKey == "ApiPassword") {
|
||||
_addPasswordSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "ApiPort") {
|
||||
_addIntSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "ApiUser") {
|
||||
_addStringSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.person,
|
||||
);
|
||||
} else if (subKey == "HostNameOrIp") {
|
||||
_addStringSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.computer,
|
||||
);
|
||||
} else if (subKey == "Path") {
|
||||
_addStringSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.route,
|
||||
);
|
||||
} else if (subKey == "Protocol") {
|
||||
_addStringSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.http,
|
||||
);
|
||||
} else if (subKey == "TimeoutMs") {
|
||||
_addIntSetting(
|
||||
hostConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (key == "RemoteMount") {
|
||||
value.forEach((subKey, subValue) {
|
||||
if (subKey == "ApiPort") {
|
||||
_addIntSetting(
|
||||
remoteMountSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "ClientPoolSize") {
|
||||
_addIntSetting(
|
||||
remoteMountSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "Enable") {
|
||||
_addBooleanSetting(
|
||||
remoteMountSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "EncryptionToken") {
|
||||
_addPasswordSetting(
|
||||
remoteMountSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (key == "S3Config") {
|
||||
value.forEach((subKey, subValue) {
|
||||
if (subKey == "AccessKey") {
|
||||
_addPasswordSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "Bucket") {
|
||||
_addStringSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.folder,
|
||||
);
|
||||
} else if (subKey == "EncryptionToken") {
|
||||
_addPasswordSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "Region") {
|
||||
_addStringSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.map,
|
||||
);
|
||||
} else if (subKey == "SecretKey") {
|
||||
_addPasswordSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "TimeoutMs") {
|
||||
_addIntSetting(s3ConfigSettings, _settings?[key], subKey, subValue);
|
||||
} else if (subKey == "URL") {
|
||||
_addStringSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.http,
|
||||
);
|
||||
} else if (subKey == "UsePathStyle") {
|
||||
_addBooleanSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
} else if (subKey == "UseRegionInURL") {
|
||||
_addBooleanSetting(
|
||||
s3ConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (key == "SiaConfig") {
|
||||
value.forEach((subKey, subValue) {
|
||||
if (subKey == "Bucket") {
|
||||
_addStringSetting(
|
||||
siaConfigSettings,
|
||||
_settings?[key],
|
||||
subKey,
|
||||
subValue,
|
||||
Icons.folder,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -65,10 +320,32 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
||||
body: SettingsList(
|
||||
shrinkWrap: false,
|
||||
sections: [
|
||||
SettingsSection(
|
||||
title: Text('Common Settings'),
|
||||
tiles: commonSettings.toList(),
|
||||
),
|
||||
if (encryptConfigSettings.isNotEmpty)
|
||||
SettingsSection(
|
||||
title: const Text('Encrypt Config'),
|
||||
tiles: encryptConfigSettings,
|
||||
),
|
||||
if (hostConfigSettings.isNotEmpty)
|
||||
SettingsSection(
|
||||
title: const Text('Host Config'),
|
||||
tiles: hostConfigSettings,
|
||||
),
|
||||
if (remoteMountSettings.isNotEmpty)
|
||||
SettingsSection(
|
||||
title: const Text('Remote Mount'),
|
||||
tiles: remoteMountSettings,
|
||||
),
|
||||
if (s3ConfigSettings.isNotEmpty)
|
||||
SettingsSection(
|
||||
title: const Text('S3 Config'),
|
||||
tiles: s3ConfigSettings,
|
||||
),
|
||||
if (siaConfigSettings.isNotEmpty)
|
||||
SettingsSection(
|
||||
title: const Text('Sia Config'),
|
||||
tiles: siaConfigSettings,
|
||||
),
|
||||
SettingsSection(title: const Text('Settings'), tiles: commonSettings),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -76,7 +353,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
config = widget.config;
|
||||
_settings = Map.from(widget.config.settings);
|
||||
super.initState();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user