-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathinstance.go
57 lines (49 loc) · 2.05 KB
/
instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package plugin
import (
"context"
"wox/setting"
)
type Instance struct {
Plugin Plugin // plugin implementation
API API // APIs exposed to plugin
Metadata Metadata // metadata parsed from plugin.json
IsSystemPlugin bool // is system plugin, see `plugin.md` for more detail
IsDevPlugin bool // plugins loaded from `local plugin directories` which defined in wpm settings
DevPluginDirectory string // absolute path to dev plugin directory defined in wpm settings
PluginDirectory string // absolute path to plugin directory
Host Host // plugin host to run this plugin
Setting *setting.PluginSetting // setting for this plugin
DynamicSettingCallbacks []func(key string) string // dynamic setting callbacks
SettingChangeCallbacks []func(key string, value string)
DeepLinkCallbacks []func(arguments map[string]string)
UnloadCallbacks []func()
// for measure performance
LoadStartTimestamp int64
LoadFinishedTimestamp int64
InitStartTimestamp int64
InitFinishedTimestamp int64
}
// trigger keywords to trigger this plugin. Maybe user defined or pre-defined in plugin.json
func (i *Instance) GetTriggerKeywords() []string {
if i.Setting.TriggerKeywords != nil {
return i.Setting.TriggerKeywords
}
return i.Metadata.TriggerKeywords
}
// query commands to query this plugin. Maybe plugin author dynamical registered or pre-defined in plugin.json
func (i *Instance) GetQueryCommands() []MetadataCommand {
commands := i.Metadata.Commands
for _, command := range i.Setting.QueryCommands {
commands = append(commands, MetadataCommand{
Command: command.Command,
Description: command.Description,
})
}
return commands
}
func (i *Instance) String() string {
return i.Metadata.Name
}
func (i *Instance) SaveSetting(ctx context.Context) error {
return setting.GetSettingManager().SavePluginSetting(ctx, i.Metadata.Id, i.Setting)
}