Add option to linger after copy (might be useful under X11)

This commit is contained in:
Andreas Schneider 2021-03-06 14:33:29 +01:00
parent e3e64309b6
commit 82e8d971d8
1 changed files with 19 additions and 1 deletions

20
main.go
View File

@ -5,7 +5,9 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"log"
"sync" "sync"
"time"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/app"
@ -19,7 +21,8 @@ import (
//go:embed data/gitmojis.json data/images //go:embed data/gitmojis.json data/images
var data embed.FS var data embed.FS
var preferredTheme = flag.String("theme", "light", "Specifiy the theme to be used. dark/light") var preferredTheme = flag.String("theme", "light", "Specify the theme to be used. dark/light")
var linger = flag.String("linger", "", "If specified, linger for the given duration (e.g. 10s) before actually closing.")
type Gitmoji struct { type Gitmoji struct {
Emoji string Emoji string
@ -64,12 +67,23 @@ func main() {
} }
a := app.New() a := app.New()
switch *preferredTheme { switch *preferredTheme {
case "dark": case "dark":
a.Settings().SetTheme(theme.DarkTheme()) a.Settings().SetTheme(theme.DarkTheme())
default: default:
a.Settings().SetTheme(theme.LightTheme()) a.Settings().SetTheme(theme.LightTheme())
} }
var lingerDuration *time.Duration = nil
if *linger != "" {
if d, err := time.ParseDuration(*linger); err != nil {
log.Fatalf("invalid linger time: %v\n", err)
} else {
lingerDuration = &d
}
}
w := a.NewWindow("Gitmoji Picker") w := a.NewWindow("Gitmoji Picker")
w.CenterOnScreen() w.CenterOnScreen()
@ -192,6 +206,10 @@ func main() {
if currentId > -1 { if currentId > -1 {
w.Clipboard().SetContent(currentEntries[currentId].Emoji) w.Clipboard().SetContent(currentEntries[currentId].Emoji)
if lingerDuration != nil {
w.Hide()
time.Sleep(*lingerDuration)
}
w.Close() w.Close()
return true return true
} }