示例#1
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
}
示例#2
0
func newUpclt() (*uptoshare.Uploader, error) {
	tmp, e := ioutil.TempFile("", tmpHistory+".")
	if e != nil {
		return nil, e
	}
	// Uptoshare actions
	up := uptoshare.New()
	up.Log = log.NewLog(log.Logs).SetName("uptoshare_test")
	// up.SetPreCheck(func() {  })
	// up.SetPostCheck(func() {  })

	// Uptoshare settings.
	up.SetHistoryFile(tmp.Name())
	up.SetHistorySize(42)
	// up.LimitRate = app.conf.UploadRateLimit
	// up.PostAnonymous = app.conf.PostAnonymous

	return up, nil
}