コード例 #1
0
ファイル: update.go プロジェクト: sqp/godock
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf, app.actions()...)
	app.Action().SetMax(1)

	// Events
	events.OnClick = app.onClick
	events.OnMiddleClick = app.onMiddleClick
	events.OnScroll = app.onScroll
	events.OnBuildMenu = app.onBuildMenu
	events.OnDropData = app.GrepTarget

	// Create a cairo-dock sources version checker.
	app.version = versions.NewVersions(app.onGotVersions)

	// The poller will check for new versions on a timer.
	poller := app.Poller().Add(app.version.Check)

	// Set "working" emblem during version check. It should be removed or changed by the check.
	poller.SetPreCheck(func() { app.SetEmblem(app.FileLocation("img", app.conf.VersionEmblemWork), EmblemVersion) })
	poller.SetPostCheck(func() {
		for _, v := range app.version.Sources() {
			v.Log = strhelp.EscapeGtk(v.Log) // Escape <>&
		}
	})

	return app
}
コード例 #2
0
ファイル: example_cdtype_test.go プロジェクト: sqp/godock
// NewApplet create a new applet instance.
//
// It will be trigered remotely by the dock when the applet icon is created.
// Only called once for each running instance.
//
// The goal is to:
//   -Create and fill the applet struct.
//   -Set the config pointer, and maybe some actions.
//   -Register (dock to) applet events (See cdtype.Events for the full list).
//   -Declare and load permanent items required during all the applet lifetime.
//    (those who do not require a config setting, unless it's in a callback).
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf)

	// Events.

	// Forward click events to the defined command launcher.
	events.OnClick = app.Command().Callback(cmdClickLeft)
	events.OnMiddleClick = app.Command().Callback(cmdClickMiddle)

	// For simple callbacks event, use a closure.
	events.OnDropData = func(data string) {
		app.Log().Info("dropped", data)
	}

	events.OnBuildMenu = func(menu cdtype.Menuer) { // Another closure.
		menu.AddEntry("disabled entry", "icon-name", nil)
		menu.AddSeparator()
		menu.AddEntry("my action", "system-run", func() {
			app.Log().Info("clicked")
		})
	}

	events.OnScroll = app.myonScroll // Or use another function with the same args.

	//
	// Create and set your other permanent items here...

	return app
}
コード例 #3
0
ファイル: NetActivity.go プロジェクト: sqp/godock
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf)

	// Events.
	events.OnClick = app.Command().Callback(cmdLeft)
	events.OnMiddleClick = app.Command().Callback(cmdMiddle)
	events.OnBuildMenu = app.buildMenu
	events.End = func() { app.video.WebUnregister() }

	events.OnDropData = func(data string) {
		if strings.HasPrefix(data, "http://") || strings.HasPrefix(data, "https://") {
			if app.conf.VideoDLEnabled {
				app.DownloadVideo(data)
			}
		} else {
			app.UpToShareUpload(data)
		}
	}

	// Uptoshare actions
	app.up = uptoshare.New()
	app.up.Log = app.Log()
	app.up.SetPreCheck(func() { app.SetEmblem(app.FileLocation("icon"), EmblemAction) })
	app.up.SetPostCheck(func() { app.SetEmblem("none", EmblemAction) })
	app.up.SetOnResult(app.onUploadDone)

	// Network activity actions.
	app.service = sysinfo.NewIOActivity(app)
	app.service.Log = app.Log()
	app.service.FormatIcon = sysinfo.FormatIcon
	app.service.FormatLabel = formatLabel
	app.service.GetData = sysinfo.GetNetActivity

	app.Poller().Add(app.service.Check)

	// Video download actions.
	ActionsVideoDL := 0

	hist := videodl.NewHistoryVideo(app, videodl.HistoryFile)
	app.video = videodl.NewManager(app, app.Log(), hist)

	app.video.SetPreCheck(func() error { return app.SetEmblem(app.FileLocation("img", "go-down.svg"), EmblemDownload) })
	app.video.SetPostCheck(func() error { return app.SetEmblem("none", EmblemDownload) })
	app.video.Actions(ActionsVideoDL, app.Action().Add)

	app.video.WebRegister()

	hist.Load()

	return app
}