-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (53 loc) · 1.44 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"github.com/Dnnd/sway-menus/dmenu"
"github.com/Dnnd/sway-menus/dmenu/rofi"
"github.com/Dnnd/sway-menus/dmenu/wofi"
"github.com/Dnnd/sway-menus/logind"
"github.com/Dnnd/sway-menus/powermenu"
"github.com/Dnnd/sway-menus/window"
"log"
"os"
)
func main() {
mode := flag.String("mode", "window", "mode")
var configFile string
flag.StringVar(&configFile, "config", "", "path to config file")
flag.Parse()
if configFile == "" {
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
if xdgConfigHome == "" {
xdgConfigHome = os.Getenv("HOME") + "/.config"
}
var configDir = xdgConfigHome + "/sway_menus"
configFile = configDir + "/config.toml"
}
config, err := LoadConfig(configFile)
if err != nil {
log.Fatal(err)
}
var menuFactory dmenu.MenuFactory
if config.Launcher == "rofi" {
menuFactory = rofi.MenuFactory{}
} else if config.Launcher == "wofi" {
menuFactory = wofi.MenuFactory{}
} else {
log.Fatal("unknown launcher")
}
if *mode == "window" {
switcher := window.NewSwitcherService(menuFactory.NewMenuPresenter())
if err := switcher.Run(); err != nil {
log.Fatal(err)
}
} else if *mode == "powermenu" {
logindManager, err := logind.ConnectToLogindManager()
if err != nil {
log.Fatal(err)
}
powermenuService := powermenu.NewPowerMenuService(config.Powermenu, &logindManager, menuFactory.NewMenuPresenter())
if err := powermenuService.Run(); err != nil {
log.Fatal(err)
}
}
}