fix: proper opening of the mac app on bookmarklet
This commit is contained in:
40
src/renderer/navigation/blogmarkHandling.ts
Normal file
40
src/renderer/navigation/blogmarkHandling.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { openEntityTab } from './tabPolicy';
|
||||
import type { SidebarView } from './sidebarViewRegistry';
|
||||
|
||||
interface BlogmarkStateSnapshot {
|
||||
activeView: SidebarView;
|
||||
sidebarVisible: boolean;
|
||||
}
|
||||
|
||||
interface BlogmarkCreatedPayload {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
interface BlogmarkHandlers {
|
||||
setActiveView: (view: SidebarView) => void;
|
||||
toggleSidebar: () => void;
|
||||
setSelectedPost: (id: string) => void;
|
||||
openTab: (tab: { type: 'post'; id: string; isTransient: boolean }) => void;
|
||||
}
|
||||
|
||||
export function handleBlogmarkCreatedEvent(
|
||||
snapshot: BlogmarkStateSnapshot,
|
||||
payload: BlogmarkCreatedPayload | null | undefined,
|
||||
handlers: BlogmarkHandlers,
|
||||
): void {
|
||||
const postId = typeof payload?.id === 'string' ? payload.id : '';
|
||||
if (!postId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (snapshot.activeView !== 'posts') {
|
||||
handlers.setActiveView('posts');
|
||||
}
|
||||
|
||||
if (!snapshot.sidebarVisible) {
|
||||
handlers.toggleSidebar();
|
||||
}
|
||||
|
||||
handlers.setSelectedPost(postId);
|
||||
openEntityTab(handlers.openTab, 'post', postId, 'preview');
|
||||
}
|
||||
35
src/renderer/navigation/deferredEventGate.ts
Normal file
35
src/renderer/navigation/deferredEventGate.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
export interface DeferredEventGate<T> {
|
||||
push: (event: T, consume: (event: T) => void) => void;
|
||||
markReady: (consume: (event: T) => void) => void;
|
||||
isReady: () => boolean;
|
||||
}
|
||||
|
||||
export function createDeferredEventGate<T>(): DeferredEventGate<T> {
|
||||
let ready = false;
|
||||
let queue: T[] = [];
|
||||
|
||||
return {
|
||||
push: (event, consume) => {
|
||||
if (ready) {
|
||||
consume(event);
|
||||
return;
|
||||
}
|
||||
|
||||
queue.push(event);
|
||||
},
|
||||
markReady: (consume) => {
|
||||
if (ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
ready = true;
|
||||
const queuedEvents = queue;
|
||||
queue = [];
|
||||
|
||||
for (const event of queuedEvents) {
|
||||
consume(event);
|
||||
}
|
||||
},
|
||||
isReady: () => ready,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user