2023-11-10 14:53:12 +03:30
|
|
|
import 'package:flutter/foundation.dart';
|
2023-12-01 12:56:24 +03:30
|
|
|
import 'package:hiddify/core/app_info/app_info_provider.dart';
|
|
|
|
|
import 'package:hiddify/core/model/environment.dart';
|
|
|
|
|
import 'package:hiddify/core/model/region.dart';
|
|
|
|
|
import 'package:hiddify/core/preferences/preferences_provider.dart';
|
2024-03-02 22:53:14 +03:30
|
|
|
import 'package:hiddify/core/utils/preferences_utils.dart';
|
2023-12-01 12:56:24 +03:30
|
|
|
import 'package:hiddify/features/per_app_proxy/model/per_app_proxy_mode.dart';
|
2023-12-14 19:58:15 +03:30
|
|
|
import 'package:hiddify/utils/platform_utils.dart';
|
2023-09-07 13:43:46 +03:30
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
2023-07-15 18:00:44 +03:30
|
|
|
|
2023-12-01 12:56:24 +03:30
|
|
|
part 'general_preferences.g.dart';
|
|
|
|
|
|
2023-11-10 14:53:12 +03:30
|
|
|
bool _debugIntroPage = false;
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
abstract class Preferences {
|
|
|
|
|
static final introCompleted = PreferencesNotifier.create(
|
2023-09-17 00:23:31 +03:30
|
|
|
"intro_completed",
|
|
|
|
|
false,
|
2024-03-02 22:53:14 +03:30
|
|
|
overrideValue: _debugIntroPage && kDebugMode ? false : null,
|
2023-09-17 00:23:31 +03:30
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final region = PreferencesNotifier.create<Region, String>(
|
2023-09-17 14:55:46 +03:30
|
|
|
"region",
|
|
|
|
|
Region.other,
|
|
|
|
|
mapFrom: Region.values.byName,
|
|
|
|
|
mapTo: (value) => value.name,
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final silentStart = PreferencesNotifier.create<bool, bool>(
|
2023-12-01 12:56:24 +03:30
|
|
|
"silent_start",
|
|
|
|
|
false,
|
|
|
|
|
);
|
2023-09-07 13:43:46 +03:30
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final disableMemoryLimit = PreferencesNotifier.create<bool, bool>(
|
2023-10-26 15:16:25 +03:30
|
|
|
"disable_memory_limit",
|
2023-12-14 19:58:15 +03:30
|
|
|
// disable memory limit on desktop by default
|
|
|
|
|
PlatformUtils.isDesktop,
|
2023-09-16 15:16:20 +03:30
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final perAppProxyMode =
|
|
|
|
|
PreferencesNotifier.create<PerAppProxyMode, String>(
|
2023-09-13 23:19:16 +03:30
|
|
|
"per_app_proxy_mode",
|
|
|
|
|
PerAppProxyMode.off,
|
|
|
|
|
mapFrom: PerAppProxyMode.values.byName,
|
|
|
|
|
mapTo: (value) => value.name,
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final markNewProfileActive = PreferencesNotifier.create<bool, bool>(
|
|
|
|
|
"mark_new_profile_active",
|
|
|
|
|
true,
|
2023-09-13 23:19:16 +03:30
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final dynamicNotification = PreferencesNotifier.create<bool, bool>(
|
|
|
|
|
"dynamic_notification",
|
|
|
|
|
true,
|
2023-09-13 23:19:16 +03:30
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final autoCheckIp = PreferencesNotifier.create<bool, bool>(
|
|
|
|
|
"auto_check_ip",
|
2023-09-10 14:16:44 +03:30
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
static final startedByUser = PreferencesNotifier.create<bool, bool>(
|
|
|
|
|
"started_by_user",
|
|
|
|
|
false,
|
|
|
|
|
);
|
2024-03-17 14:45:15 +01:00
|
|
|
|
|
|
|
|
static final storeReviewedByUser = PreferencesNotifier.create<bool, bool>(
|
|
|
|
|
"store_reviewed_by_user",
|
|
|
|
|
false,
|
|
|
|
|
);
|
2023-09-10 14:16:44 +03:30
|
|
|
}
|
2023-12-14 14:50:10 +03:30
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
@Riverpod(keepAlive: true)
|
|
|
|
|
class DebugModeNotifier extends _$DebugModeNotifier {
|
|
|
|
|
late final _pref = PreferencesEntry(
|
|
|
|
|
preferences: ref.watch(sharedPreferencesProvider).requireValue,
|
|
|
|
|
key: "debug_mode",
|
|
|
|
|
defaultValue: ref.read(environmentProvider) == Environment.dev,
|
2023-12-14 14:50:10 +03:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@override
|
2024-03-02 22:53:14 +03:30
|
|
|
bool build() => _pref.read();
|
2023-12-14 14:50:10 +03:30
|
|
|
|
|
|
|
|
Future<void> update(bool value) {
|
|
|
|
|
state = value;
|
2024-03-02 22:53:14 +03:30
|
|
|
return _pref.write(value);
|
2023-12-14 14:50:10 +03:30
|
|
|
}
|
|
|
|
|
}
|
2024-02-17 13:11:50 +03:30
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
@Riverpod(keepAlive: true)
|
|
|
|
|
class PerAppProxyList extends _$PerAppProxyList {
|
|
|
|
|
late final _include = PreferencesEntry(
|
|
|
|
|
preferences: ref.watch(sharedPreferencesProvider).requireValue,
|
|
|
|
|
key: "per_app_proxy_include_list",
|
|
|
|
|
defaultValue: <String>[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
late final _exclude = PreferencesEntry(
|
|
|
|
|
preferences: ref.watch(sharedPreferencesProvider).requireValue,
|
|
|
|
|
key: "per_app_proxy_exclude_list",
|
|
|
|
|
defaultValue: <String>[],
|
2024-02-17 13:11:50 +03:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@override
|
2024-03-02 22:53:14 +03:30
|
|
|
List<String> build() =>
|
|
|
|
|
ref.watch(Preferences.perAppProxyMode) == PerAppProxyMode.include
|
|
|
|
|
? _include.read()
|
|
|
|
|
: _exclude.read();
|
2024-02-17 13:11:50 +03:30
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
Future<void> update(List<String> value) {
|
2024-02-17 13:11:50 +03:30
|
|
|
state = value;
|
2024-03-02 22:53:14 +03:30
|
|
|
if (ref.read(Preferences.perAppProxyMode) == PerAppProxyMode.include) {
|
|
|
|
|
return _include.write(value);
|
|
|
|
|
}
|
|
|
|
|
return _exclude.write(value);
|
2024-02-17 13:11:50 +03:30
|
|
|
}
|
|
|
|
|
}
|