diff --git a/backend/events.go b/backend/events.go index 201281b..df88833 100644 --- a/backend/events.go +++ b/backend/events.go @@ -142,17 +142,14 @@ func CreateEventsHandler(notifier *Notifier[Notification]) http.HandlerFunc { w.Header().Set("Content-Type", "text/event-stream") w.Header().Set("Cache-Control", "no-cache") w.Header().Set("Connection", "keep-alive") - w.(http.Flusher).Flush() - - notifier.AddKey(userId.String()) - defer notifier.RemoveKey(userId.String()) + // w.(http.Flusher).Flush() if err := notifier.Create(userId.String()); err != nil { // TODO: this could be better. // EG: The user could attempt to create many connections // and they just get a 500, with no explanation. w.WriteHeader(http.StatusInternalServerError) - w.(http.Flusher).Flush() + // w.(http.Flusher).Flush() return } @@ -174,7 +171,7 @@ func CreateEventsHandler(notifier *Notifier[Notification]) http.HandlerFunc { fmt.Printf("Sending msg %s\n", msg) fmt.Fprintf(w, "event: data\ndata: %s\n\n", string(msgString)) - w.(http.Flusher).Flush() + // w.(http.Flusher).Flush() } } } diff --git a/backend/notifications.go b/backend/notifications.go index d4cf4c0..466eb0f 100644 --- a/backend/notifications.go +++ b/backend/notifications.go @@ -8,8 +8,6 @@ type Notifier[TNotification any] struct { bufferSize int Listeners map[string]chan TNotification - - AllowedKeys map[string]bool } func (n *Notifier[TNotification]) Create(id string) error { @@ -17,10 +15,6 @@ func (n *Notifier[TNotification]) Create(id string) error { return errors.New("This listener already exists") } - if _, exists := n.AllowedKeys[id]; !exists { - return errors.New("This key cannot be used to create a listener") - } - n.Listeners[id] = make(chan TNotification, n.bufferSize) return nil @@ -56,18 +50,9 @@ func (n *Notifier[TNotification]) Delete(id string) error { return nil } -func (n *Notifier[TNotification]) AddKey(id string) { - n.AllowedKeys[id] = true -} - -func (n *Notifier[TNotification]) RemoveKey(id string) { - delete(n.AllowedKeys, id) -} - func NewNotifier[TNotification any](bufferSize int) Notifier[TNotification] { return Notifier[TNotification]{ - bufferSize: bufferSize, - Listeners: make(map[string]chan TNotification), - AllowedKeys: make(map[string]bool), + bufferSize: bufferSize, + Listeners: make(map[string]chan TNotification), } } diff --git a/backend/notifications_test.go b/backend/notifications_test.go index d986bb1..2e25752 100644 --- a/backend/notifications_test.go +++ b/backend/notifications_test.go @@ -13,8 +13,6 @@ func TestSendingNotifications(t *testing.T) { notifier := NewNotifier[string](3) - notifier.AddKey("1") - err := notifier.SendAndCreate("1", "a") require.NoError(err) @@ -41,8 +39,6 @@ func TestFullBuffer(t *testing.T) { notifier := NewNotifier[string](1) - notifier.AddKey("1") - err := notifier.SendAndCreate("1", "a") require.NoError(err) @@ -50,11 +46,3 @@ func TestFullBuffer(t *testing.T) { assert.Error(err) } - -func TestNoAllowedKey(t *testing.T) { - require := require.New(t) - notifier := NewNotifier[string](1) - - err := notifier.SendAndCreate("1", "a") - require.Error(err) -} diff --git a/frontend/src-tauri/tauri.conf.json b/frontend/src-tauri/tauri.conf.json index 7863ea8..4a1e95f 100644 --- a/frontend/src-tauri/tauri.conf.json +++ b/frontend/src-tauri/tauri.conf.json @@ -26,8 +26,8 @@ "icons/icon.icns", "icons/icon.ico" ], - "macOS": { - "signingIdentity": "6F3F957C06DE870B9A9F2CA8C2E762C6752AB2CB" - } + "macOS": { + "signingIdentity": "6F3F957C06DE870B9A9F2CA8C2E762C6752AB2CB" + } } } diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index e80b804..2a83c6c 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -20,7 +20,8 @@ type BaseRequestParams = Partial<{ method: "GET" | "POST"; }>; -export const base = "https://haystack.johncosta.tech"; +// export const base = "https://haystack.johncosta.tech"; +export const base = "http://192.168.1.199:3040"; const getBaseRequest = ({ path, body, method }: BaseRequestParams): Request => { return new Request(`${base}/${path}`, { diff --git a/frontend/src/notifications/index.ts b/frontend/src/notifications/index.ts index 7f66f87..881e413 100644 --- a/frontend/src/notifications/index.ts +++ b/frontend/src/notifications/index.ts @@ -83,6 +83,10 @@ export const Notifications = (onCompleteImage: () => void) => { events.addEventListener("data", dataEventListener); + events.onerror = (e) => { + console.error(e); + }; + onCleanup(() => { events.removeEventListener("data", dataEventListener); events.close();