func main() {

	thrust.InitLogger()
	// Set any Custom Provisioners before Start
	thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
	// thrust.Start() must always come before any bindings are created.
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl:  "http://breach.cc/",
		HasFrame: true,
	})
	thrustWindow.Show()
	thrustWindow.Focus()

	// Lets do a window timeout
	go func() {
		<-time.After(time.Second * 5)
		thrustWindow.Close()
		thrust.Exit()
	}()

	// In lieu of something like an http server, we need to lock this thread
	// in order to keep it open, and keep the process running.
	// Dont worry we use runtime.Gosched :)
	thrust.LockThread()
}
func main() {
	http.HandleFunc("/", handler)
	thrust.InitLogger()
	// Set any Custom Provisioners before Start
	thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
	// thrust.Start() must always come before any bindings are created.
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://localhost:8080/",
	})
	thrustWindow.Show()
	thrustWindow.Maximize()
	thrustWindow.Focus()
	thrustWindow.OpenDevtools()
	_, err := thrustWindow.HandleRemote(func(er commands.EventResult, this *window.Window) {
		fmt.Println("RemoteMessage Recieved:", er.Message.Payload)
		// Keep in mind once we have the message, lets say its json of some new type we made,
		// We can unmarshal it to that type.
		// Same goes for the other way around.
		this.SendRemoteMessage("boop")
	})
	if err != nil {
		fmt.Println(err)
		thrust.Exit()
	}
	// See, we dont use thrust.LockThread() because we now have something holding the process open
	http.ListenAndServe(":8080", nil)
}
Ejemplo n.º 3
0
func main() {
	thrust.InitLogger()
	// Set any Custom Provisioners before Start
	thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
	// thrust.Start() must always come before any bindings are created.
	thrust.Start()
	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://breach.cc/",
	})
	thrustWindow.Show()
	thrustWindow.Maximize()
	thrustWindow.Focus()

	// make our top menus
	//applicationMenu, is essentially the menu bar
	applicationMenu := thrust.NewMenu()
	//applicationMenuRoot is the first menu, on darwin this is always named the name of your application.
	applicationMenuRoot := thrust.NewMenu()
	//File menu is our second menu
	fileMenu := thrust.NewMenu()

	// Lets build our root menu.
	// the first argument to AddItem is a CommandID
	// A CommandID is used by Thrust Core to communicate back results and events.
	applicationMenuRoot.AddItem(1, "About")
	applicationMenuRoot.RegisterEventHandlerByCommandID(1,
		func(reply commands.CommandResponse, item *menu.MenuItem) {
			fmt.Println("About Handled")
		})
	// Now for the File menu
	fileMenu.AddItem(2, "Open")
	fileMenu.RegisterEventHandlerByCommandID(2,
		func(reply commands.CommandResponse, item *menu.MenuItem) {
			fmt.Println("Open Handled")
		})
	fileMenu.AddItem(3, "Edit")
	fileMenu.AddSeparator()
	fileMenu.AddItem(4, "Close")
	fileMenu.RegisterEventHandlerByCommandID(4,
		func(reply commands.CommandResponse, item *menu.MenuItem) {
			fmt.Println("Close Event Handled")
			thrust.Exit()
		})
	// Now we just need to plumb our menus together any way we want.

	applicationMenu.AddSubmenu(5, "Application", applicationMenuRoot)
	applicationMenu.AddSubmenu(6, "File", fileMenu)

	// Remember how in basic_browser, Window automatically self registered with the dispatcher.
	// unfortunately we have no such luck here.
	// I suppose this method could be added as an effect of SetApplicationMenu, but the effects of that need to be
	// Ironed out.
	// However, as least we only need to register the top level menu for events, all sub menus will delegate for the top menu.

	// Now we set it as our application Menu
	applicationMenu.SetApplicationMenu()
	// BLOCKING - Dont run before youve excuted all commands you want first.
	thrust.LockThread()
}
Ejemplo n.º 4
0
// Stop tears down all components and finally stops thrust and webserver
func (b *Blank) Stop() {
	// TODO graceful shutdown (teardown http, then exit)
	log.Println("shutting down...")

	for _, c := range components.Components() {
		c.Teardown()
	}

	thrust.Exit()
	os.Exit(0)
}
Ejemplo n.º 5
0
func main() {
	logger := golog.New(os.Stderr, log.Debug)
	//	http.Handle("/", http.FileServer(&assetfs.AssetFS{
	//		Asset:     Asset,
	//		AssetDir:  AssetDir,
	//		AssetInfo: AssetInfo,
	//		Prefix:    "asset/html"}))

	http.Handle("/", http.FileServer(http.Dir("asset/html")))

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		logger.Error("Listen:", err)
		return
	}

	fmt.Println(ln.Addr().String())

	thrust.SetProvisioner(ThrustProvisioner{})
	thrust.InitLogger()
	thrust.Start()

	win := thrust.NewWindow(thrust.WindowOptions{
		HasFrame: true,
		RootUrl:  fmt.Sprintf("http://%s/", ln.Addr().String()),
	})
	win.Show()
	win.OpenDevtools()
	win.SetTitle("GVRTool")
	win.Focus()

	rpc, err := thrustrpc.NewRpc(win, logger)
	if err != nil {
		panic(err)
	}

	rpc.Register("add", func(arg []int) (int, error) {
		fmt.Println("add for", arg)
		sum := 0
		for _, v := range arg {
			sum += v
		}
		return sum, nil
	})

	_, err = win.HandleEvent("closed", func(er thrustcmd.EventResult, this *thrustwin.Window) {
		thrust.Exit()
	})

	if err != nil {
		fmt.Println(err)
		thrust.Exit()
	}

	go func() {
		counter := uint32(0)
		for {
			time.Sleep(time.Second)
			rpc.Call("setCounter", counter, time.Millisecond*200)
			counter++
		}
	}()

	http.Serve(ln, nil)
}