feat: v0.1.1, support version and readonly

This commit is contained in:
2025-09-14 10:46:24 +08:00
parent e9213c740d
commit d82a8df7e0
2 changed files with 31 additions and 3 deletions

32
main.go
View File

@@ -15,8 +15,9 @@ import (
)
const (
AlgorithmAes256Gcm = "aes-256-gcm"
Version = "0.1.1"
Title = "Secure Editor"
AlgorithmAes256Gcm = "aes-256-gcm"
)
func decrypt(ciphertext, key, nonce []byte) ([]byte, error) {
@@ -69,8 +70,17 @@ func showErrorMessage(err error, parent fyne.Window) {
dialog.ShowError(err, parent)
}
func isReadonly() bool {
return os.Getenv("READONLY") == "true"
}
func main() {
args := os.Args
if len(args) == 2 && args[1] == "version" {
fmt.Printf("secure-editor-go version: %s\n", Version)
os.Exit(0)
}
if len(args) != 5 {
fmt.Printf("Bad encrypt args: %v\n", args)
os.Exit(1)
@@ -113,6 +123,8 @@ func main() {
os.Exit(1)
}
isReadonly := isReadonly()
secureEditorApp := app.New()
window := secureEditorApp.NewWindow(Title)
window.Resize(fyne.NewSize(800, 600))
@@ -123,7 +135,16 @@ func main() {
textEntry := widget.NewMultiLineEntry()
textEntry.Wrapping = fyne.TextWrapWord
textEntry.SetText(string(plaintext))
initialText := string(plaintext)
textEntry.SetText(initialText)
if isReadonly {
// textEntry.Disable() // TODO for font is grey
textEntry.OnChanged = func(text string) {
if text != initialText {
textEntry.SetText(initialText)
}
}
}
exitButton := widget.NewButton(" [ Exit ] ", func() {
secureEditorApp.Quit()
@@ -143,9 +164,14 @@ func main() {
secureEditorApp.Quit()
})
buttons := container.NewHBox(exitButton, saveButton)
if isReadonly {
buttons = container.NewHBox(exitButton)
}
content := container.NewBorder(
nil, // top
container.NewBorder(nil, nil, nil, container.NewHBox(exitButton, saveButton), nil), // bottom
container.NewBorder(nil, nil, nil, buttons, nil), // bottom
nil, // left
nil, // right
textEntry, // center