Official
sidebar
Built-in sidebar UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/sidebar@0.2.7
Permissions in 0.2.7
Files
rest.ts1.5 KB
// Reading a chat ahead builds its whole pane, which the kernel takes on the
// main thread, so it waits until the pointer rests on a row for REST_MS. A
// pointer sweeping over the list reads nothing, and its hover frames do not
// wait behind chats it only passed.
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import type * as Scope from "effect/Scope";
/** How long the pointer rests on a row before its chat is read ahead: a pointer passing over rows reads none. */
export const REST_MS = 90;
export function restingReads(read: (chatId: string) => Effect.Effect<void>, scope: Scope.Scope) {
let resting: { chatId: string; fiber: Fiber.Fiber<void> } | undefined;
// The pointer came onto a row: its chat is read once it has rested there.
const restOn = Effect.fn("Sidebar.restOn")(function* (chatId: string) {
if (resting?.chatId === chatId) return;
if (resting) yield* Fiber.interrupt(resting.fiber);
const wait = Effect.sleep(REST_MS).pipe(
Effect.andThen(Effect.sync(() => (resting = undefined))),
Effect.andThen(read(chatId)),
);
resting = { chatId, fiber: yield* Effect.forkIn(wait, scope, { startImmediately: true }) };
});
// The pointer left the row before it rested there: nothing is read.
const leaveRow = (chatId: string): Effect.Effect<void> => {
if (resting?.chatId !== chatId) return Effect.void;
const { fiber } = resting;
resting = undefined;
return Fiber.interrupt(fiber);
};
return { restOn, leaveRow };
}
No comments yet.