2023-09-12 16:51:43 +02:00
|
|
|
import 'dart:io';
|
2023-04-13 17:22:06 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2023-04-11 19:21:00 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-09-12 16:51:43 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' show useEffect, useState;
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-09-12 16:51:43 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-04-11 19:21:00 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/ui/settings_switch_list_tile.dart';
|
2023-04-14 15:50:46 +02:00
|
|
|
import 'package:immich_mobile/shared/services/immich_logger.service.dart';
|
2023-09-12 16:51:43 +02:00
|
|
|
import 'package:immich_mobile/utils/http_ssl_cert_override.dart';
|
2023-04-14 15:50:46 +02:00
|
|
|
import 'package:logging/logging.dart';
|
2023-04-11 19:21:00 +02:00
|
|
|
|
|
|
|
class AdvancedSettings extends HookConsumerWidget {
|
|
|
|
const AdvancedSettings({super.key});
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-09-12 16:51:43 +02:00
|
|
|
bool isLoggedIn = Store.tryGet(StoreKey.currentUser) != null;
|
2023-04-11 19:21:00 +02:00
|
|
|
final appSettingService = ref.watch(appSettingsServiceProvider);
|
|
|
|
final isEnabled =
|
|
|
|
useState(AppSettingsEnum.advancedTroubleshooting.defaultValue);
|
2023-04-14 15:50:46 +02:00
|
|
|
final levelId = useState(AppSettingsEnum.logLevel.defaultValue);
|
2023-07-01 03:47:44 +02:00
|
|
|
final preferRemote =
|
|
|
|
useState(AppSettingsEnum.preferRemoteImage.defaultValue);
|
2023-09-12 16:51:43 +02:00
|
|
|
final allowSelfSignedSSLCert =
|
|
|
|
useState(AppSettingsEnum.allowSelfSignedSSLCert.defaultValue);
|
2023-04-11 19:21:00 +02:00
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
isEnabled.value = appSettingService.getSetting<bool>(
|
|
|
|
AppSettingsEnum.advancedTroubleshooting,
|
|
|
|
);
|
2023-04-14 15:50:46 +02:00
|
|
|
levelId.value = appSettingService.getSetting(AppSettingsEnum.logLevel);
|
2023-07-01 03:47:44 +02:00
|
|
|
preferRemote.value =
|
|
|
|
appSettingService.getSetting(AppSettingsEnum.preferRemoteImage);
|
2023-09-12 16:51:43 +02:00
|
|
|
allowSelfSignedSSLCert.value = appSettingService
|
|
|
|
.getSetting(AppSettingsEnum.allowSelfSignedSSLCert);
|
2023-04-11 19:21:00 +02:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2023-04-14 15:50:46 +02:00
|
|
|
|
|
|
|
final logLevel = Level.LEVELS[levelId.value].name;
|
|
|
|
|
2023-04-11 19:21:00 +02:00
|
|
|
return ExpansionTile(
|
2023-11-09 18:19:53 +02:00
|
|
|
textColor: context.primaryColor,
|
2023-04-11 19:21:00 +02:00
|
|
|
title: const Text(
|
2023-04-13 17:22:06 +02:00
|
|
|
"advanced_settings_tile_title",
|
2023-04-11 19:21:00 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
).tr(),
|
|
|
|
subtitle: const Text(
|
|
|
|
"advanced_settings_tile_subtitle",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 13,
|
|
|
|
),
|
|
|
|
).tr(),
|
2023-04-11 19:21:00 +02:00
|
|
|
children: [
|
|
|
|
SettingsSwitchListTile(
|
|
|
|
enabled: true,
|
|
|
|
appSettingService: appSettingService,
|
|
|
|
valueNotifier: isEnabled,
|
|
|
|
settingsEnum: AppSettingsEnum.advancedTroubleshooting,
|
2023-04-13 17:22:06 +02:00
|
|
|
title: "advanced_settings_troubleshooting_title".tr(),
|
|
|
|
subtitle: "advanced_settings_troubleshooting_subtitle".tr(),
|
2023-04-11 19:21:00 +02:00
|
|
|
),
|
2023-04-14 15:50:46 +02:00
|
|
|
ListTile(
|
|
|
|
dense: true,
|
|
|
|
title: Text(
|
|
|
|
// Not translated because the levels are only English
|
|
|
|
"Log level: $logLevel",
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
subtitle: Slider(
|
|
|
|
value: levelId.value.toDouble(),
|
|
|
|
onChanged: (double v) => levelId.value = v.toInt(),
|
|
|
|
onChangeEnd: (double v) {
|
|
|
|
appSettingService.setSetting(
|
|
|
|
AppSettingsEnum.logLevel,
|
|
|
|
v.toInt(),
|
|
|
|
);
|
|
|
|
ImmichLogger().level = Level.LEVELS[v.toInt()];
|
|
|
|
},
|
|
|
|
max: 8,
|
|
|
|
min: 1.0,
|
|
|
|
divisions: 7,
|
|
|
|
label: logLevel,
|
2023-11-09 18:19:53 +02:00
|
|
|
activeColor: context.primaryColor,
|
2023-04-14 15:50:46 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-01 03:47:44 +02:00
|
|
|
SettingsSwitchListTile(
|
|
|
|
appSettingService: appSettingService,
|
|
|
|
valueNotifier: preferRemote,
|
|
|
|
settingsEnum: AppSettingsEnum.preferRemoteImage,
|
|
|
|
title: "advanced_settings_prefer_remote_title".tr(),
|
|
|
|
subtitle: "advanced_settings_prefer_remote_subtitle".tr(),
|
|
|
|
),
|
2023-09-12 16:51:43 +02:00
|
|
|
SettingsSwitchListTile(
|
|
|
|
enabled: !isLoggedIn,
|
|
|
|
appSettingService: appSettingService,
|
|
|
|
valueNotifier: allowSelfSignedSSLCert,
|
|
|
|
settingsEnum: AppSettingsEnum.allowSelfSignedSSLCert,
|
|
|
|
title: "advanced_settings_self_signed_ssl_title".tr(),
|
|
|
|
subtitle: "advanced_settings_self_signed_ssl_subtitle".tr(),
|
|
|
|
onChanged: (value) {
|
|
|
|
HttpOverrides.global = HttpSSLCertOverride();
|
|
|
|
},
|
|
|
|
),
|
2023-04-11 19:21:00 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|