-
Notifications
You must be signed in to change notification settings - Fork 46
feat(notifications): focus-aware notification bus on quill toasts #2934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32bef75
feat(notifications): focus-aware notification bus on quill toasts
adamleithp 64df565
refactor(notifications): generic targetsEqual via exhaustive targetKey
adamleithp 1fa4a5a
fix(notifications): channel-aware deep link for in-app toast clicks
adamleithp b7d8e9b
Merge remote-tracking branch 'origin/main' into feat/notification-bus
adamleithp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
| import { ROOT_LOGGER, type RootLogger } from "@posthog/di/logger"; | ||
| import { | ||
| type IMainWindow, | ||
| MAIN_WINDOW_SERVICE, | ||
| } from "@posthog/platform/main-window"; | ||
| import type { NotificationTarget } from "@posthog/platform/notifications"; | ||
| import { TypedEventEmitter } from "@posthog/shared"; | ||
| import { inject, injectable } from "inversify"; | ||
| import type { LinkLogger } from "./identifiers"; | ||
|
|
||
| export const OpenTargetLinkEvent = { | ||
| Open: "open", | ||
| } as const; | ||
|
|
||
| export interface OpenTargetLinkEvents { | ||
| [OpenTargetLinkEvent.Open]: NotificationTarget; | ||
| } | ||
|
|
||
| // Carries "open this target" intents (from a clicked native notification) out of | ||
| // the main process to the renderer, which navigates by target kind. Mirrors | ||
| // TaskLinkService's pending-replay + window-focus, but registers NO OS | ||
| // URL-scheme handler — notification clicks are its only source, so it stays | ||
| // target-generic without entangling URL parsing. | ||
| @injectable() | ||
| export class OpenTargetLinkService extends TypedEventEmitter<OpenTargetLinkEvents> { | ||
| private pending: NotificationTarget | null = null; | ||
| private readonly log: LinkLogger; | ||
|
|
||
| constructor( | ||
| @inject(MAIN_WINDOW_SERVICE) | ||
| private readonly mainWindow: IMainWindow, | ||
| @inject(ROOT_LOGGER) | ||
| rootLogger: RootLogger, | ||
| ) { | ||
| super(); | ||
| this.log = rootLogger.scope("open-target-link-service"); | ||
| } | ||
|
|
||
| // Called from the notification click handler (main process). Emits to the | ||
| // renderer if it's listening, else queues for replay once it subscribes. | ||
| open(target: NotificationTarget): void { | ||
| if (this.listenerCount(OpenTargetLinkEvent.Open) > 0) { | ||
| this.log.info("Emitting open-target event", { kind: target.kind }); | ||
| this.emit(OpenTargetLinkEvent.Open, target); | ||
| } else { | ||
| this.log.info("Queueing open-target (renderer not ready)", { | ||
| kind: target.kind, | ||
| }); | ||
| this.pending = target; | ||
| } | ||
|
|
||
| if (this.mainWindow.isMinimized()) { | ||
| this.mainWindow.restore(); | ||
| } | ||
| this.mainWindow.focus(); | ||
| } | ||
|
|
||
| consumePending(): NotificationTarget | null { | ||
| const pending = this.pending; | ||
| this.pending = null; | ||
| return pending; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.