This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
95 lines (78 loc) · 2.03 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"github.com/neversun/Slackfish/settings"
slack "github.com/neversun/Slackfish/slack"
qml "gopkg.in/qml.v1"
)
const (
// Appname is the package name
Appname = "harbour-slackfish"
)
// SlackfishControl is exported to QML and enables interaction with API
type SlackfishControl struct {
Root qml.Object
Slack *slack.Model
ChannelsModel *slack.Channels
SettingsModel *settings.Settings
MessagesModel *slack.Messages
UsersModel *slack.Users
ImChannelsModel *slack.IMs
}
func main() {
if err := qml.SailfishRun(run); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(1)
}
}
func run() error {
ss := &settings.Settings{}
slackfish := SlackfishControl{
Slack: &slack.Slack,
ChannelsModel: &slack.Slack.Channels,
SettingsModel: ss,
MessagesModel: &slack.Slack.Messages,
UsersModel: &slack.Slack.Users,
ImChannelsModel: &slack.Slack.IMs,
}
engine := qml.SailfishNewEngine()
path, err := getPath()
if err != nil {
panic(err)
}
dataDir := filepath.Join(path, ".local", "share", Appname)
set := settings.Settings{Location: filepath.Join(dataDir, "settings.yml")}
slackfish.SettingsModel = &set
if err = slackfish.SettingsModel.Load(); err != nil {
log.Printf("WARN: %+v\n", err)
}
// TODO: implement translation
// engine.Translator("/usr/share/harbour-slackfish/qml/i18n")
context := engine.Context()
context.SetVar("slackfishctrl", &slackfish)
// publish direct bindings to public members of slackfish
context.SetVars(&slackfish)
controls, err := engine.SailfishSetSource("qml/" + Appname + ".qml")
if err != nil {
return err
}
window := controls.SailfishCreateWindow()
slackfish.Root = window.Root()
window.SailfishShow()
window.Wait()
return nil
}
func getPath() (string, error) {
path := os.Getenv("XDG_DATA_HOME")
if len(path) == 0 {
path = os.Getenv("HOME")
if len(path) == 0 {
return "", errors.New("No XDG_DATA or HOME env set")
}
}
return path, nil
}