Change sharedpreferences to unify with android

This commit is contained in:
problematicconsumer
2023-09-09 12:07:39 +03:30
parent ac00873c70
commit f6da63ec90
5 changed files with 24 additions and 13 deletions

View File

@@ -57,7 +57,7 @@ class MethodHandler : FlutterPlugin, MethodChannel.MethodCallHandler {
Trigger.SetActiveConfigPath.method -> { Trigger.SetActiveConfigPath.method -> {
val args = call.arguments as Map<*, *> val args = call.arguments as Map<*, *>
Settings.selectedConfigPath = args["path"] as String? ?: "" Settings.activeConfigPath = args["path"] as String? ?: ""
result.success(true) result.success(true)
} }

View File

@@ -11,25 +11,31 @@ object Settings {
private val preferences by lazy { private val preferences by lazy {
val context = Application.application.applicationContext val context = Application.application.applicationContext
context.getSharedPreferences("preferences", Context.MODE_PRIVATE) context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
} }
var disableMemoryLimit = preferences.getBoolean(SettingsKey.DISABLE_MEMORY_LIMIT, false)
var perAppProxyEnabled = preferences.getBoolean(SettingsKey.PER_APP_PROXY_ENABLED, false) var perAppProxyEnabled = preferences.getBoolean(SettingsKey.PER_APP_PROXY_ENABLED, false)
var perAppProxyMode = preferences.getInt(SettingsKey.PER_APP_PROXY_MODE, PER_APP_PROXY_EXCLUDE) var perAppProxyMode = preferences.getInt(SettingsKey.PER_APP_PROXY_MODE, PER_APP_PROXY_EXCLUDE)
var perAppProxyList = preferences.getStringSet(SettingsKey.PER_APP_PROXY_LIST, emptySet())!! var perAppProxyList = preferences.getStringSet(SettingsKey.PER_APP_PROXY_LIST, emptySet())!!
var perAppProxyUpdateOnChange = var perAppProxyUpdateOnChange =
preferences.getInt(SettingsKey.PER_APP_PROXY_UPDATE_ON_CHANGE, PER_APP_PROXY_DISABLED) preferences.getInt(SettingsKey.PER_APP_PROXY_UPDATE_ON_CHANGE, PER_APP_PROXY_DISABLED)
var selectedConfigPath: String var activeConfigPath: String
get() = preferences.getString(SettingsKey.SELECTED_CONFIG_PATH, "") ?: "" get() = preferences.getString(SettingsKey.ACTIVE_CONFIG_PATH, "") ?: ""
set(value) = preferences.edit().putString(SettingsKey.SELECTED_CONFIG_PATH, value).apply() set(value) = preferences.edit().putString(SettingsKey.ACTIVE_CONFIG_PATH, value).apply()
var configOptions: String var configOptions: String
get() = preferences.getString(SettingsKey.CONFIG_OPTIONS, "") ?: "" get() = preferences.getString(SettingsKey.CONFIG_OPTIONS, "") ?: ""
set(value) = preferences.edit().putString(SettingsKey.CONFIG_OPTIONS, value).apply() set(value) = preferences.edit().putString(SettingsKey.CONFIG_OPTIONS, value).apply()
var disableMemoryLimit: Boolean
get() = preferences.getBoolean(SettingsKey.DISABLE_MEMORY_LIMIT, false)
set(value) = preferences.edit().putBoolean(SettingsKey.DISABLE_MEMORY_LIMIT, value).apply()
var systemProxyEnabled: Boolean
get() = preferences.getBoolean(SettingsKey.SYSTEM_PROXY_ENABLED, true)
set(value) = preferences.edit().putBoolean(SettingsKey.SYSTEM_PROXY_ENABLED, value).apply()
var startedByUser: Boolean var startedByUser: Boolean
get() = preferences.getBoolean(SettingsKey.STARTED_BY_USER, false) get() = preferences.getBoolean(SettingsKey.STARTED_BY_USER, false)
set(value) = preferences.edit().putBoolean(SettingsKey.STARTED_BY_USER, value).apply() set(value) = preferences.edit().putBoolean(SettingsKey.STARTED_BY_USER, value).apply()

View File

@@ -136,7 +136,7 @@ class BoxService(
try { try {
Log.d(TAG, "starting service") Log.d(TAG, "starting service")
val selectedConfigPath = Settings.selectedConfigPath val selectedConfigPath = Settings.activeConfigPath
if (selectedConfigPath.isBlank()) { if (selectedConfigPath.isBlank()) {
stopAndAlert(Alert.EmptyConfiguration) stopAndAlert(Alert.EmptyConfiguration)
return return

View File

@@ -33,7 +33,7 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
} }
var systemProxyAvailable = false var systemProxyAvailable = false
var systemProxyEnabled = true var systemProxyEnabled = false
override fun openTun(options: TunOptions): Int { override fun openTun(options: TunOptions): Int {
if (prepare(this) != null) error("android: missing vpn permission") if (prepare(this) != null) error("android: missing vpn permission")
@@ -128,7 +128,7 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
if (options.isHTTPProxyEnabled) { if (options.isHTTPProxyEnabled) {
systemProxyAvailable = true systemProxyAvailable = true
// systemProxyEnabled = Settings.systemProxyEnabled systemProxyEnabled = Settings.systemProxyEnabled
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (systemProxyEnabled) builder.setHttpProxy( if (systemProxyEnabled) builder.setHttpProxy(
ProxyInfo.buildDirectProxy( ProxyInfo.buildDirectProxy(

View File

@@ -1,17 +1,22 @@
package com.hiddify.hiddify.constant package com.hiddify.hiddify.constant
object SettingsKey { object SettingsKey {
const val SELECTED_CONFIG_PATH = "selected_config_path" private const val KEY_PREFIX = "flutter."
const val ACTIVE_CONFIG_PATH = "${KEY_PREFIX}active_config_path"
const val CONFIG_OPTIONS = "config_options_json" const val CONFIG_OPTIONS = "config_options_json"
const val DISABLE_MEMORY_LIMIT = "disable_memory_limit"
const val PER_APP_PROXY_ENABLED = "per_app_proxy_enabled" const val PER_APP_PROXY_ENABLED = "per_app_proxy_enabled"
const val PER_APP_PROXY_MODE = "per_app_proxy_mode" const val PER_APP_PROXY_MODE = "per_app_proxy_mode"
const val PER_APP_PROXY_LIST = "per_app_proxy_list" const val PER_APP_PROXY_LIST = "per_app_proxy_list"
const val PER_APP_PROXY_UPDATE_ON_CHANGE = "per_app_proxy_update_on_change" const val PER_APP_PROXY_UPDATE_ON_CHANGE = "per_app_proxy_update_on_change"
const val DISABLE_MEMORY_LIMIT = "${KEY_PREFIX}disable_memory_limit"
const val SYSTEM_PROXY_ENABLED = "${KEY_PREFIX}system_proxy_enabled"
// cache // cache
const val STARTED_BY_USER = "started_by_user" const val STARTED_BY_USER = "${KEY_PREFIX}started_by_user"
} }