diff --git a/.gitignore b/.gitignore index 4c51c87..e004695 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +secure-editor-go + # ---> macOS # General .DS_Store diff --git a/main.go b/main.go index 8cd471c..d145cb1 100644 --- a/main.go +++ b/main.go @@ -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