✨ Add option to linger after copy (might be useful under X11)
This commit is contained in:
parent
e3e64309b6
commit
82e8d971d8
20
main.go
20
main.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue