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()
}
Example #2
0
//StartgGITui starts the GUI of the application for the front end.
func StartgGITui() {

	thrust.InitLogger()
	// thrust.Start() must always come before any bindings are created.
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://localhost:9090",
	})
	thrustWindow.Show()
	thrustWindow.Maximize()
	thrustWindow.Focus()

	onclose, err := thrust.NewEventHandler("closed", func(cr commands.EventResult) {
		fmt.Println("Close Event Occured")
		connection.CleanExit()
	})
	fmt.Println(onclose)
	if err != nil {
		fmt.Println(err)
		connection.CleanExit()
	}
	// 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()
}
Example #3
0
func (b *Blank) initThrust() error {
	thrust.SetProvisioner(NewDefaultProvisioner())
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: fmt.Sprintf("http://%s", b.addr),
	})

	thrustWindow.Show()
	thrustWindow.Maximize()
	thrustWindow.Focus()

	if b.debug {
		thrustWindow.OpenDevtools()
	}

	b.tunnel = transport.NewTunnel(thrustWindow)
	_, err := thrustWindow.HandleRemote(b.tunnel.OnRemote)
	if err != nil {
		return err
	}

	// bind close event
	thrust.NewEventHandler("closed", func(cr commands.EventResult) {
		b.Stop()
	})

	return nil
}
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)
}
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()
}
Example #6
0
func main() {
	flag.Parse()
	thrust.InitLogger()
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: fmt.Sprintf("http://127.0.0.1:%d", *port),
	})
	thrustWindow.Show()
	thrustWindow.Focus()
	// BLOCKING - Dont run before youve excuted all commands you want first.
	thrust.LockThread()
}
Example #7
0
func (c *WebClient) RunFrontend() {
	thrust.InitLogger()
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://localhost:54693/#/chat",
	})
	thrustWindow.Show()
	thrustWindow.Focus()

	quit := make(chan bool, 0)
	thrust.NewEventHandler("closed", func(cr commands.EventResult) {
		connection.CleanExit()
		close(quit)
	})
	<-quit
}
Example #8
0
func main() {
	flag.Parse()
	thrust.InitLogger()
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: fmt.Sprintf("http://127.0.0.1:%d", *port),
	})
	thrustWindow.Show()
	thrustWindow.Focus()

	addr := fmt.Sprintf("127.0.0.1:%d", *port)
	http.Handle("/", http.HandlerFunc(index))
	err := http.ListenAndServe(addr, nil)

	if err != nil {
		panic(err)
	}
}
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()

	thrustWindow.OpenDevtools()
	// Lets do a window timeout
	go func() {
		<-time.After(time.Second * 10)
		thrustWindow.CloseDevtools()
	}()
	// BLOCKING - Dont run before youve excuted all commands you want first
	thrust.LockThread()
}
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()

	thrustWindow2 := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://google.com/",
	})
	thrustWindow2.Show()
	thrustWindow2.Focus()

	// BLOCKING - Dont run before youve excuted all commands you want first.
	thrust.LockThread()
}
Example #11
0
func main() {
	/*
	   use basic setup
	*/
	thrust.InitLogger()
	// Set any Custom Provisioners before Start
	thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
	// thrust.Start() must always come before any bindings are created.
	thrust.Start()

	/*
			  Start of Advanced Session Tutorial.
			  We are going to set the Override value to true as ooposed to the false
			  used in basic_session. This will cause ThrustCore to try to invoke methods from us.

		    Look down below func main to find our session class.
	*/
	mysession := thrust.NewSession(false, true, "session_cache")

	mysession.SetInvokable(NewSimpleSession())
	/*
	   Modified basic_window, where we provide, a session argument
	   to NewWindow.
	*/
	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://breach.cc/",
		Session: mysession,
	})
	thrustWindow.Show()
	thrustWindow.Maximize()
	thrustWindow.Focus()

	// 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()
}
Example #12
0
func main() {
	prog := path.Base(os.Args[0])
	log.SetFlags(0)
	log.SetPrefix(prog + ": ")

	flag.Usage = Usage
	flag.Parse()

	if flag.NArg() > 0 {
		Usage()
		os.Exit(1)
	}

	log.Printf("Serving at http://%s:%d/", *host, *port)

	chat := Chat{}
	chat.broadcast = topic.New()
	chat.registry = birpc.NewRegistry()
	chat.registry.RegisterService(&chat)
	defer close(chat.broadcast.Broadcast)
	upgrader := websocket.Upgrader{}

	serve := func(w http.ResponseWriter, req *http.Request) {
		ws, err := upgrader.Upgrade(w, req, nil)
		if err != nil {
			log.Println(err)
			return
		}
		endpoint := wetsock.NewEndpoint(chat.registry, ws)
		messages := make(chan interface{}, 10)
		chat.broadcast.Register(messages)
		go func() {
			defer chat.broadcast.Unregister(messages)
			for i := range messages {
				msg := i.(Outgoing)
				// Fire-and-forget.
				// TODO use .Notify when it exists
				_ = endpoint.Go("Chat.Message", msg, nil, nil)
			}
			// broadcast topic kicked us out for being too slow;
			// probably a hung TCP connection. let client
			// re-establish.
			log.Printf("Kicking slow client: %v", ws.RemoteAddr())
			ws.Close()
		}()

		if err := endpoint.Serve(); err != nil {
			log.Printf("websocket error from %v: %v", ws.RemoteAddr(), err)
		}
	}

	http.HandleFunc("/sock", serve)
	http.Handle("/", http.HandlerFunc(index))
	addr := fmt.Sprintf("%s:%d", *host, *port)

	thrust.InitLogger()
	thrust.Start()
	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: fmt.Sprintf("http://127.0.0.1:%d", *port),
	})
	thrustWindow.Show()
	thrustWindow.Focus()

	err := http.ListenAndServe(addr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
func main() {

	//redirect logger output to console
	log.SetOutput(os.Stdout)

	//initialize go-httpclient
	httpclient.Defaults(httpclient.Map{
		httpclient.OPT_USERAGENT: "meetup ui client",
		"Accept-Language":        "en-us",
	})

	//define some mux handlers
	http.HandleFunc("/", handler)
	http.HandleFunc("/auth", authHandler)
	http.HandleFunc("/view", viewHandler)

	//thrust code starts here
	thrust.InitLogger()
	// Set any Custom Provisioners before Start
	thrust.SetProvisioner(tutorial.NewTutorialProvisioner())

	//must always be called before bindings are created
	thrust.Start()

	thrustWindow := thrust.NewWindow(thrust.WindowOptions{
		RootUrl: "http://localhost:8080/",
	})
	thrustWindow.Show()
	thrustWindow.Maximize()
	thrustWindow.Focus()
	thrustWindow.OpenDevtools()

	//capture remote messages
	_, err := thrustWindow.HandleRemote(func(er commands.EventResult, this *window.Window) {

		//fmt.Println("RemoteMessage Recieved:", er.Message.Payload)

		log.Printf("Remote message Recieved:", er.Message.Payload)

		if er.Message.Payload == "getGroup" {

			//this.SendRemoteMessage("preparing data")
			data := getGroupData()
			log.Printf("data", data)

			msg := "getGroup|" + data
			this.SendRemoteMessage(msg)
		}

		if er.Message.Payload == "getMembers" {

			//this.SendRemoteMessage("preparing data")
			data := getMemberData()
			log.Printf("data", data)

			msg := "getMembers|" + data
			this.SendRemoteMessage(msg)
		}

		if er.Message.Payload == "getEvents" {

			//this.SendRemoteMessage("preparing data")
			data := getEventData()
			log.Printf("data", data)

			msg := "getEvents|" + data
			this.SendRemoteMessage(msg)
		}

	})
	if err != nil {

		log.Printf("remote message error:", err)
	}

	//start go server
	http.ListenAndServe(":8080", nil)
}
Example #14
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)
}
/*
This tutorial teaches how to handle global events.
You can even use this to track menu/window/session etc. events,
if you store your bindings somewhere and track the ids.
Check package thrust for the acceptable handler definitions.
*/
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()

	/*
	  Here we use an EventResult Callback, it provides us a little less data than a ComandResponse cb
	  however, its good for if we know we dont need to worry about targetids. Like understanding which window
	  was focuses, just that there is a window, that was focused.
	*/
	onfocus, err := thrust.NewEventHandler("focus", func(er commands.EventResult) {
		fmt.Println("Focus Event Occured")
	})
	fmt.Println(onfocus)
	if err != nil {
		fmt.Println(err)
		connection.CleanExit()
	}

	/*
	  Note blur does not seem to be triggered by unfocus
	  only by actually clicking the window, and then clicking somewhere else.
	*/
	onblur, err := thrust.NewEventHandler("blur", func(er commands.EventResult) {
		fmt.Println("Blur Event Occured")
	})
	fmt.Println(onblur)
	if err != nil {
		fmt.Println(err)
		connection.CleanExit()
	}

	/*
		Here we use a CommandResponse callback just because we can, it provides us more data
		than the EventResult callback
	*/
	onclose, err := thrust.NewEventHandler("closed", func(cr commands.EventResult) {
		fmt.Println("Close Event Occured")
	})
	fmt.Println(onclose)
	if err != nil {
		fmt.Println(err)
		connection.CleanExit()
	}

	/*
	  Lets say we just want to log all events
	*/
	onanything, err := thrust.NewEventHandler("*", func(cr commands.CommandResponse) {
		cr_marshaled, err := json.Marshal(cr)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Println(fmt.Sprintf("Event(%s) - Signaled by Command (%s)", cr.Type, cr_marshaled))
		}
	})

	fmt.Println(onanything)
	if err != nil {
		fmt.Println(err)
		connection.CleanExit()
	}

	time.AfterFunc(time.Second, func() {
		thrustWindow.Focus()
	})

	time.AfterFunc(time.Second*2, func() {
		thrustWindow.UnFocus()
	})

	time.AfterFunc(time.Second*3, func() {
		thrustWindow.Close()
	})

	// Lets do a window timeout
	go func() {
		<-time.After(time.Second * 5)
		connection.CleanExit()
	}()
	// BLOCKING - Dont run before youve excuted all commands you want first
	thrust.LockThread()

}