mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Add plugin init. Update plugin signature.
This commit is contained in:
@@ -25,6 +25,11 @@ func main() {
|
||||
generate.NewSubCommandFunction("icons", "Generate icons", commands.GenerateIcons)
|
||||
generate.NewSubCommandFunction("syso", "Generate Windows .syso file", commands.GenerateSyso)
|
||||
generate.NewSubCommandFunction("bindings", "Generate bindings + models", commands.GenerateBindings)
|
||||
plugin := app.NewSubCommand("plugin", "Plugin tools")
|
||||
//plugin.NewSubCommandFunction("list", "List plugins", commands.PluginList)
|
||||
plugin.NewSubCommandFunction("init", "Initialise a new plugin", commands.PluginInit)
|
||||
//plugin.NewSubCommandFunction("add", "Add a plugin", commands.PluginAdd)
|
||||
|
||||
err := app.Run()
|
||||
if err != nil {
|
||||
pterm.Error.Println(err)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
module plugin_demo
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/wailsapp/wails/v3 v3.0.0-alpha.0
|
||||
|
||||
require (
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/leaanthony/slicer v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/samber/lo v1.37.0 // indirect
|
||||
github.com/wailsapp/mimetype v1.4.1 // indirect
|
||||
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6 // indirect
|
||||
golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 // indirect
|
||||
golang.org/x/net v0.7.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/wailsapp/wails/v3 => ../..
|
||||
|
||||
replace github.com/wailsapp/wails/v2 => ../../../v2
|
||||
@@ -0,0 +1,33 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0HtY=
|
||||
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
|
||||
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw=
|
||||
github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
|
||||
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
|
||||
golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 h1:RjggHMcaTVp0LOVZcW0bo8alwHrOaCrGUDgfWUHhnN4=
|
||||
golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
||||
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
@@ -5,28 +5,12 @@ import (
|
||||
_ "embed"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"log"
|
||||
"math/rand"
|
||||
"plugin_demo/plugins/hashes"
|
||||
)
|
||||
|
||||
//go:embed assets/*
|
||||
var assets embed.FS
|
||||
|
||||
type RandomNumberPlugin struct{}
|
||||
|
||||
func (r *RandomNumberPlugin) Shutdown() {}
|
||||
|
||||
func (r *RandomNumberPlugin) Name() string {
|
||||
return "Random Number Plugin"
|
||||
}
|
||||
|
||||
func (r *RandomNumberPlugin) Init(_ *application.App) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RandomNumberPlugin) RandInt() int {
|
||||
return rand.Intn(100)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
app := application.New(application.Options{
|
||||
@@ -36,7 +20,7 @@ func main() {
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
Plugins: map[string]application.Plugin{
|
||||
"random": &RandomNumberPlugin{},
|
||||
"hashes": hashes.NewPlugin(),
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
FS: assets,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# Hashes Plugin
|
||||
|
||||
This example plugin provides a way to generate hashes of strings.
|
||||
|
||||
## Usage
|
||||
|
||||
Add the plugin to the `Plugins` option in the Applications options:
|
||||
|
||||
```go
|
||||
Plugins: map[string]application.Plugin{
|
||||
"hashes": hashes.NewPlugin(),
|
||||
},
|
||||
```
|
||||
|
||||
You can then call the Generate method from the frontend:
|
||||
|
||||
```js
|
||||
wails.Plugin("hashes","Generate","hello world").then((result) => console.log(result))
|
||||
```
|
||||
|
||||
This method returns a struct with the following fields:
|
||||
|
||||
```typescript
|
||||
interface Hashes {
|
||||
md5: string;
|
||||
sha1: string;
|
||||
sha256: string;
|
||||
}
|
||||
```
|
||||
|
||||
A TypeScript definition file is provided for this interface.
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
export namespace HashesPlugin {
|
||||
export interface Hashes {
|
||||
md5: string;
|
||||
sha1: string;
|
||||
sha256: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Generate takes a string and returns a number of hashes for it
|
||||
export function Generate(input) {
|
||||
return wails.Plugin("hashes","Generate",input);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package hashes
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
// ---------------- Plugin Setup ----------------
|
||||
|
||||
type Plugin struct{}
|
||||
|
||||
func NewPlugin() *Plugin {
|
||||
return &Plugin{}
|
||||
}
|
||||
|
||||
func (r *Plugin) Shutdown() {}
|
||||
|
||||
func (r *Plugin) Name() string {
|
||||
return "Hashes Plugin"
|
||||
}
|
||||
|
||||
func (r *Plugin) Init(_ *application.App) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---------------- Plugin Methods ----------------
|
||||
|
||||
type Hashes struct {
|
||||
MD5 string `json:"md5"`
|
||||
SHA1 string `json:"sha1"`
|
||||
SHA256 string `json:"sha256"`
|
||||
}
|
||||
|
||||
func (r *Plugin) Generate(s string) Hashes {
|
||||
md5Hash := md5.Sum([]byte(s))
|
||||
sha1Hash := sha1.Sum([]byte(s))
|
||||
sha256Hash := sha256.Sum256([]byte(s))
|
||||
|
||||
return Hashes{
|
||||
MD5: hex.EncodeToString(md5Hash[:]),
|
||||
SHA1: hex.EncodeToString(sha1Hash[:]),
|
||||
SHA256: hex.EncodeToString(sha256Hash[:]),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# This is the plugin definition file for the "Hashes" plugin.
|
||||
|
||||
Name = "Hashes"
|
||||
Description = "Provides a method to generate a number of hashes."
|
||||
Author = "Lea Anthony"
|
||||
Version = "v1.0.0"
|
||||
Website = "https://wails.io"
|
||||
License = "MIT"
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/internal/flags"
|
||||
"github.com/wailsapp/wails/v3/internal/plugins"
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
)
|
||||
|
||||
func toCamelCasePlugin(s string) string {
|
||||
var camelCase string
|
||||
var capitalize = true
|
||||
|
||||
for _, c := range s {
|
||||
if c >= 'a' && c <= 'z' || c >= '0' && c <= '9' {
|
||||
if capitalize {
|
||||
camelCase += strings.ToUpper(string(c))
|
||||
capitalize = false
|
||||
} else {
|
||||
camelCase += string(c)
|
||||
}
|
||||
} else if c >= 'A' && c <= 'Z' {
|
||||
camelCase += string(c)
|
||||
capitalize = false
|
||||
} else {
|
||||
capitalize = true
|
||||
}
|
||||
}
|
||||
|
||||
return camelCase + "Plugin"
|
||||
}
|
||||
|
||||
func PluginInit(options *flags.PluginInit) error {
|
||||
|
||||
if options.Quiet {
|
||||
pterm.DisableOutput()
|
||||
}
|
||||
|
||||
if options.PackageName == "" {
|
||||
options.PackageName = toCamelCasePlugin(options.Name)
|
||||
}
|
||||
|
||||
return plugins.Install(options)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package flags
|
||||
type Init struct {
|
||||
Common
|
||||
|
||||
PackageName string `name:"p" description:"Package name" default:"main"`
|
||||
TemplateName string `name:"t" description:"Name of built-in template to use, path to template or template url" default:"vanilla"`
|
||||
ProjectName string `name:"n" description:"Name of project" default:""`
|
||||
ProjectDir string `name:"d" description:"Project directory" default:"."`
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package flags
|
||||
|
||||
type PluginInit struct {
|
||||
Name string `name:"n" description:"Name of plugin" default:"example_plugin"`
|
||||
Description string `name:"d" description:"Description of plugin" default:"Example plugin"`
|
||||
PackageName string `name:"p" description:"Package name for plugin" default:""`
|
||||
OutputDir string `name:"o" description:"Output directory" default:"."`
|
||||
Quiet bool `name:"q" description:"Suppress output to console"`
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/wailsapp/wails/v3/internal/flags"
|
||||
|
||||
"github.com/leaanthony/gosod"
|
||||
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
//go:embed template
|
||||
var pluginTemplate embed.FS
|
||||
|
||||
type TemplateOptions struct {
|
||||
*flags.PluginInit
|
||||
}
|
||||
|
||||
func Install(options *flags.PluginInit) error {
|
||||
|
||||
if options.OutputDir == "." || options.OutputDir == "" {
|
||||
options.OutputDir = filepath.Join(lo.Must(os.Getwd()), options.Name)
|
||||
}
|
||||
fmt.Printf("Creating plugin '%s' into '%s'\n", options.Name, options.OutputDir)
|
||||
tfs, err := fs.Sub(pluginTemplate, "template")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return gosod.New(tfs).Extract(options.OutputDir, options)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
# Next Steps
|
||||
|
||||
Congratulations on generating a plugin. This guide will help you author your plugin
|
||||
and provide some tips on how to get started.
|
||||
|
||||
## Plugin Structure
|
||||
|
||||
The plugin is a standard Go module that adheres to the following interface:
|
||||
|
||||
```go
|
||||
type Plugin interface {
|
||||
Name() string
|
||||
Init(app *App) error
|
||||
Shutdown()
|
||||
}
|
||||
```
|
||||
|
||||
The `Name()` method returns the name of the plugin. It should follow the Go module naming convention
|
||||
and have a prefix of `wails-plugin-`, e.g. `github.com/myuser/wails-plugin-example`.
|
||||
|
||||
The `Init()` method is called when the plugin is loaded. The `App` parameter is a pointer to the
|
||||
main application struct. This may be used for showing dialogs, listening for events or even opening
|
||||
new windows. The `Init()` method should return an error if it fails to initialise. This method is
|
||||
called synchronously so the application will not start until it returns.
|
||||
|
||||
The `Shutdown()` method is called when the application is shutting down. This is a good place to
|
||||
perform any cleanup. This method is called synchronously so the application will not exit completely until
|
||||
it returns.
|
||||
|
||||
## Plugin Directory Structure
|
||||
|
||||
The plugin directory structure is as follows:
|
||||
|
||||
```
|
||||
plugin-name
|
||||
├── models.d.ts
|
||||
├── plugin.js
|
||||
├── plugin.go
|
||||
├── README.md
|
||||
├── go.mod
|
||||
├── go.sum
|
||||
└── plugin.toml
|
||||
```
|
||||
|
||||
### `plugin.go`
|
||||
|
||||
This file contains the plugin code. It should contain a struct that implements the `Plugin` interface
|
||||
and a `NewPlugin()` method that returns a pointer to the struct. Methods are exported by capitalising
|
||||
the first letter of the method name. These methods may be called from the frontend. If methods
|
||||
accept or return structs, these structs must be exported.
|
||||
|
||||
### `plugin.js`
|
||||
|
||||
This file should contain any JavaScript code that may help developers use the plugin.
|
||||
In the example plugin, this file contains function wrappers for the plugin methods.
|
||||
It's good to include JSDocs as that will help developers using your plugin.
|
||||
|
||||
### `models.d.ts`
|
||||
|
||||
This file should contain TypeScript definitions for any structs that are passed
|
||||
or returned from the plugin.
|
||||
`
|
||||
### `plugin.toml`
|
||||
|
||||
This file contains the plugin metadata. It is important to fill this out correctly
|
||||
as it will be used by the Wails CLI.
|
||||
|
||||
### `README.md`
|
||||
|
||||
This file should contain a description of the plugin and how to use it. It should
|
||||
also contain a link to the plugin repository and how to report bugs.
|
||||
|
||||
### `go.mod` and `go.sum`
|
||||
|
||||
These are standard Go module files. The package name in `go.mod` should match the
|
||||
name of the plugin, e.g. `github.com/myuser/wails-plugin-example`.
|
||||
|
||||
## Promoting your Plugin
|
||||
|
||||
Once you have created your plugin, you should promote it on the Wails Discord server
|
||||
in the `#plugins` channel. You should also open a PR to promote your plugin on the Wails
|
||||
website. Update the `website/content/plugins.md` file and add your plugin to the list.
|
||||
@@ -0,0 +1,38 @@
|
||||
# {{.Name}} Plugin
|
||||
|
||||
This example plugin provides a way to generate hashes of strings.
|
||||
|
||||
## Installation
|
||||
|
||||
Add the plugin to the `Plugins` option in the Applications options:
|
||||
|
||||
```go
|
||||
Plugins: map[string]application.Plugin{
|
||||
"{{.Name}}": {{.Name}}.NewPlugin(),
|
||||
},
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
You can then call the methods from the frontend:
|
||||
|
||||
```js
|
||||
wails.Plugin("{{.Name}}","All","hello world").then((result) => console.log(result))
|
||||
```
|
||||
|
||||
This method returns a struct with the following fields:
|
||||
|
||||
```typescript
|
||||
interface Hashes {
|
||||
MD5: string;
|
||||
SHA1: string;
|
||||
SHA256: string;
|
||||
}
|
||||
```
|
||||
|
||||
A TypeScript definition file is provided for this interface.
|
||||
|
||||
## Support
|
||||
|
||||
If you find a bug in this plugin, please raise a ticket [here](https://github.com/plugin/repository).
|
||||
Please do not contact the Wails team for support.
|
||||
@@ -0,0 +1,13 @@
|
||||
module github.com/myuser/wails-plugin-{{.Name}}
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/wailsapp/wails/v3 v3.0.0-alpha.0
|
||||
|
||||
require (
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/leaanthony/slicer v1.5.0 // indirect
|
||||
github.com/wailsapp/mimetype v1.4.1 // indirect
|
||||
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6 // indirect
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0HtY=
|
||||
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
|
||||
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
|
||||
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
|
||||
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
|
||||
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6 h1:Wn+nhnS+VytzE0PegUzSh4T3hXJCtggKGD/4U5H9+wQ=
|
||||
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6/go.mod h1:zlNLI0E2c2qA6miiuAHtp0Bac8FaGH0tlhA19OssR/8=
|
||||
github.com/wailsapp/wails/v3 v3.0.0-alpha.0 h1:T5gqG98Xr8LBf69oxlPkhpsFD59w2SnqUZk6XHj8Zoc=
|
||||
github.com/wailsapp/wails/v3 v3.0.0-alpha.0/go.mod h1:OAfO5bP0TSUvCIHZYc6Dqfow/9RqxzHvYtmhWPpo1c0=
|
||||
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -0,0 +1,10 @@
|
||||
// models.d.ts
|
||||
// This file should contain any models that are used by the plugin.
|
||||
|
||||
export namespace {{.Name}}Plugin {
|
||||
export interface Hashes {
|
||||
MD5: string;
|
||||
SHA1: string;
|
||||
SHA256: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package github.com/myuser/wails-plugin-{{.PackageName}}
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
// ---------------- Plugin Setup ----------------
|
||||
// This is the main plugin struct. It can be named anything you like.
|
||||
// It must implement the application.Plugin interface.
|
||||
// Both the Init() and Shutdown() methods are called synchronously when the app starts and stops.
|
||||
|
||||
type Plugin struct{}
|
||||
|
||||
func NewPlugin() *Plugin {
|
||||
return &Plugin{}
|
||||
}
|
||||
|
||||
// Shutdown is called when the app is shutting down
|
||||
// You can use this to clean up any resources you have allocated
|
||||
func (r *Plugin) Shutdown() {}
|
||||
|
||||
// Name returns the name of the plugin
|
||||
// You should use the go module format here (e.g. github.com/myuser/myrepo)
|
||||
func (r *Plugin) Name() string {
|
||||
return "github.com/myuser/{{.Name}}"
|
||||
}
|
||||
|
||||
func (r *Plugin) Init(_ *application.App) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---------------- Plugin Methods ----------------
|
||||
// Plugin methods are just normal Go methods. You can add as many as you like.
|
||||
// The only requirement is that they are exported (start with a capital letter).
|
||||
// You can also return any type that is JSON serializable.
|
||||
// See https://golang.org/pkg/encoding/json/#Marshal for more information.
|
||||
|
||||
// Hashes contains all hashes of a string
|
||||
type Hashes struct {
|
||||
MD5 string
|
||||
SHA1 string
|
||||
SHA256 string
|
||||
}
|
||||
|
||||
// MD5 returns the MD5 hash of the given string
|
||||
func (r *Plugin) MD5(s string) string {
|
||||
md5Hash := md5.Sum([]byte(s))
|
||||
return hex.EncodeToString(md5Hash[:])
|
||||
}
|
||||
|
||||
// SHA1 returns the SHA1 hash of the given string
|
||||
func (r *Plugin) SHA1(s string) string {
|
||||
sha1Hash := sha1.Sum([]byte(s))
|
||||
return hex.EncodeToString(sha1Hash[:])
|
||||
}
|
||||
|
||||
// SHA256 returns the SHA256 hash of the given string
|
||||
func (r *Plugin) SHA256(s string) string {
|
||||
sha256Hash := sha256.Sum256([]byte(s))
|
||||
return hex.EncodeToString(sha256Hash[:])
|
||||
}
|
||||
|
||||
// All returns all hashes of the given string
|
||||
// This is an example of returning a struct from a plugin method.
|
||||
func (r *Plugin) All(s string) Hashes {
|
||||
return Hashes{
|
||||
MD5: r.MD5(s),
|
||||
SHA1: r.SHA1(s),
|
||||
SHA256: r.SHA256(s),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// plugin.js
|
||||
// This file should contain helper functions for the that can be used by the frontend.
|
||||
// Below are examples of how to use JSDoc to define the Hashes struct and the exported functions.
|
||||
|
||||
/**
|
||||
* @typedef {Object} Hashes - A collection of hashes.
|
||||
* @property {string} md5 - The MD5 hash of a string, represented as a hexadecimal string.
|
||||
* @property {string} sha1 - The SHA-1 hash of a string, represented as a hexadecimal string.
|
||||
* @property {string} sha256 - The SHA-256 hash of a string, represented as a hexadecimal string.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate all hashes for a string.
|
||||
* @param input {string} - The string to generate hashes for.
|
||||
* @returns {Promise<Hashes>}
|
||||
*/
|
||||
export function All(input) {
|
||||
return wails.Plugin("{{.Name}}", "All", input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the MD5 hash for a string.
|
||||
* @param input {string} - The string to generate the hash for.
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function MD5(input) {
|
||||
return wails.Plugin("{{.Name}}", "MD5", input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the SHA-1 hash for a string.
|
||||
* @param input {string} - The string to generate the hash for.
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function SHA1(input) {
|
||||
return wails.Plugin("{{.Name}}", "SHA1", input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the SHA-256 hash for a string.
|
||||
* @param input {string} - The string to generate the hash for.
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function SHA256(input) {
|
||||
return wails.Plugin("{{.Name}}", "SHA256", input);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user