Skip to content

Commit

Permalink
Add 'summary' command to Browser plugin
Browse files Browse the repository at this point in the history
This update adds a 'summary' command to the Browser plugin, providing a summary of the content of the currently active Browser URL. The command will return with an error message if there is no active browser URL. A conditions check whether the plugin's query is executed within a browser has been added.
  • Loading branch information
qianlifeng committed May 23, 2024
1 parent 56a0f02 commit 499ec2e
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Wox/plugin/system/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"wox/plugin"
"wox/setting/definition"
"wox/setting/validator"
"wox/share"
"wox/util"
)

Expand Down Expand Up @@ -64,9 +65,14 @@ func (c *BrowserPlugin) GetMetadata() plugin.Metadata {
Icon: browserIcon.String(),
Entry: "",
TriggerKeywords: []string{
"*",
"*", "browser",
},
Commands: []plugin.MetadataCommand{
{
Command: "summary",
Description: "Summary current active browser url content",
},
},
Commands: []plugin.MetadataCommand{},
SupportedOS: []string{
"Windows",
"Macos",
Expand All @@ -77,6 +83,7 @@ func (c *BrowserPlugin) GetMetadata() plugin.Metadata {
Name: "queryEnv",
Params: map[string]string{
"requireActiveWindowName": "true",
"requireActiveBrowserUrl": "true",
},
},
},
Expand Down Expand Up @@ -125,8 +132,10 @@ func (c *BrowserPlugin) Init(ctx context.Context, initParams plugin.InitParams)
}

func (c *BrowserPlugin) Query(ctx context.Context, query plugin.Query) (results []plugin.QueryResult) {
if query.IsGlobalQuery() {
if strings.ToLower(query.Env.ActiveWindowTitle) == "google chrome" {
isInBrowser := strings.ToLower(query.Env.ActiveWindowTitle) == "google chrome"

if isInBrowser {
if query.IsGlobalQuery() {
for _, tab := range c.openedTabs {
isTitleMatched, titleScore := IsStringMatchScore(ctx, tab.Title, query.Search)
isUrlMatched, urlScore := strings.Contains(tab.Url, query.Search), int64(1)
Expand Down Expand Up @@ -164,6 +173,23 @@ func (c *BrowserPlugin) Query(ctx context.Context, query plugin.Query) (results
})
}
}

if query.Command == "summary" {
if query.Env.ActiveBrowserUrl == "" {
return []plugin.QueryResult{
{
Title: "No active browser url",
SubTitle: "Please open a browser tab",
Icon: browserIcon,
},
}
}

c.api.ChangeQuery(ctx, share.PlainQuery{
QueryType: plugin.QueryTypeInput,
QueryText: "llm tldr " + query.Env.ActiveBrowserUrl,
})
}
}

return results
Expand Down

0 comments on commit 499ec2e

Please sign in to comment.