-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
96 lines (70 loc) · 1.99 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
96
package main
import (
"log"
"os"
"runtime"
"github.com/gotk3/gotk3/gtk"
"github.com/jhekasoft/insteadman/core/configurator"
"github.com/jhekasoft/insteadman/core/interpreterfinder"
"github.com/jhekasoft/insteadman/core/manager"
"github.com/jhekasoft/insteadman/core/utils"
"github.com/jhekasoft/insteadman/gtk/i18n"
"github.com/jhekasoft/insteadman/gtk/osintegration"
"github.com/jhekasoft/insteadman/gtk/ui"
)
const (
title = "InsteadMan"
envDataPath = "DATA_PATH"
envLocalePath = "LOCALE_PATH"
i18nDomain = "insteadman"
)
var (
version = "3"
)
func main() {
runtime.LockOSThread()
// OS integrations
osintegration.OsIntegrate()
gtk.Init(nil)
executablePath, e := os.Executable()
if e != nil {
ui.ShowErrorDlgFatal(e.Error(), nil)
}
currentDir, e := utils.BinAbsDir(executablePath)
if e != nil {
ui.ShowErrorDlgFatal(e.Error(), nil)
}
dataPath := os.Getenv(envDataPath)
localePath := os.Getenv(envLocalePath)
cf := &configurator.Configurator{FilePath: "", CurrentDir: currentDir, DataPath: dataPath,
LocalePath: localePath, Version: version}
config, e := cf.GetConfig()
if e != nil {
ui.ShowErrorDlgFatal(e.Error(), nil)
}
finder := &interpreterfinder.InterpreterFinder{CurrentDir: currentDir}
mn := &manager.Manager{Config: config, InterpreterFinder: finder}
// I18n init
i18n.Init(cf.DataLocalePath(), i18nDomain, config.Lang)
mainWindow := ui.GetMain(mn, cf, title, version)
if mn.InterpreterCommand() == "" {
findInterpreter(mn, cf, mainWindow.Window)
}
ui.ShowExistingMainWindow(true)
gtk.Main()
}
func findInterpreter(m *manager.Manager, c *configurator.Configurator, wnd *gtk.Window) {
path := m.InterpreterFinder.Find()
if path == nil {
ui.ShowErrorDlg(i18n.T("INSTEAD has not found. Please add INSTEAD in the Settings."), wnd)
return
}
log.Printf("INSTEAD has found: %s", *path)
m.Config.InterpreterCommand = *path
e := c.SaveConfig(m.Config)
if e != nil {
ui.ShowErrorDlgFatal(e.Error(), wnd)
return
}
log.Print("Path has saved")
}