chg: framgnet option

This commit is contained in:
hiddify
2024-09-29 00:20:27 +02:00
parent 67646530ac
commit b0a1f3d349
3 changed files with 5 additions and 284 deletions

View File

@@ -1,279 +0,0 @@
package extension_repository
import (
"context"
"fmt"
"strconv"
"time"
ex "github.com/hiddify/hiddify-core/extension"
ui "github.com/hiddify/hiddify-core/extension/ui_elements"
)
// Field name constants
const (
CountKey = "countKey"
InputKey = "inputKey"
PasswordKey = "passwordKey"
EmailKey = "emailKey"
SelectKey = "selectKey"
TextAreaKey = "textareaKey"
SwitchKey = "switchKey"
CheckboxKey = "checkboxKey"
RadioboxKey = "radioboxKey"
ContentKey = "contentKey"
)
type ExampleExtension struct {
ex.BaseExtension
cancel context.CancelFunc
input string
password string
email string
selected bool
textarea string
switchVal bool
// checkbox string
radiobox string
content string
count int
}
func NewExampleExtension() ex.Extension {
return &ExampleExtension{
input: "default",
password: "123456",
email: "app@hiddify.com",
selected: false,
textarea: "area",
switchVal: true,
// checkbox: "B",
radiobox: "A",
content: "Welcome to Example Extension",
count: 10,
}
}
func (e *ExampleExtension) GetId() string {
return "example"
}
func (e *ExampleExtension) GetTitle() string {
return "Example Extension"
}
func (e *ExampleExtension) GetDescription() string {
return "This is a sample extension."
}
func (e *ExampleExtension) GetUI() ui.Form {
// e.setFormData(data)
return e.buildForm()
}
func (e *ExampleExtension) setFormData(data map[string]string) error {
if val, ok := data[CountKey]; ok {
if intValue, err := strconv.Atoi(val); err == nil {
e.count = intValue
} else {
return err
}
}
if val, ok := data[InputKey]; ok {
e.input = val
}
if val, ok := data[PasswordKey]; ok {
e.password = val
}
if val, ok := data[EmailKey]; ok {
e.email = val
}
if val, ok := data[SelectKey]; ok {
if selectedValue, err := strconv.ParseBool(val); err == nil {
e.selected = selectedValue
} else {
return err
}
}
if val, ok := data[TextAreaKey]; ok {
e.textarea = val
}
if val, ok := data[SwitchKey]; ok {
if selectedValue, err := strconv.ParseBool(val); err == nil {
e.switchVal = selectedValue
} else {
return err
}
}
// if val, ok := data[CheckboxKey]; ok {
// e.checkbox = val
// }
if val, ok := data[ContentKey]; ok {
e.content = val
}
if val, ok := data[RadioboxKey]; ok {
e.radiobox = val
}
return nil
}
func (e *ExampleExtension) buildForm() ui.Form {
return ui.Form{
Title: "Example Form",
Description: "This is a sample form.",
ButtonMode: ui.Button_SubmitCancel,
Fields: []ui.FormField{
{
Type: ui.FieldInput,
Key: CountKey,
Label: "Count",
Placeholder: "This will be the count",
Required: true,
Value: fmt.Sprintf("%d", e.count),
Validator: ui.ValidatorDigitsOnly,
},
{
Type: ui.FieldInput,
Key: InputKey,
Label: "Hi Group",
Placeholder: "Hi Group flutter",
Required: true,
Value: e.input,
},
{
Type: ui.FieldPassword,
Key: PasswordKey,
Label: "Password",
Required: true,
Value: e.password,
},
{
Type: ui.FieldEmail,
Key: EmailKey,
Label: "Email Label",
Placeholder: "Enter your email",
Required: true,
Value: e.email,
},
{
Type: ui.FieldSwitch,
Key: SelectKey,
Label: "Select Label",
Value: strconv.FormatBool(e.selected),
},
{
Type: ui.FieldTextArea,
Key: TextAreaKey,
Label: "TextArea Label",
Placeholder: "Enter your text",
Required: true,
Value: e.textarea,
},
{
Type: ui.FieldSwitch,
Key: SwitchKey,
Label: "Switch Label",
Value: strconv.FormatBool(e.switchVal),
},
// {
// Type: ui.Checkbox,
// Key: CheckboxKey,
// Label: "Checkbox Label",
// Required: true,
// Value: e.checkbox,
// Items: []ui.SelectItem{
// {
// Label: "A",
// Value: "A",
// },
// {
// Label: "B",
// Value: "B",
// },
// },
// },
{
Type: ui.FieldRadioButton,
Key: RadioboxKey,
Label: "Radio Label",
Required: true,
Value: e.radiobox,
Items: []ui.SelectItem{
{
Label: "A",
Value: "A",
},
{
Label: "B",
Value: "B",
},
},
},
{
Type: ui.FieldTextArea,
Readonly: true,
Key: ContentKey,
Label: "Content",
Value: e.content,
Lines: 10,
Monospace: true,
HorizontalScroll: true,
VerticalScroll: true,
},
},
}
}
func (e *ExampleExtension) backgroundTask(ctx context.Context) {
i := 1
for {
select {
case <-ctx.Done():
e.content = strconv.Itoa(i) + " Background task stop...\n" + e.content
e.UpdateUI(e.buildForm())
fmt.Println("Background task stopped")
return
case <-time.After(1000 * time.Millisecond):
txt := strconv.Itoa(i) + " Background task working..."
e.content = txt + "\n" + e.content
e.UpdateUI(e.buildForm())
fmt.Println(txt)
}
i++
}
}
func (e *ExampleExtension) SubmitData(data map[string]string) error {
err := e.setFormData(data)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
e.cancel = cancel
go e.backgroundTask(ctx)
return nil
}
func (e *ExampleExtension) Cancel() error {
if e.cancel != nil {
e.cancel()
e.cancel = nil
}
return nil
}
func (e *ExampleExtension) Stop() error {
if e.cancel != nil {
e.cancel()
e.cancel = nil
}
return nil
}
func init() {
ex.RegisterExtension("com.example.extension", NewExampleExtension())
}

