Files
umbrix-libcore/mobile/mobile.go

36 lines
817 B
Go
Raw Normal View History

2023-08-16 15:16:02 +03:30
package mobile
import (
2023-08-19 14:09:49 +03:30
"encoding/json"
"os"
2023-08-16 15:16:02 +03:30
"github.com/hiddify/libcore/shared"
_ "github.com/sagernet/gomobile/event/key"
2023-08-19 14:09:49 +03:30
"github.com/sagernet/sing-box/option"
2023-08-16 15:16:02 +03:30
)
2023-08-19 14:09:49 +03:30
func Parse(path string) error {
return shared.ParseConfig(path)
}
func ApplyOverrides(path string) (string, error) {
fileContent, err := os.ReadFile(path)
if err != nil {
return "", err
}
var options option.Options
err = options.UnmarshalJSON(fileContent)
if err != nil {
return "", err
}
2023-08-22 00:54:58 +03:30
overrides := shared.ConfigOverrides{
EnableTun: shared.BoolAddr(true),
SetSystemProxy: shared.BoolAddr(false),
LogOutput: shared.StringAddr(""),
}
template := shared.DefaultTemplate(overrides)
options = shared.ApplyOverrides(template, options, overrides)
2023-08-19 14:09:49 +03:30
config, err := json.Marshal(options)
2023-08-16 15:16:02 +03:30
return string(config), err
}