diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/Settings.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/Settings.kt index c841ddeff..62e2743a5 100644 --- a/android/app/src/main/kotlin/com/hiddify/hiddify/Settings.kt +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/Settings.kt @@ -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()) diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/constant/ServiceMode.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/constant/ServiceMode.kt index 3a0fc4873..f86de8a10 100644 --- a/android/app/src/main/kotlin/com/hiddify/hiddify/constant/ServiceMode.kt +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/constant/ServiceMode.kt @@ -1,6 +1,6 @@ package com.hiddify.hiddify.constant object ServiceMode { - const val NORMAL = "normal" + const val NORMAL = "proxy" const val VPN = "vpn" } \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/constant/SettingsKey.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/constant/SettingsKey.kt index 96782ad83..c331b5dad 100644 --- a/android/app/src/main/kotlin/com/hiddify/hiddify/constant/SettingsKey.kt +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/constant/SettingsKey.kt @@ -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" } \ No newline at end of file diff --git a/lib/core/preferences/preferences_migration.dart b/lib/core/preferences/preferences_migration.dart index c02b108a4..ec0d63d96 100644 --- a/lib/core/preferences/preferences_migration.dart +++ b/lib/core/preferences/preferences_migration.dart @@ -48,6 +48,20 @@ class PreferencesVersion1Migration extends PreferencesMigrationStep @override Future 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)}]", diff --git a/lib/singbox/model/singbox_config_enum.dart b/lib/singbox/model/singbox_config_enum.dart index a7da0a569..67f7be47e 100644 --- a/lib/singbox/model/singbox_config_enum.dart +++ b/lib/singbox/model/singbox_config_enum.dart @@ -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;