Skip to content

Commit

Permalink
Get current status when program starts
Browse files Browse the repository at this point in the history
  • Loading branch information
3e849f2e5c committed Jan 29, 2020
1 parent 614046d commit 1a32b5e
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@ import (
"os"
)

func getStatus () string {
var connection, err= dbus.ConnectSessionBus()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
obj := connection.Object("org.fcitx.Fcitx", "/Status")
call := obj.Call("org.fcitx.Fcitx.Status.Get", 0, "mozc-composition-mode")
if call.Err != nil {
fmt.Println(call.Err)
os.Exit(1)
}

if len(call.Body) >= 1 && call.Body[0] != "" {
return formatLetter(call.Body[0].(string))
} else {
return "あ"
}
}

func main() {
var connection, err = dbus.ConnectSessionBus()
var connection, err= dbus.ConnectSessionBus()
if err != nil {
fmt.Println("Bruh " + err.Error())
fmt.Println(err.Error())
os.Exit(1)
}

Expand All @@ -28,25 +48,28 @@ func main() {
var messages = make(chan *dbus.Message)
connection.Eavesdrop(messages)

var oldMode = "あ"
var oldMode = getStatus()

fmt.Println(oldMode)
for v := range messages {
if len(v.Body) >= 3 {
var newMode = v.Body[1].(string)
if oldMode != newMode {
switch newMode {
case "A":
fmt.Println("A")
break
case "ア":
fmt.Println("ア\u2423")
break
default:
fmt.Println(newMode)
}
oldMode = newMode
var mode = formatLetter(newMode)
fmt.Println(mode)
oldMode = mode
}
}
}
}

func formatLetter (letter string) string {
switch letter {
case "A":
return "A"
case "ア":
return "ア\u2423"
default:
return letter
}
}

0 comments on commit 1a32b5e

Please sign in to comment.