Add config options
This commit is contained in:
@@ -19,6 +19,7 @@ class MethodHandler : FlutterPlugin, MethodChannel.MethodCallHandler {
|
||||
enum class Trigger(val method: String) {
|
||||
ParseConfig("parse_config"),
|
||||
SetActiveConfigPath("set_active_config_path"),
|
||||
ChangeConfigOptions("change_config_options"),
|
||||
Start("start"),
|
||||
Stop("stop"),
|
||||
SelectOutbound("select_outbound"),
|
||||
@@ -60,6 +61,14 @@ class MethodHandler : FlutterPlugin, MethodChannel.MethodCallHandler {
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
Trigger.ChangeConfigOptions.method -> {
|
||||
result.runCatching {
|
||||
val args = call.arguments as String
|
||||
Settings.configOptions = args
|
||||
success(true)
|
||||
}
|
||||
}
|
||||
|
||||
Trigger.Start.method -> {
|
||||
MainActivity.instance.startService()
|
||||
result.success(true)
|
||||
|
||||
@@ -26,6 +26,10 @@ object Settings {
|
||||
get() = preferences.getString(SettingsKey.SELECTED_CONFIG_PATH, "") ?: ""
|
||||
set(value) = preferences.edit().putString(SettingsKey.SELECTED_CONFIG_PATH, value).apply()
|
||||
|
||||
var configOptions: String
|
||||
get() = preferences.getString(SettingsKey.CONFIG_OPTIONS, "") ?: ""
|
||||
set(value) = preferences.edit().putString(SettingsKey.CONFIG_OPTIONS, value).apply()
|
||||
|
||||
var startedByUser: Boolean
|
||||
get() = preferences.getBoolean(SettingsKey.STARTED_BY_USER, false)
|
||||
set(value) = preferences.edit().putBoolean(SettingsKey.STARTED_BY_USER, value).apply()
|
||||
|
||||
@@ -132,8 +132,14 @@ class BoxService(
|
||||
return
|
||||
}
|
||||
|
||||
val configOptions = Settings.configOptions
|
||||
if (configOptions.isBlank()) {
|
||||
stopAndAlert(Alert.EmptyConfiguration)
|
||||
return
|
||||
}
|
||||
|
||||
val content = try {
|
||||
Mobile.applyOverrides(selectedConfigPath)
|
||||
Mobile.buildConfig(selectedConfigPath, configOptions)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, e)
|
||||
stopAndAlert(Alert.EmptyConfiguration)
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hiddify.hiddify.constant
|
||||
|
||||
object SettingsKey {
|
||||
const val SELECTED_CONFIG_PATH = "selected_config_path"
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user