Skip to content

Commit

Permalink
Fix icon issues for python plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Dec 23, 2024
1 parent 7a584c8 commit 4524f16
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 19 deletions.
4 changes: 4 additions & 0 deletions wox.core/plugin/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (w *WoxImage) String() string {
return fmt.Sprintf("%s:%s", w.ImageType, w.ImageData)
}

func (w *WoxImage) IsEmpty() bool {
return w.ImageData == ""
}

func (w *WoxImage) ToPng() (image.Image, error) {
if w.ImageType == WoxImageTypeBase64 {
if !strings.HasPrefix(w.ImageData, "data:image/png;") {
Expand Down
8 changes: 4 additions & 4 deletions wox.core/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (m *Manager) PolishResult(ctx context.Context, pluginInstance *Instance, qu
if result.Actions[actionIndex].Id == "" {
result.Actions[actionIndex].Id = uuid.NewString()
}
if result.Actions[actionIndex].Icon.ImageType == "" {
if result.Actions[actionIndex].Icon.IsEmpty() {
// set default action icon if not present
result.Actions[actionIndex].Icon = DefaultActionIcon
}
Expand Down Expand Up @@ -589,7 +589,7 @@ func (m *Manager) PolishResult(ctx context.Context, pluginInstance *Instance, qu

// store preview for ui invoke later
// because preview may contain some heavy data (E.g. image or large text), we will store preview in cache and only send preview to ui when user select the result
if result.Preview.PreviewType != "" && result.Preview.PreviewData != "" && result.Preview.PreviewType != WoxPreviewTypeRemote {
if !result.Preview.IsEmpty() && result.Preview.PreviewType != WoxPreviewTypeRemote {
resultCache.Preview = result.Preview
result.Preview = WoxPreview{
PreviewType: WoxPreviewTypeRemote,
Expand Down Expand Up @@ -696,7 +696,7 @@ func (m *Manager) polishRefreshableResult(ctx context.Context, resultCache *Quer
if result.Actions[actionIndex].Id == "" {
result.Actions[actionIndex].Id = uuid.NewString()
}
if result.Actions[actionIndex].Icon.ImageType == "" {
if result.Actions[actionIndex].Icon.IsEmpty() {
// set default action icon if not present
result.Actions[actionIndex].Icon = DefaultActionIcon
}
Expand Down Expand Up @@ -760,7 +760,7 @@ func (m *Manager) polishRefreshableResult(ctx context.Context, resultCache *Quer
// convert non-remote preview to remote preview
// because preview may contain some heavy data (E.g. image or large text),
// we will store preview in cache and only send preview to ui when user select the result
if result.Preview.PreviewType != "" && result.Preview.PreviewType != WoxPreviewTypeRemote {
if !result.Preview.IsEmpty() && result.Preview.PreviewType != WoxPreviewTypeRemote {
resultCache.Preview = result.Preview
result.Preview = WoxPreview{
PreviewType: WoxPreviewTypeRemote,
Expand Down
4 changes: 4 additions & 0 deletions wox.core/plugin/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ type WoxPreview struct {
PreviewProperties map[string]string // key support i18n
ScrollPosition WoxPreviewScrollPosition
}

func (p *WoxPreview) IsEmpty() bool {
return p.PreviewData == ""
}
2 changes: 1 addition & 1 deletion wox.core/plugin/system/websearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (r *WebSearchPlugin) Init(ctx context.Context, initParams plugin.InitParams
func (r *WebSearchPlugin) indexIcons(ctx context.Context) {
hasAnyIconIndexed := false
for i, search := range r.webSearches {
if search.Icon.ImageType == "" {
if search.Icon.IsEmpty() {
r.webSearches[i].Icon = r.indexWebSearchIcon(ctx, search)
hasAnyIconIndexed = true
}
Expand Down
2 changes: 1 addition & 1 deletion wox.plugin.host.python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "README.md"
requires-python = ">=3.10"
license = "GPL-3.0"
authors = [{ name = "Wox Team", email = "qianlifeng@gmail.com" }]
dependencies = ["loguru", "websockets", "wox-plugin==0.0.47"]
dependencies = ["loguru", "websockets", "wox-plugin==0.0.48"]

[project.scripts]
run = "wox_plugin_host.__main__:run"
Expand Down
14 changes: 7 additions & 7 deletions wox.plugin.host.python/src/wox_plugin_host/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ async def query(ctx: Context, request: Dict[str, Any]) -> list[dict[str, Any]]:
"Id": result.id,
"Title": result.title,
"SubTitle": result.sub_title,
"Icon": result.icon,
"Icon": json.loads(result.icon.to_json()),
"Actions": [
{
"Id": action.id,
"Name": action.name,
"Icon": action.icon,
"Icon": json.loads(action.icon.to_json()),
"IsDefault": action.is_default,
"PreventHideAfterAction": action.prevent_hide_after_action,
"Hotkey": action.hotkey,
Expand All @@ -183,7 +183,7 @@ async def query(ctx: Context, request: Dict[str, Any]) -> list[dict[str, Any]]:
"Score": result.score,
"Group": result.group,
"GroupScore": result.group_score,
"Tails": result.tails,
"Tails": [json.loads(tail.to_json()) for tail in result.tails],
"ContextData": result.context_data,
"RefreshInterval": result.refresh_interval,
}
Expand Down Expand Up @@ -264,16 +264,16 @@ async def refresh(ctx: Context, request: Dict[str, Any]) -> dict[str, Any]:
return {
"Title": refreshed_result.title,
"SubTitle": refreshed_result.sub_title,
"Icon": refreshed_result.icon,
"Preview": refreshed_result.preview,
"Tails": refreshed_result.tails,
"Icon": json.loads(refreshed_result.icon.to_json()),
"Preview": json.loads(refreshed_result.preview.to_json()),
"Tails": [json.loads(tail.to_json()) for tail in refreshed_result.tails],
"ContextData": refreshed_result.context_data,
"RefreshInterval": refreshed_result.refresh_interval,
"Actions": [
{
"Id": action.id,
"Name": action.name,
"Icon": action.icon,
"Icon": json.loads(action.icon.to_json()),
"IsDefault": action.is_default,
"PreventHideAfterAction": action.prevent_hide_after_action,
"Hotkey": action.hotkey,
Expand Down
8 changes: 4 additions & 4 deletions wox.plugin.host.python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wox.plugin.python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "wox-plugin"
version = "0.0.47"
version = "0.0.48"
description = "Python plugin SDK for Wox launcher"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion wox.plugin.python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4524f16

Please sign in to comment.