From 848c56099ece77ff5fe1e9d64fff1d519848e099 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 17 Jun 2017 21:17:59 -0500 Subject: [PATCH] request start/end events to ui --- bg/background.go | 9 ++++++--- bg/server.go | 9 +++++---- events/background_event.go | 8 ++++++++ ui/EventListener.h | 2 ++ ui/MainViewController.m | 34 ++++++---------------------------- ui/ui_darwin.go | 4 ++++ ui/ui_darwin.h | 2 ++ ui/ui_darwin.m | 10 ++++++++++ 8 files changed, 43 insertions(+), 35 deletions(-) diff --git a/bg/background.go b/bg/background.go index 76c6edc..9bad4ca 100644 --- a/bg/background.go +++ b/bg/background.go @@ -9,9 +9,12 @@ import ( func Run(out chan events.BackgroundEvent, in chan events.UserEvent) { bg := &background{ - in: in, - out: out, - server: newServer(), + in: in, + out: out, + server: &server{ + port: 8000, + out: out, + }, } go bg.handleSignals() go bg.listen() diff --git a/bg/server.go b/bg/server.go index cc746fb..a714f09 100644 --- a/bg/server.go +++ b/bg/server.go @@ -4,15 +4,14 @@ import ( "fmt" "log" "net/http" + + "github.com/jordanorelli/dws/events" ) type server struct { port int root string -} - -func newServer() *server { - return &server{port: 8000} + out chan events.BackgroundEvent } func (s *server) listen() { @@ -29,11 +28,13 @@ func (s *server) setRoot(path string) { } func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + s.out <- events.BeginRequestEvent{} if s.root == "" { writeNotInitializedResponse(w) return } fmt.Fprintf(w, "root: %s", s.root) + s.out <- events.EndRequestEvent{} } func writeNotInitializedResponse(w http.ResponseWriter) { diff --git a/events/background_event.go b/events/background_event.go index 268a13b..af109b3 100644 --- a/events/background_event.go +++ b/events/background_event.go @@ -15,3 +15,11 @@ type SetRootEvent struct { Path string backgroundEvent } + +type BeginRequestEvent struct { + backgroundEvent +} + +type EndRequestEvent struct { + backgroundEvent +} diff --git a/ui/EventListener.h b/ui/EventListener.h index 7bf9e12..6b38860 100644 --- a/ui/EventListener.h +++ b/ui/EventListener.h @@ -2,5 +2,7 @@ @protocol EventListener - (void) serverDidSetRoot:(NSString *)path; +- (void) serverDidBeginHandlingRequest; +- (void) serverDidFinishHandlingRequest; @end diff --git a/ui/MainViewController.m b/ui/MainViewController.m index ac7f12f..3f69eca 100644 --- a/ui/MainViewController.m +++ b/ui/MainViewController.m @@ -75,38 +75,16 @@ }]; } -- (void) viewWillAppear { - NSLog(@"[MainViewController] viewWillAppear"); - return [super viewWillAppear]; -} - -- (void) viewDidAppear { - NSLog(@"[MainViewController] viewDidAppear"); - return [super viewDidAppear]; -} - -- (void) viewWillDisappear { - NSLog(@"[MainViewController] viewWillDisappear"); - return [super viewWillDisappear]; -} - -- (void) viewDidDisappear { - NSLog(@"[MainViewController] viewDidDisappear"); - return [super viewDidDisappear]; -} - -- (void) viewWillLayout { - NSLog(@"[MainViewController] viewWillLayout"); - return [super viewWillLayout]; +- (void) serverDidSetRoot:(NSString *)path { + [self.selectedDirectoryText setStringValue:path]; } -- (void) viewDidLayout { - NSLog(@"[MainViewController] viewDidLayout"); - return [super viewDidLayout]; +- (void) serverDidBeginHandlingRequest { + NSLog(@"[MainViewController] request start"); } -- (void) serverDidSetRoot:(NSString *)path { - [self.selectedDirectoryText setStringValue:path]; +- (void) serverDidFinishHandlingRequest { + NSLog(@"[MainViewController] request finish"); } @end diff --git a/ui/ui_darwin.go b/ui/ui_darwin.go index 566a2c3..a3e9d98 100644 --- a/ui/ui_darwin.go +++ b/ui/ui_darwin.go @@ -52,6 +52,10 @@ func (ui *cocoaUI) forwardEvents() { cs := C.CString(v.Path) C.set_root(cs) C.free(unsafe.Pointer(cs)) + case events.BeginRequestEvent: + C.begin_request() + case events.EndRequestEvent: + C.end_request() } } } diff --git a/ui/ui_darwin.h b/ui/ui_darwin.h index 8ed096a..9d82cae 100644 --- a/ui/ui_darwin.h +++ b/ui/ui_darwin.h @@ -2,3 +2,5 @@ void initialize(); int run(); void shutdown(); void set_root(char *); +void begin_request(); +void end_request(); diff --git a/ui/ui_darwin.m b/ui/ui_darwin.m index 941fc6d..5407675 100644 --- a/ui/ui_darwin.m +++ b/ui/ui_darwin.m @@ -26,3 +26,13 @@ void set_root(char *path) { id listener = [[EventBridge shared] listener]; [listener serverDidSetRoot:[NSString stringWithUTF8String:path]]; } + +void begin_request() { + id listener = [[EventBridge shared] listener]; + [listener serverDidBeginHandlingRequest]; +} + +void end_request() { + id listener = [[EventBridge shared] listener]; + [listener serverDidFinishHandlingRequest]; +}