mirror of https://github.com/Wox-launcher/Wox
feat(system): add ID field to SysCommand and update command handling
* Introduced an `ID` field to the `SysCommand` struct for better command identification. * Updated command initialization in `Init` method to include unique IDs for each command. * Modified context data handling to use `CommandID` instead of `CommandTitle` for command lookup. * Enhanced error messages to reflect the use of command IDs.
This commit is contained in:
parent
38929cc506
commit
d6a2af6f94
|
@ -28,6 +28,7 @@ type SysPlugin struct {
|
|||
}
|
||||
|
||||
type SysCommand struct {
|
||||
ID string
|
||||
Title string
|
||||
SubTitle string
|
||||
Icon common.WoxImage
|
||||
|
@ -36,7 +37,7 @@ type SysCommand struct {
|
|||
}
|
||||
|
||||
type sysContextData struct {
|
||||
CommandTitle string `json:"commandTitle"`
|
||||
CommandID string `json:"commandId"`
|
||||
}
|
||||
|
||||
func (r *SysPlugin) GetMetadata() plugin.Metadata {
|
||||
|
@ -72,6 +73,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
r.api = initParams.API
|
||||
r.commands = []SysCommand{
|
||||
{
|
||||
ID: "lock_computer",
|
||||
Title: "i18n:plugin_sys_lock_computer",
|
||||
Icon: plugin.LockIcon,
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -84,6 +86,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
},
|
||||
},
|
||||
{
|
||||
ID: "empty_trash",
|
||||
Title: "i18n:plugin_sys_empty_trash",
|
||||
Icon: plugin.TrashIcon,
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -96,6 +99,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
},
|
||||
},
|
||||
{
|
||||
ID: "quit_wox",
|
||||
Title: "i18n:plugin_sys_quit_wox",
|
||||
Icon: plugin.ExitIcon,
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -103,6 +107,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
},
|
||||
},
|
||||
{
|
||||
ID: "open_wox_settings",
|
||||
Title: "i18n:plugin_sys_open_wox_settings",
|
||||
PreventHideAfterAction: true,
|
||||
Icon: plugin.WoxIcon,
|
||||
|
@ -111,6 +116,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
},
|
||||
},
|
||||
{
|
||||
ID: "open_system_settings",
|
||||
Title: "i18n:plugin_sys_open_system_settings",
|
||||
Icon: plugin.SettingIcon,
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -126,6 +132,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
|
||||
if util.IsDev() {
|
||||
r.commands = append(r.commands, SysCommand{
|
||||
ID: "cpu_profiling",
|
||||
Title: "i18n:plugin_sys_performance_cpu_profiling",
|
||||
Icon: plugin.CPUProfileIcon,
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -151,6 +158,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
})
|
||||
|
||||
r.commands = append(r.commands, SysCommand{
|
||||
ID: "memory_profiling",
|
||||
Title: "i18n:plugin_sys_performance_memory_profiling",
|
||||
Icon: plugin.CPUProfileIcon,
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -173,6 +181,7 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
})
|
||||
|
||||
r.commands = append(r.commands, SysCommand{
|
||||
ID: "delete_image_cache",
|
||||
Title: "i18n:plugin_sys_delete_image_cache",
|
||||
Icon: common.NewWoxImageEmoji("🗑️"),
|
||||
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||
|
@ -197,7 +206,7 @@ func (r *SysPlugin) Query(ctx context.Context, query plugin.Query) (results []pl
|
|||
|
||||
if isTitleMatch {
|
||||
contextData := sysContextData{
|
||||
CommandTitle: command.Title,
|
||||
CommandID: command.ID,
|
||||
}
|
||||
contextDataJson, _ := json.Marshal(contextData)
|
||||
|
||||
|
@ -261,17 +270,17 @@ func (r *SysPlugin) handleMRURestore(mruData plugin.MRUData) (*plugin.QueryResul
|
|||
return nil, fmt.Errorf("failed to parse context data: %w", err)
|
||||
}
|
||||
|
||||
// Find the command by title
|
||||
// Find the command by ID
|
||||
var foundCommand *SysCommand
|
||||
for _, command := range r.commands {
|
||||
if command.Title == contextData.CommandTitle {
|
||||
if command.ID == contextData.CommandID {
|
||||
foundCommand = &command
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if foundCommand == nil {
|
||||
return nil, fmt.Errorf("system command no longer exists: %s", contextData.CommandTitle)
|
||||
return nil, fmt.Errorf("system command no longer exists: %s", contextData.CommandID)
|
||||
}
|
||||
|
||||
result := &plugin.QueryResult{
|
||||
|
|
|
@ -111,6 +111,12 @@ func serializeValue(value interface{}) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
// Use reflection to check if it's a string-based type
|
||||
rv := reflect.ValueOf(value)
|
||||
if rv.Kind() == reflect.String {
|
||||
return rv.String(), nil
|
||||
}
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
return v, nil
|
||||
|
|
|
@ -505,6 +505,12 @@ func (m *Manager) PostSettingUpdate(ctx context.Context, key string, value any)
|
|||
for _, queryHotkey := range queryHotkeys {
|
||||
m.RegisterQueryHotkey(ctx, queryHotkey)
|
||||
}
|
||||
case "LangCode":
|
||||
langCode := value.(string)
|
||||
langErr := i18n.GetI18nManager().UpdateLang(ctx, i18n.LangCode(langCode))
|
||||
if langErr != nil {
|
||||
logger.Error(ctx, fmt.Sprintf("failed to update lang: %s", langErr.Error()))
|
||||
}
|
||||
case "EnableAutostart":
|
||||
enabled := value.(bool)
|
||||
err := autostart.SetAutostart(ctx, enabled)
|
||||
|
|
|
@ -243,7 +243,7 @@ class WoxListController<T> extends GetxController {
|
|||
|
||||
var score = weightedRatio(queryText, filterText.toLowerCase());
|
||||
// Logger.instance.debug(traceId, "calculate fuzzy match score, queryText: $queryText, filterText: $filterText, score: $score");
|
||||
return score > 50;
|
||||
return score > 60;
|
||||
}
|
||||
|
||||
String transferChineseToPinYin(String str) {
|
||||
|
|
Loading…
Reference in New Issue