Ejemplo n.º 1
0
func main() {
	err := dbus.InstallOnSystem(&LanguageSelector{})
	if err != nil {
		print("Can't Init LanguageSelector DBus Servier: " + err.Error())
		return
	}
	dbus.DealWithUnhandledMessage()
	dbus.Wait()
}
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)
	}
}