forked from linuxdeepin/startdde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
198 lines (165 loc) · 4.16 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// SPDX-FileCopyrightText: 2014 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import "C"
import (
"flag"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"time"
dbus "github.com/godbus/dbus/v5"
x "github.com/linuxdeepin/go-x11-client"
"github.com/linuxdeepin/startdde/display"
// "github.com/linuxdeepin/startdde/watchdog"
"github.com/linuxdeepin/go-lib/dbusutil"
"github.com/linuxdeepin/go-lib/gettext"
"github.com/linuxdeepin/go-lib/gsettings"
"github.com/linuxdeepin/go-lib/log"
"github.com/linuxdeepin/go-lib/proxy"
wl_display "github.com/linuxdeepin/startdde/wl_display"
"github.com/linuxdeepin/startdde/xsettings"
)
var logger = log.NewLogger("startdde")
var _gSettingsConfig *GSettingsConfig
var globalCgExecBin string
var globalXSManager *xsettings.XSManager
var _xConn *x.Conn
var _useWayland bool
var _useKWin bool
func init() {
}
func reapZombies() {
// We must reap children process even we hasn't create anyone at this moment,
// Because the startdde may be launched by exec syscall
// in another existed process, like /usr/sbin/lighdm-session does.
// NOTE: Don't use signal.Ignore(syscall.SIGCHILD), otherwise os/exec wouldn't work properly.
// And simply ignore SIGCHILD hasn't any helpful in here.
for {
pid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil)
if err != nil || pid == 0 {
break
}
}
}
var _mainBeginTime time.Time
func logDebugAfter(msg string) {
elapsed := time.Since(_mainBeginTime)
logger.Debugf("after %s, %s", elapsed, msg)
}
func logInfoAfter(msg string) {
elapsed := time.Since(_mainBeginTime)
logger.Infof("after %s, %s", elapsed, msg)
}
func greeterDisplayMain() {
display.SetGreeterMode(true)
// init x conn
xConn, err := x.NewConn()
if err != nil {
logger.Warning(err)
os.Exit(1)
}
// TODO
display.Init(xConn, false)
logger.Debug("greeter mode")
service, err := dbusutil.NewSessionService()
if err != nil {
logger.Warning(err)
}
err = display.Start(service)
if err != nil {
logger.Warning(err)
}
err = display.StartPart2()
if err != nil {
logger.Warning(err)
}
service.Wait()
}
func main() {
flag.Parse()
if len(os.Args) > 0 && strings.HasPrefix(filepath.Base(os.Args[0]), "greeter") {
// os.Args[0] 应该一般是 greeter-display-daemon
greeterDisplayMain()
return
}
initGSettingsConfig()
_mainBeginTime = time.Now()
gettext.InitI18n()
gettext.BindTextdomainCodeset("startdde", "UTF-8")
gettext.Textdomain("startdde")
reapZombies()
// init x conn
xConn, err := x.NewConn()
if err != nil {
logger.Warning(err)
os.Exit(1)
}
_xConn = xConn
var recommendedScaleFactor float64
if os.Getenv("WAYLAND_DISPLAY") != "" {
logger.Info("in wayland mode")
_useWayland = true
}
display.Init(xConn, _useWayland)
// TODO
recommendedScaleFactor = display.GetRecommendedScaleFactor()
service, err := dbusutil.NewSessionService()
if err != nil {
logger.Warning(err)
os.Exit(1)
}
xsManager, err := xsettings.Start(xConn, recommendedScaleFactor, service, &display.ScaleFactorsHelper)
if err != nil {
logger.Warning(err)
} else {
globalXSManager = xsManager
}
sessionManager := newSessionManager(service)
err = display.Start(service)
if err != nil {
logger.Warning("start display part1 failed:", err)
}
// 启动 display 模块的后一部分
go func() {
err := display.StartPart2()
if err != nil {
logger.Warning("start display part2 failed:", err)
}
}()
go func() {
initSoundThemePlayer()
playLoginSound()
}()
err = gsettings.StartMonitor()
if err != nil {
logger.Warning("gsettings start monitor failed:", err)
}
proxy.SetupProxy()
sysBus, err := dbus.SystemBus()
if err != nil {
logger.Warning(err)
os.Exit(1)
}
sysSignalLoop := dbusutil.NewSignalLoop(sysBus, 10)
sysSignalLoop.Start()
sessionManager.start(xConn, sysSignalLoop, service)
go func() {
logger.Info("systemd-notify --ready")
cmd := exec.Command("systemd-notify", "--ready")
cmd.Run()
}()
service.Wait()
}
func doSetLogLevel(level log.Priority) {
logger.SetLogLevel(level)
if !_useWayland {
display.SetLogLevel(level)
} else {
wl_display.SetLogLevel(level)
}
// watchdog.SetLogLevel(level)
}