6
go.mod
View File

@@ -6,13 +6,11 @@ toolchain go1.22.3
require (
github.com/bepass-org/warp-plus v1.2.4
github.com/fatih/color v1.16.0
github.com/hiddify/hiddify-app-example-extension v0.0.0-20240928185410-086adbcac1bb
github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240928194626-7f6dde034dfe
github.com/improbable-eng/grpc-web v0.15.0
github.com/jellydator/validation v1.1.0
github.com/kardianos/service v1.2.2
github.com/rodaine/table v1.1.1
github.com/sagernet/gomobile v0.1.4
github.com/sagernet/sing v0.4.3
github.com/sagernet/sing-box v1.8.9
@@ -28,10 +26,12 @@ require (
require (
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/metacubex/tfo-go v0.0.0-20240821025650-e9be0afd5e7d // indirect
github.com/rodaine/table v1.1.1 // indirect
github.com/rs/cors v1.7.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
nhooyr.io/websocket v1.8.6 // indirect
@@ -142,4 +142,4 @@ replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0
replace github.com/bepass-org/warp-plus => github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d
replace github.com/hiddify/ray2sing => github.com/hiddify/ray2sing v0.0.0-20240928214231-84f7ecbfdaa2
replace github.com/hiddify/ray2sing => github.com/hiddify/ray2sing v0.0.0-20240928221833-190b549d5222

4
go.sum
View File

@@ -243,8 +243,8 @@ github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240928194626-7f6dde034d
github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240928194626-7f6dde034dfe/go.mod h1:9Fjoaxn2gbFQioxwdb06Kaz4kfFV7nxS0TJ/+IlDWvg=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20240928213625-7b79bf0c814d h1:+jTGlmOl+Kt3JEU1pt5yIItpi6nKKqUIUf76jkONHgQ=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20240928213625-7b79bf0c814d/go.mod h1:2Cozqb5uVY/y0c/HWZ57CfE6fZwjmik/J3tWynsjjDA=
github.com/hiddify/ray2sing v0.0.0-20240928214231-84f7ecbfdaa2 h1:dHtBmUOIe71peOA5ANiExaGosIiJKX/Ysfgql7jMa/4=
github.com/hiddify/ray2sing v0.0.0-20240928214231-84f7ecbfdaa2/go.mod h1:Qp3mFdKsJZ5TwBYLREgWp8n2O6dgmNt3aAoX+xpvnsM=
github.com/hiddify/ray2sing v0.0.0-20240928221833-190b549d5222 h1:+MFxFxoWCA44WhqIixqL/Zkt4DwnqhQvafS0Dm4+dKM=
github.com/hiddify/ray2sing v0.0.0-20240928221833-190b549d5222/go.mod h1:cFEg1b0eBgL9kBgIPAD71lHO1Q5g20PZL4dUGhQpAO8=
github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d h1:vRGKh9ou+/vQGfVYa8MczhbIVjHxlP52OWwrDWO77RA=
github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d/go.mod h1:uSRUbr1CcvFrEV69FTvuJFwpzEmwO8N4knb6+Zq3Ys4=
github.com/hiddify/wireguard-go v0.0.0-20240727191222-383c1da14ff1 h1:xdbHlZtzs+jijAxy85qal835GglwmjohA/srHT8gm9s=