Major plugin updates

This commit is contained in:
Lea Anthony
2024-04-14 21:41:33 +10:00
parent cf130a6e25
commit c7ed7e72d4
52 changed files with 1155 additions and 326 deletions
+32
View File
@@ -0,0 +1,32 @@
# 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
import {Call} from "/wails/runtime.js";
Call.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.
+58
View File
@@ -0,0 +1,58 @@
package hashes
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"github.com/wailsapp/wails/v3/pkg/application"
"io/fs"
)
// ---------------- Plugin Setup ----------------
type Plugin struct{}
func NewPlugin() *Plugin {
return &Plugin{}
}
func (r *Plugin) Shutdown() error { return nil }
func (r *Plugin) Name() string {
return "Hashes Plugin"
}
func (r *Plugin) Init(api application.PluginAPI) error {
return nil
}
func (r *Plugin) CallableByJS() []string {
return []string{
"Generate",
}
}
func (r *Plugin) Assets() fs.FS {
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[:]),
}
}
+10
View File
@@ -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"