feat: v0.1.1, support version and readonly
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
secure-editor-go
|
||||||
|
|
||||||
# ---> macOS
|
# ---> macOS
|
||||||
# General
|
# General
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
32
main.go
32
main.go
@@ -15,8 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AlgorithmAes256Gcm = "aes-256-gcm"
|
Version = "0.1.1"
|
||||||
Title = "Secure Editor"
|
Title = "Secure Editor"
|
||||||
|
AlgorithmAes256Gcm = "aes-256-gcm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func decrypt(ciphertext, key, nonce []byte) ([]byte, error) {
|
func decrypt(ciphertext, key, nonce []byte) ([]byte, error) {
|
||||||
@@ -69,8 +70,17 @@ func showErrorMessage(err error, parent fyne.Window) {
|
|||||||
dialog.ShowError(err, parent)
|
dialog.ShowError(err, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isReadonly() bool {
|
||||||
|
return os.Getenv("READONLY") == "true"
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args
|
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 {
|
if len(args) != 5 {
|
||||||
fmt.Printf("Bad encrypt args: %v\n", args)
|
fmt.Printf("Bad encrypt args: %v\n", args)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -113,6 +123,8 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isReadonly := isReadonly()
|
||||||
|
|
||||||
secureEditorApp := app.New()
|
secureEditorApp := app.New()
|
||||||
window := secureEditorApp.NewWindow(Title)
|
window := secureEditorApp.NewWindow(Title)
|
||||||
window.Resize(fyne.NewSize(800, 600))
|
window.Resize(fyne.NewSize(800, 600))
|
||||||
@@ -123,7 +135,16 @@ func main() {
|
|||||||
textEntry := widget.NewMultiLineEntry()
|
textEntry := widget.NewMultiLineEntry()
|
||||||
textEntry.Wrapping = fyne.TextWrapWord
|
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() {
|
exitButton := widget.NewButton(" [ Exit ] ", func() {
|
||||||
secureEditorApp.Quit()
|
secureEditorApp.Quit()
|
||||||
@@ -143,9 +164,14 @@ func main() {
|
|||||||
secureEditorApp.Quit()
|
secureEditorApp.Quit()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
buttons := container.NewHBox(exitButton, saveButton)
|
||||||
|
if isReadonly {
|
||||||
|
buttons = container.NewHBox(exitButton)
|
||||||
|
}
|
||||||
|
|
||||||
content := container.NewBorder(
|
content := container.NewBorder(
|
||||||
nil, // top
|
nil, // top
|
||||||
container.NewBorder(nil, nil, nil, container.NewHBox(exitButton, saveButton), nil), // bottom
|
container.NewBorder(nil, nil, nil, buttons, nil), // bottom
|
||||||
nil, // left
|
nil, // left
|
||||||
nil, // right
|
nil, // right
|
||||||
textEntry, // center
|
textEntry, // center
|
||||||
|
|||||||
Reference in New Issue
Block a user