コード例 #1
0
ファイル: startdock.go プロジェクト: sqp/godock
// Run starts dock routines and locks the main thread with gtk.
//
// It wraps all backends and clients to start a dock :
// Dbus server, applets manager, GUI, menu and gldi.
//
// Dbus service is enabled by default. Mandatory if enabled, to provide remote control.
// This will prevent launching a 2nd instance without the disable Dbus service option.
//
// You can add custom changes, launched before the start, with CustomHacks.
//
// Run returns true if the dock is able to start. This can be done with:
//   gldi.Lock()      // alias for gtk_main.
//   maindock.Clean() // may be better with defer, but cause confused panic messages.
//
func Run(log cdtype.Logger, getSettings func() maindock.DockSettings) bool {
	settings := getSettings()

	// Logger debug state.
	log.SetDebug(settings.Debug)
	maindock.SetLogger(log)

	// Dock init.
	settings.Init()

	// Load new config settings. New options are in an other file to keep the
	// original config file as compatible with the real dock as possible.
	file, e := globals.DirUserAppData(confown.GuiFilename)
	e = confown.Init(log, file, e)
	log.Err(e, "Load ConfigSettings")

	// Register go internal applets events.
	appmgr := mgrgldi.Register(log)

	// Start the polling loop for go internal applets (can be in DBus with other events).
	if settings.DisableDBus {
		go appmgr.StartLoop()

	} else {
		// DBus service is mandatory if enabled. This prevent double launch.
		dbus, e := serviceDbus(log)
		if log.Err(e, "start dbus service") {
			fmt.Println("restart the program with the -N flag if you really need a second instance")
			return false
		}
		dbus.SetManager(appmgr)
		go dbus.StartLoop()
	}

	// HTTP listener for the pprof debug.
	if settings.HTTPPprof {
		websrv.Service.Register("debug/pprof", pprof.Index, log)
		websrv.Service.Start("debug/pprof")
	}

	// Print useful packages versions.
	versions.Print()

	// Custom calls added by devs for their own uses and tests.
	CustomHacks()

	// Register GUI events.
	backendgui.Register(guibridge.New(log))

	// Register mouse events.
	eventmouse.Register(log)

	// Register menus events.
	backendmenu.Register(log, mainmenu.BuildMenuContainer, mainmenu.BuildMenuIcon)

	// Finish startup.
	settings.Start()

	return true
}
コード例 #2
0
ファイル: dock.go プロジェクト: sqp/godock
// runDock starts dock routines and locks the main thread with gtk.
//
func runDock(cmd *Command, args []string) {
	if *pprofFile {
		defer profile.Start().Stop()
	}

	switch {
	case *showVersionGldi:
		fmt.Println(globals.Version()) // -v option only prints gldi version.

	case *showVersionAll:
		versions.Print() // -vv option only prints all versions.

	case dock.Run(logger, dockSettings): // Start dock success => lock gtk.
		dockSettings = nil // free
		gldi.LockGTK()
		maindock.Clean() // may be better with defer, but cause confused panic messages.
	}
}