Fix service mode
This commit is contained in:
@@ -12,7 +12,6 @@ import java.io.ByteArrayInputStream
|
||||
import java.io.File
|
||||
import java.io.ObjectInputStream
|
||||
|
||||
|
||||
object Settings {
|
||||
|
||||
private val preferences by lazy {
|
||||
@@ -67,9 +66,6 @@ object Settings {
|
||||
get() = preferences.getBoolean(SettingsKey.DEBUG_MODE, false)
|
||||
set(value) = preferences.edit().putBoolean(SettingsKey.DEBUG_MODE, value).apply()
|
||||
|
||||
val enableTun: Boolean
|
||||
get() = preferences.getBoolean(SettingsKey.ENABLE_TUN, true)
|
||||
|
||||
var disableMemoryLimit: Boolean
|
||||
get() = preferences.getBoolean(SettingsKey.DISABLE_MEMORY_LIMIT, false)
|
||||
set(value) =
|
||||
@@ -112,7 +108,7 @@ object Settings {
|
||||
}
|
||||
|
||||
private suspend fun needVPNService(): Boolean {
|
||||
if (enableTun) return true
|
||||
if (serviceMode == ServiceMode.VPN) return true
|
||||
val filePath = activeConfigPath
|
||||
if (filePath.isBlank()) return false
|
||||
val content = JSONObject(File(filePath).readText())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hiddify.hiddify.constant
|
||||
|
||||
object ServiceMode {
|
||||
const val NORMAL = "normal"
|
||||
const val NORMAL = "proxy"
|
||||
const val VPN = "vpn"
|
||||
}
|
||||
@@ -3,18 +3,15 @@ package com.hiddify.hiddify.constant
|
||||
object SettingsKey {
|
||||
private const val KEY_PREFIX = "flutter."
|
||||
|
||||
const val SERVICE_MODE = "${KEY_PREFIX}service-mode"
|
||||
const val ACTIVE_CONFIG_PATH = "${KEY_PREFIX}active_config_path"
|
||||
const val ACTIVE_PROFILE_NAME = "${KEY_PREFIX}active_profile_name"
|
||||
const val SERVICE_MODE = "${KEY_PREFIX}service_mode"
|
||||
|
||||
const val CONFIG_OPTIONS = "config_options_json"
|
||||
|
||||
const val PER_APP_PROXY_MODE = "${KEY_PREFIX}per_app_proxy_mode"
|
||||
const val PER_APP_PROXY_INCLUDE_LIST = "${KEY_PREFIX}per_app_proxy_include_list"
|
||||
const val PER_APP_PROXY_EXCLUDE_LIST = "${KEY_PREFIX}per_app_proxy_exclude_list"
|
||||
|
||||
const val DEBUG_MODE = "${KEY_PREFIX}debug_mode"
|
||||
const val ENABLE_TUN = "${KEY_PREFIX}enable-tun"
|
||||
const val DISABLE_MEMORY_LIMIT = "${KEY_PREFIX}disable_memory_limit"
|
||||
const val DYNAMIC_NOTIFICATION = "${KEY_PREFIX}dynamic_notification"
|
||||
const val SYSTEM_PROXY_ENABLED = "${KEY_PREFIX}system_proxy_enabled"
|
||||
@@ -22,5 +19,6 @@ object SettingsKey {
|
||||
// cache
|
||||
|
||||
const val STARTED_BY_USER = "${KEY_PREFIX}started_by_user"
|
||||
const val CONFIG_OPTIONS = "config_options_json"
|
||||
|
||||
}
|
||||
@@ -48,6 +48,20 @@ class PreferencesVersion1Migration extends PreferencesMigrationStep
|
||||
|
||||
@override
|
||||
Future<void> migrate() async {
|
||||
if (sharedPreferences.getString("service-mode")
|
||||
case final String serviceMode) {
|
||||
final newMode = switch (serviceMode) {
|
||||
"proxy" || "system-proxy" || "vpn" => serviceMode,
|
||||
"systemProxy" => "system-proxy",
|
||||
"tun" => "vpn",
|
||||
_ => PlatformUtils.isDesktop ? "system-proxy" : "vpn",
|
||||
};
|
||||
loggy.debug(
|
||||
"changing service-mode from [$serviceMode] to [$newMode]",
|
||||
);
|
||||
await sharedPreferences.setString("service-mode", newMode);
|
||||
}
|
||||
|
||||
if (sharedPreferences.getString("ipv6-mode") case final String ipv6Mode) {
|
||||
loggy.debug(
|
||||
"changing ipv6-mode from [$ipv6Mode] to [${_ipv6Mapper(ipv6Mode)}]",
|
||||
|
||||
@@ -2,10 +2,15 @@ import 'package:hiddify/core/localization/translations.dart';
|
||||
import 'package:hiddify/utils/platform_utils.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
@JsonEnum(valueField: 'key')
|
||||
enum ServiceMode {
|
||||
proxy,
|
||||
systemProxy,
|
||||
tun;
|
||||
proxy("proxy"),
|
||||
systemProxy("system-proxy"),
|
||||
tun("vpn");
|
||||
|
||||
const ServiceMode(this.key);
|
||||
|
||||
final String key;
|
||||
|
||||
static ServiceMode get defaultMode =>
|
||||
PlatformUtils.isDesktop ? systemProxy : tun;
|
||||
|
||||
Reference in New Issue
Block a user