request start/end events to ui

master
Jordan Orelli 8 years ago
parent 199c59b786
commit 848c56099e

@ -9,9 +9,12 @@ import (
func Run(out chan events.BackgroundEvent, in chan events.UserEvent) { func Run(out chan events.BackgroundEvent, in chan events.UserEvent) {
bg := &background{ bg := &background{
in: in, in: in,
out: out, out: out,
server: newServer(), server: &server{
port: 8000,
out: out,
},
} }
go bg.handleSignals() go bg.handleSignals()
go bg.listen() go bg.listen()

@ -4,15 +4,14 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"github.com/jordanorelli/dws/events"
) )
type server struct { type server struct {
port int port int
root string root string
} out chan events.BackgroundEvent
func newServer() *server {
return &server{port: 8000}
} }
func (s *server) listen() { func (s *server) listen() {
@ -29,11 +28,13 @@ func (s *server) setRoot(path string) {
} }
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.out <- events.BeginRequestEvent{}
if s.root == "" { if s.root == "" {
writeNotInitializedResponse(w) writeNotInitializedResponse(w)
return return
} }
fmt.Fprintf(w, "root: %s", s.root) fmt.Fprintf(w, "root: %s", s.root)
s.out <- events.EndRequestEvent{}
} }
func writeNotInitializedResponse(w http.ResponseWriter) { func writeNotInitializedResponse(w http.ResponseWriter) {

@ -15,3 +15,11 @@ type SetRootEvent struct {
Path string Path string
backgroundEvent backgroundEvent
} }
type BeginRequestEvent struct {
backgroundEvent
}
type EndRequestEvent struct {
backgroundEvent
}

@ -2,5 +2,7 @@
@protocol EventListener @protocol EventListener
- (void) serverDidSetRoot:(NSString *)path; - (void) serverDidSetRoot:(NSString *)path;
- (void) serverDidBeginHandlingRequest;
- (void) serverDidFinishHandlingRequest;
@end @end

@ -75,38 +75,16 @@
}]; }];
} }
- (void) viewWillAppear { - (void) serverDidSetRoot:(NSString *)path {
NSLog(@"[MainViewController] viewWillAppear"); [self.selectedDirectoryText setStringValue:path];
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) viewDidLayout { - (void) serverDidBeginHandlingRequest {
NSLog(@"[MainViewController] viewDidLayout"); NSLog(@"[MainViewController] request start");
return [super viewDidLayout];
} }
- (void) serverDidSetRoot:(NSString *)path { - (void) serverDidFinishHandlingRequest {
[self.selectedDirectoryText setStringValue:path]; NSLog(@"[MainViewController] request finish");
} }
@end @end

@ -52,6 +52,10 @@ func (ui *cocoaUI) forwardEvents() {
cs := C.CString(v.Path) cs := C.CString(v.Path)
C.set_root(cs) C.set_root(cs)
C.free(unsafe.Pointer(cs)) C.free(unsafe.Pointer(cs))
case events.BeginRequestEvent:
C.begin_request()
case events.EndRequestEvent:
C.end_request()
} }
} }
} }

@ -2,3 +2,5 @@ void initialize();
int run(); int run();
void shutdown(); void shutdown();
void set_root(char *); void set_root(char *);
void begin_request();
void end_request();

@ -26,3 +26,13 @@ void set_root(char *path) {
id listener = [[EventBridge shared] listener]; id listener = [[EventBridge shared] listener];
[listener serverDidSetRoot:[NSString stringWithUTF8String:path]]; [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];
}

Loading…
Cancel
Save