Files
umbrix-libcore/mobile/mobile.go

43 lines
1.0 KiB
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"
"path/filepath"
2023-08-19 14:09:49 +03:30
2024-01-15 17:17:05 +03:30
"github.com/hiddify/libcore/config"
2023-12-21 11:10:14 +03:30
_ "github.com/sagernet/gomobile"
2023-08-19 14:09:49 +03:30
"github.com/sagernet/sing-box/option"
2023-08-16 15:16:02 +03:30
)
2023-09-22 23:25:38 +03:30
func Parse(path string, tempPath string, debug bool) error {
2024-01-15 17:59:45 +03:30
config, err := config.ParseConfig(tempPath, debug)
if err != nil {
return err
}
2024-01-29 21:55:01 +01:00
return os.WriteFile(path, config, 0644)
2023-08-19 14:09:49 +03:30
}
2023-09-01 14:52:30 +03:30
func BuildConfig(path string, configOptionsJson string) (string, error) {
os.Chdir(filepath.Dir(path))
2023-08-19 14:09:49 +03:30
fileContent, err := os.ReadFile(path)
if err != nil {
return "", err
}
var options option.Options
err = options.UnmarshalJSON(fileContent)
if err != nil {
return "", err
}
2024-01-15 17:17:05 +03:30
configOptions := &config.ConfigOptions{}
2023-09-01 14:52:30 +03:30
err = json.Unmarshal([]byte(configOptionsJson), configOptions)
if err != nil {
return "", nil
2023-08-22 00:54:58 +03:30
}
2024-01-15 17:17:05 +03:30
return config.BuildConfigJson(*configOptions, options)
2023-08-16 15:16:02 +03:30
}
2024-02-18 12:31:17 +03:30
func GenerateWarpConfig(licenseKey string, accountId string, accessToken string) (string, error) {
return config.GenerateWarpAccount(licenseKey, accountId, accessToken)
}