-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Brave News]: Notify tabs when there are updates to their feed. (#16048)
- Loading branch information
1 parent
b1fe6e1
commit 7bee6e2
Showing
8 changed files
with
235 additions
and
109 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
components/brave_new_tab_ui/api/brave_news/feedListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import getBraveNewsController from '.' | ||
import { | ||
BraveNewsControllerRemote, | ||
FeedListenerInterface, | ||
FeedListenerReceiver | ||
} from 'gen/brave/components/brave_today/common/brave_news.mojom.m' | ||
|
||
export const addFeedListener = (listener: (feedHash: string) => void) => | ||
new (class implements FeedListenerInterface { | ||
#receiver = new FeedListenerReceiver(this) | ||
#controller: BraveNewsControllerRemote | ||
|
||
constructor () { | ||
this.#controller = getBraveNewsController() | ||
|
||
if (process.env.NODE_ENV !== 'test') { | ||
this.#controller.addFeedListener( | ||
this.#receiver.$.bindNewPipeAndPassRemote() | ||
) | ||
} | ||
} | ||
|
||
onUpdateAvailable (feedHash: string): void { | ||
listener(feedHash) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.