mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-16 00:49:32 +08:00
43 lines
818 B
Go
43 lines
818 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
|
|
wails "github.com/wailsapp/wails/v2"
|
|
"github.com/wailsapp/wails/v2/pkg/options"
|
|
)
|
|
|
|
type Notepad struct {
|
|
runtime *wails.Runtime
|
|
}
|
|
|
|
func (n *Notepad) WailsInit(runtime *wails.Runtime) error {
|
|
n.runtime = runtime
|
|
return nil
|
|
}
|
|
|
|
// SaveNotes attempts to save the given notes to disk.
|
|
// Returns false if the user cancelled the save, true on
|
|
// successful save.
|
|
func (n *Notepad) SaveNotes(notes string) (bool, error) {
|
|
|
|
selectedFile := n.runtime.Dialog.Save(&options.SaveDialog{
|
|
DefaultFilename: "notes.md",
|
|
Filters: "*.md",
|
|
})
|
|
|
|
// Check if the user pressed cancel
|
|
if selectedFile == "" {
|
|
// Cancelled
|
|
return false, nil
|
|
}
|
|
|
|
// Save notes
|
|
err := ioutil.WriteFile(selectedFile, []byte(notes), 0700)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|