Skip to content

Commit

Permalink
Add plugin setting update api
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Dec 1, 2023
1 parent 7f56f36 commit 6677bea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Wox/setting/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (m *Manager) loadWoxSetting(ctx context.Context) error {
if woxSetting.LastQueryMode == "" {
woxSetting.LastQueryMode = defaultWoxSetting.LastQueryMode
}
if woxSetting.AppWidth == 0 {
woxSetting.AppWidth = defaultWoxSetting.AppWidth
}
if woxSetting.ThemeId == "" {
woxSetting.ThemeId = defaultWoxSetting.ThemeId
}
Expand Down
6 changes: 5 additions & 1 deletion Wox/setting/wox_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ type WoxSetting struct {
QueryHotkeys PlatformSettingValue[[]QueryHotkey]
QueryShortcuts []QueryShortcut
LastQueryMode LastQueryMode
ThemeId string

// UI related
AppWidth int
ThemeId string
}

type LastQueryMode = string
Expand Down Expand Up @@ -77,6 +80,7 @@ func GetDefaultWoxSetting(ctx context.Context) WoxSetting {
HideOnLostFocus: true,
LangCode: langCode,
LastQueryMode: LastQueryModeEmpty,
AppWidth: 800,
ThemeId: "53c1d0a4-ffc8-4d90-91dc-b408fb0b9a03",
}
}
Expand Down
41 changes: 41 additions & 0 deletions Wox/ui/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,47 @@ func serveAndWait(ctx context.Context, port int) {
writeSuccessResponse(w, "")
})

mux.HandleFunc("/setting/plugin/update", func(w http.ResponseWriter, r *http.Request) {
type keyValuePair struct {
PluginId string
Key string
Value string
}

decoder := json.NewDecoder(r.Body)
var kv keyValuePair
err := decoder.Decode(&kv)
if err != nil {
w.Header().Set("code", "500")
w.Write([]byte(err.Error()))
return
}

pluginInstance, exist := lo.Find(plugin.GetPluginManager().GetPluginInstances(), func(item *plugin.Instance) bool {
if item.Metadata.Id == kv.PluginId {
return true
}
return false
})
if !exist {
w.Header().Set("code", "500")
w.Write([]byte("can't find plugin"))
return
}

if kv.Key == "Disabled" {
pluginInstance.Setting.Disabled = kv.Value == "true"
pluginInstance.SaveSetting(ctx)
} else if kv.Key == "TriggerKeywords" {
pluginInstance.Setting.TriggerKeywords = strings.Split(kv.Value, ",")
pluginInstance.SaveSetting(ctx)
} else {
pluginInstance.API.SaveSetting(util.NewTraceContext(), kv.Key, kv.Value, false)
}

writeSuccessResponse(w, "")
})

mux.HandleFunc("/open/url", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
urlResult := gjson.GetBytes(body, "url")
Expand Down

0 comments on commit 6677bea

Please sign in to comment.