Add memory limit option
This commit is contained in:
@@ -146,7 +146,8 @@
|
|||||||
"advanced": {
|
"advanced": {
|
||||||
"sectionTitle": "Advanced",
|
"sectionTitle": "Advanced",
|
||||||
"debugMode": "Debug Mode",
|
"debugMode": "Debug Mode",
|
||||||
"debugModeMsg": "Restart the app for applying this change"
|
"debugModeMsg": "Restart the app for applying this change",
|
||||||
|
"memoryLimit": "Memory Limit"
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"perAppProxyPageTitle": "Per-app Proxy",
|
"perAppProxyPageTitle": "Per-app Proxy",
|
||||||
|
|||||||
@@ -146,7 +146,8 @@
|
|||||||
"advanced": {
|
"advanced": {
|
||||||
"sectionTitle": "پیشرفته",
|
"sectionTitle": "پیشرفته",
|
||||||
"debugMode": "دیباگ مود",
|
"debugMode": "دیباگ مود",
|
||||||
"debugModeMsg": "برای اعمال این تغییر اپ را ریاستارت کنید"
|
"debugModeMsg": "برای اعمال این تغییر اپ را ریاستارت کنید",
|
||||||
|
"memoryLimit": "محدودیت مموری"
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"perAppProxyPageTitle": "پراکسی برنامهها",
|
"perAppProxyPageTitle": "پراکسی برنامهها",
|
||||||
|
|||||||
@@ -146,7 +146,8 @@
|
|||||||
"advanced": {
|
"advanced": {
|
||||||
"sectionTitle": "Расширенные",
|
"sectionTitle": "Расширенные",
|
||||||
"debugMode": "Режим отладки",
|
"debugMode": "Режим отладки",
|
||||||
"debugModeMsg": "Для применения перезапустите приложение."
|
"debugModeMsg": "Для применения перезапустите приложение.",
|
||||||
|
"memoryLimit": "Ограничение памяти"
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"perAppProxyPageTitle": "Раздельное проксирование",
|
"perAppProxyPageTitle": "Раздельное проксирование",
|
||||||
|
|||||||
@@ -146,7 +146,8 @@
|
|||||||
"advanced": {
|
"advanced": {
|
||||||
"sectionTitle": "先进的",
|
"sectionTitle": "先进的",
|
||||||
"debugMode": "调试模式",
|
"debugMode": "调试模式",
|
||||||
"debugModeMsg": "重新启动应用程序以应用此更改"
|
"debugModeMsg": "重新启动应用程序以应用此更改",
|
||||||
|
"memoryLimit": "内存限制"
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"perAppProxyPageTitle": "每个应用程序代理",
|
"perAppProxyPageTitle": "每个应用程序代理",
|
||||||
|
|||||||
@@ -74,6 +74,23 @@ class EnableAnalytics extends _$EnableAnalytics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Riverpod(keepAlive: true)
|
||||||
|
class DisableMemoryLimit extends _$DisableMemoryLimit {
|
||||||
|
late final _pref = Pref(
|
||||||
|
ref.watch(sharedPreferencesProvider),
|
||||||
|
"disable_memory_limit",
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool build() => _pref.getValue();
|
||||||
|
|
||||||
|
Future<void> update(bool value) {
|
||||||
|
state = value;
|
||||||
|
return _pref.update(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Riverpod(keepAlive: true)
|
@Riverpod(keepAlive: true)
|
||||||
class CheckForPreReleaseUpdates extends _$CheckForPreReleaseUpdates {
|
class CheckForPreReleaseUpdates extends _$CheckForPreReleaseUpdates {
|
||||||
late final _pref = Pref(
|
late final _pref = Pref(
|
||||||
|
|||||||
@@ -86,14 +86,19 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<CoreServiceFailure, Unit> start(String fileName) {
|
TaskEither<CoreServiceFailure, Unit> start(
|
||||||
|
String fileName,
|
||||||
|
bool disableMemoryLimit,
|
||||||
|
) {
|
||||||
return exceptionHandler(
|
return exceptionHandler(
|
||||||
() {
|
() {
|
||||||
final configPath = filesEditor.configPath(fileName);
|
final configPath = filesEditor.configPath(fileName);
|
||||||
return setup()
|
return setup()
|
||||||
.andThen(() => changeConfigOptions(configOptions()))
|
.andThen(() => changeConfigOptions(configOptions()))
|
||||||
.andThen(
|
.andThen(
|
||||||
() => singbox.start(configPath).mapLeft(CoreServiceFailure.start),
|
() => singbox
|
||||||
|
.start(configPath, disableMemoryLimit)
|
||||||
|
.mapLeft(CoreServiceFailure.start),
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
},
|
},
|
||||||
@@ -110,14 +115,18 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<CoreServiceFailure, Unit> restart(String fileName) {
|
TaskEither<CoreServiceFailure, Unit> restart(
|
||||||
|
String fileName,
|
||||||
|
bool disableMemoryLimit,
|
||||||
|
) {
|
||||||
return exceptionHandler(
|
return exceptionHandler(
|
||||||
() {
|
() {
|
||||||
final configPath = filesEditor.configPath(fileName);
|
final configPath = filesEditor.configPath(fileName);
|
||||||
return changeConfigOptions(configOptions())
|
return changeConfigOptions(configOptions())
|
||||||
.andThen(
|
.andThen(
|
||||||
() =>
|
() => singbox
|
||||||
singbox.restart(configPath).mapLeft(CoreServiceFailure.start),
|
.restart(configPath, disableMemoryLimit)
|
||||||
|
.mapLeft(CoreServiceFailure.start),
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,11 +18,17 @@ abstract interface class SingboxFacade {
|
|||||||
ConfigOptions options,
|
ConfigOptions options,
|
||||||
);
|
);
|
||||||
|
|
||||||
TaskEither<CoreServiceFailure, Unit> start(String fileName);
|
TaskEither<CoreServiceFailure, Unit> start(
|
||||||
|
String fileName,
|
||||||
|
bool disableMemoryLimit,
|
||||||
|
);
|
||||||
|
|
||||||
TaskEither<CoreServiceFailure, Unit> stop();
|
TaskEither<CoreServiceFailure, Unit> stop();
|
||||||
|
|
||||||
TaskEither<CoreServiceFailure, Unit> restart(String fileName);
|
TaskEither<CoreServiceFailure, Unit> restart(
|
||||||
|
String fileName,
|
||||||
|
bool disableMemoryLimit,
|
||||||
|
);
|
||||||
|
|
||||||
Stream<Either<CoreServiceFailure, List<OutboundGroup>>> watchOutbounds();
|
Stream<Either<CoreServiceFailure, List<OutboundGroup>>> watchOutbounds();
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:hiddify/core/prefs/prefs.dart';
|
||||||
import 'package:hiddify/data/data_providers.dart';
|
import 'package:hiddify/data/data_providers.dart';
|
||||||
import 'package:hiddify/domain/connectivity/connectivity.dart';
|
import 'package:hiddify/domain/connectivity/connectivity.dart';
|
||||||
import 'package:hiddify/domain/core_facade.dart';
|
import 'package:hiddify/domain/core_facade.dart';
|
||||||
@@ -50,7 +51,9 @@ class ConnectivityController extends _$ConnectivityController with AppLogger {
|
|||||||
return _disconnect();
|
return _disconnect();
|
||||||
}
|
}
|
||||||
loggy.debug("reconnecting, profile: [$profileId]");
|
loggy.debug("reconnecting, profile: [$profileId]");
|
||||||
await _core.restart(profileId).mapLeft((err) {
|
await _core
|
||||||
|
.restart(profileId, ref.read(disableMemoryLimitProvider))
|
||||||
|
.mapLeft((err) {
|
||||||
loggy.warning("error reconnecting", err);
|
loggy.warning("error reconnecting", err);
|
||||||
state = AsyncError(err, StackTrace.current);
|
state = AsyncError(err, StackTrace.current);
|
||||||
}).run();
|
}).run();
|
||||||
@@ -70,8 +73,10 @@ class ConnectivityController extends _$ConnectivityController with AppLogger {
|
|||||||
|
|
||||||
Future<void> _connect() async {
|
Future<void> _connect() async {
|
||||||
final activeProfile = await ref.read(activeProfileProvider.future);
|
final activeProfile = await ref.read(activeProfileProvider.future);
|
||||||
await _core.start(activeProfile!.id).mapLeft((err) {
|
await _core
|
||||||
loggy.warning("error connecting", err);
|
.start(activeProfile!.id, ref.read(disableMemoryLimitProvider))
|
||||||
|
.mapLeft((err) {
|
||||||
|
loggy.warning("error connecting $err", err);
|
||||||
state = AsyncError(err, StackTrace.current);
|
state = AsyncError(err, StackTrace.current);
|
||||||
}).run();
|
}).run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
|||||||
|
|
||||||
final debug = ref.watch(debugModeNotifierProvider);
|
final debug = ref.watch(debugModeNotifierProvider);
|
||||||
final perAppProxy = ref.watch(perAppProxyModeNotifierProvider).enabled;
|
final perAppProxy = ref.watch(perAppProxyModeNotifierProvider).enabled;
|
||||||
|
final disableMemoryLimit = ref.watch(disableMemoryLimitProvider);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -83,6 +84,13 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
|||||||
await ref.read(debugModeNotifierProvider.notifier).update(value);
|
await ref.read(debugModeNotifierProvider.notifier).update(value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text(t.settings.advanced.memoryLimit),
|
||||||
|
value: !disableMemoryLimit,
|
||||||
|
onChanged: (value) async {
|
||||||
|
await ref.read(disableMemoryLimitProvider.notifier).update(!value);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -930,17 +930,20 @@ class SingboxNativeLibrary {
|
|||||||
|
|
||||||
ffi.Pointer<ffi.Char> start(
|
ffi.Pointer<ffi.Char> start(
|
||||||
ffi.Pointer<ffi.Char> configPath,
|
ffi.Pointer<ffi.Char> configPath,
|
||||||
|
int disableMemoryLimit,
|
||||||
) {
|
) {
|
||||||
return _start(
|
return _start(
|
||||||
configPath,
|
configPath,
|
||||||
|
disableMemoryLimit,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
late final _startPtr = _lookup<
|
late final _startPtr = _lookup<
|
||||||
ffi.NativeFunction<
|
ffi.NativeFunction<
|
||||||
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>>('start');
|
ffi.Pointer<ffi.Char> Function(
|
||||||
|
ffi.Pointer<ffi.Char>, GoUint8)>>('start');
|
||||||
late final _start = _startPtr
|
late final _start = _startPtr
|
||||||
.asFunction<ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>();
|
.asFunction<ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>, int)>();
|
||||||
|
|
||||||
ffi.Pointer<ffi.Char> stop() {
|
ffi.Pointer<ffi.Char> stop() {
|
||||||
return _stop();
|
return _stop();
|
||||||
@@ -952,17 +955,20 @@ class SingboxNativeLibrary {
|
|||||||
|
|
||||||
ffi.Pointer<ffi.Char> restart(
|
ffi.Pointer<ffi.Char> restart(
|
||||||
ffi.Pointer<ffi.Char> configPath,
|
ffi.Pointer<ffi.Char> configPath,
|
||||||
|
int disableMemoryLimit,
|
||||||
) {
|
) {
|
||||||
return _restart(
|
return _restart(
|
||||||
configPath,
|
configPath,
|
||||||
|
disableMemoryLimit,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
late final _restartPtr = _lookup<
|
late final _restartPtr = _lookup<
|
||||||
ffi.NativeFunction<
|
ffi.NativeFunction<
|
||||||
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>>('restart');
|
ffi.Pointer<ffi.Char> Function(
|
||||||
|
ffi.Pointer<ffi.Char>, GoUint8)>>('restart');
|
||||||
late final _restart = _restartPtr
|
late final _restart = _restartPtr
|
||||||
.asFunction<ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>();
|
.asFunction<ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>, int)>();
|
||||||
|
|
||||||
ffi.Pointer<ffi.Char> startCommandClient(
|
ffi.Pointer<ffi.Char> startCommandClient(
|
||||||
int command,
|
int command,
|
||||||
|
|||||||
@@ -130,12 +130,16 @@ class FFISingboxService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<String, Unit> start(String configPath) {
|
TaskEither<String, Unit> start(String configPath, bool disableMemoryLimit) {
|
||||||
|
loggy.debug("starting, memory limit: [${!disableMemoryLimit}]");
|
||||||
return TaskEither(
|
return TaskEither(
|
||||||
() => CombineWorker().execute(
|
() => CombineWorker().execute(
|
||||||
() {
|
() {
|
||||||
final err = _box
|
final err = _box
|
||||||
.start(configPath.toNativeUtf8().cast())
|
.start(
|
||||||
|
configPath.toNativeUtf8().cast(),
|
||||||
|
disableMemoryLimit ? 1 : 0,
|
||||||
|
)
|
||||||
.cast<Utf8>()
|
.cast<Utf8>()
|
||||||
.toDartString();
|
.toDartString();
|
||||||
if (err.isNotEmpty) {
|
if (err.isNotEmpty) {
|
||||||
@@ -163,12 +167,16 @@ class FFISingboxService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<String, Unit> restart(String configPath) {
|
TaskEither<String, Unit> restart(String configPath, bool disableMemoryLimit) {
|
||||||
|
loggy.debug("restarting, memory limit: [${!disableMemoryLimit}]");
|
||||||
return TaskEither(
|
return TaskEither(
|
||||||
() => CombineWorker().execute(
|
() => CombineWorker().execute(
|
||||||
() {
|
() {
|
||||||
final err = _box
|
final err = _box
|
||||||
.restart(configPath.toNativeUtf8().cast())
|
.restart(
|
||||||
|
configPath.toNativeUtf8().cast(),
|
||||||
|
disableMemoryLimit ? 1 : 0,
|
||||||
|
)
|
||||||
.cast<Utf8>()
|
.cast<Utf8>()
|
||||||
.toDartString();
|
.toDartString();
|
||||||
if (err.isNotEmpty) {
|
if (err.isNotEmpty) {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class MobileSingboxService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<String, Unit> start(String configPath) {
|
TaskEither<String, Unit> start(String configPath, bool disableMemoryLimit) {
|
||||||
return TaskEither(
|
return TaskEither(
|
||||||
() async {
|
() async {
|
||||||
loggy.debug("starting");
|
loggy.debug("starting");
|
||||||
@@ -98,7 +98,7 @@ class MobileSingboxService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<String, Unit> restart(String configPath) {
|
TaskEither<String, Unit> restart(String configPath, bool disableMemoryLimit) {
|
||||||
return TaskEither(
|
return TaskEither(
|
||||||
() async {
|
() async {
|
||||||
loggy.debug("restarting");
|
loggy.debug("restarting");
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ abstract interface class SingboxService {
|
|||||||
|
|
||||||
TaskEither<String, Unit> changeConfigOptions(ConfigOptions options);
|
TaskEither<String, Unit> changeConfigOptions(ConfigOptions options);
|
||||||
|
|
||||||
TaskEither<String, Unit> start(String configPath);
|
TaskEither<String, Unit> start(String configPath, bool disableMemoryLimit);
|
||||||
|
|
||||||
TaskEither<String, Unit> stop();
|
TaskEither<String, Unit> stop();
|
||||||
|
|
||||||
TaskEither<String, Unit> restart(String configPath);
|
TaskEither<String, Unit> restart(String configPath, bool disableMemoryLimit);
|
||||||
|
|
||||||
Stream<String> watchOutbounds();
|
Stream<String> watchOutbounds();
|
||||||
|
|
||||||
|
|||||||
2
libcore
2
libcore
Submodule libcore updated: 7b367fe70c...57b239c0f3
Reference in New Issue
Block a user