/* Create a new menu object. Dispatches a call to ThrustCore to generate the object and return the new TargetID in a reply. */ func NewMenu() *Menu { menu := Menu{} menuCreate := Command{ Action: "create", ObjectType: "menu", } menu.Sync = MenuSync{ ReadyChan: make(chan bool), DisplayedChan: make(chan bool), ChildStableChan: make(chan uint), TreeStableChan: make(chan bool), ReadyQueue: make([]*Command, 0), DisplayedQueue: make([]*Command, 0), ChildStableQueue: make([]*ChildCommand, 0), TreeStableQueue: make([]*Command, 0), } menu.ReplyHandlers = make(map[uint]func(reply CommandResponse, item *MenuItem)) menu.SetSendChannel(connection.GetInputChannels()) menu.WaitingResponses = append(menu.WaitingResponses, &menuCreate) dispatcher.RegisterHandler(menu.DispatchResponse) go menu.SendThread() menu.Send(&menuCreate) return &menu }
/* Create a new EventHandler for a give event. */ func NewHandler(event string, fn interface{}) (ThrustEventHandler, error) { h := ThrustEventHandler{} h.Event = event h.Type = "event" err := h.SetHandleFunc(fn) dispatcher.RegisterHandler(h) return h, err }
func NewWindow(options Options) *Window { w := Window{} w.setOptions(options) _, sendChannel := connection.GetCommunicationChannels() size := options.Size if options.Size == (SizeHW{}) { size = SizeHW{ Width: 1024, Height: 768, } } windowCreate := Command{ Action: "create", ObjectType: "window", Args: CommandArguments{ RootUrl: w.Url, Title: spawn.ApplicationName, Size: size, HasFrame: !options.HasFrame, }, } dispatcher.RegisterHandler(w.DispatchResponse) if options.Session == nil { w.SetSendChannel(sendChannel) w.WaitingResponses = append(w.WaitingResponses, &windowCreate) w.Send(&windowCreate) } else { go func() { for { if options.Session.TargetID != 0 { fmt.Println("sess", options.Session.TargetID) windowCreate.Args.SessionID = options.Session.TargetID w.SetSendChannel(sendChannel) w.WaitingResponses = append(w.WaitingResponses, &windowCreate) w.Send(&windowCreate) return } time.Sleep(time.Microsecond * 10) } }() } return &w }
/* NewSession is a constructor that takes 3 arguments, incognito which is a boolean, meaning dont persist session state after close. overrideDefaultSession which is a boolean that till tell thrust core to try to invoke session methods from us. path string is the path to store session data. */ func NewSession(incognito, overrideDefaultSession bool, path string) *Session { session := Session{ CookieStore: overrideDefaultSession, OffTheRecord: incognito, Path: path, } if overrideDefaultSession == true { session.SetInvokable(*NewDummySession()) } command := Command{ Action: "create", ObjectType: "session", Args: CommandArguments{ CookieStore: session.CookieStore, OffTheRecord: session.OffTheRecord, Path: session.Path, }, } session.SendChannel = connection.GetInputChannels() session.WaitingResponses = append(session.WaitingResponses, &command) session.Send(&command) dispatcher.RegisterHandler(session.DispatchResponse) return &session }