This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
/
main.go
120 lines (96 loc) · 3.25 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
/**
* Copyright (C) 2015 Deepin Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
**/
package main
// #cgo pkg-config: gtk+-3.0
// #include <gtk/gtk.h>
// void GtkInit() { gtk_init(NULL, NULL); }
import "C"
import (
"os"
"gir/glib-2.0"
"pkg.deepin.io/dde/api/session"
"pkg.deepin.io/lib"
dapp "pkg.deepin.io/lib/app"
"pkg.deepin.io/lib/dbus"
"pkg.deepin.io/lib/initializer/v2"
"pkg.deepin.io/lib/profile"
"pkg.deepin.io/lib/proxy"
"pkg.deepin.io/service/file-manager-backend/clipboard"
"pkg.deepin.io/service/file-manager-backend/desktop"
"pkg.deepin.io/service/file-manager-backend/fileinfo"
. "pkg.deepin.io/service/file-manager-backend/log"
"pkg.deepin.io/service/file-manager-backend/monitor"
)
func main() {
// change current working directory to desktop.
os.Chdir(desktop.GetDesktopDir())
timer := profile.NewTimer()
app := dapp.New("deepin-file-manager-backend", "the backend of deepin file manager", "version "+__VERSION__)
app.ParseCommandLine(os.Args[1:])
Log.SetLogLevel(app.LogLevel())
app.StartProfile()
Log.Debug("Parse command line...ok, cost", timer.Elapsed())
proxy.SetupProxy()
Log.Info("initialize operation backend...")
operationBackend := NewOperationBackend()
info := operationBackend.GetDBusInfo()
if !lib.UniqueOnSession(info.Dest) {
Log.Info("already exists a session bus named", info.Dest)
os.Exit(1)
}
err := initializer.DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("ok, cost", timer.Elapsed())
return operationBackend, nil
}).Do(func() error {
Log.Info("initialize gtk...")
C.GtkInit()
Log.Info("ok, cost", timer.Elapsed())
Log.Info("initialize i18n...")
InitI18n()
Log.Info("ok, cost", timer.Elapsed())
return nil
}).DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("initialize operation flags dbus interface...")
return NewOperationFlags(), nil
}).DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("ok, cost", timer.Elapsed())
Log.Info("initialize monitor manager...")
return monitor.NewMonitorManager(), nil
}).DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("ok, cost", timer.Elapsed())
Log.Info("initialize trash monitor...")
return monitor.NewTrashMonitor()
}).DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("ok, cost", timer.Elapsed())
Log.Info("initialize file info...")
return fileinfo.NewQueryFileInfoJob(), nil
}).DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("ok, cost", timer.Elapsed())
Log.Info("initialize Clipboard...")
return clipboard.NewClipboard(), nil
}).DoWithSessionBus(func() (dbus.DBusObject, error) {
Log.Info("ok, cost", timer.Elapsed())
Log.Info("initialize desktop daemon...")
return desktop.NewDesktopDaemon()
}).GetError()
Log.Debug("register session...")
session.Register()
Log.Info("ok, cost", timer.Elapsed())
if err != nil {
Log.Info("Failed:", err)
os.Exit(1)
}
go glib.StartLoop()
dbus.DealWithUnhandledMessage()
Log.Info("Total cost", timer.TotalCost())
if err := dbus.Wait(); err != nil {
Log.Info(err)
os.Exit(2)
}
}