This commit is contained in:
1 parent
a56408711e
commit
d918d56dc3
8 files changed
+107
-11
No files matched your search
@@ -95,6 +95,23 @@ export function canStartPollingInExtensionContext(ctx: unknown): boolean {
|
||||
return !isExtensionContextPassiveRunMode(ctx);
|
||||
}
|
||||
|
||||
export interface PiTopStatusSegmentPorts {
|
||||
setStatusSegment?: (
|
||||
key: string,
|
||||
text: string | undefined,
|
||||
options: { placement: "after-cost" },
|
||||
) => void;
|
||||
}
|
||||
|
||||
export function setExtensionContextTopStatusSegment(
|
||||
ctx: ExtensionContext,
|
||||
key: string,
|
||||
text: string,
|
||||
): void {
|
||||
const ui = ctx.ui as ExtensionContext["ui"] & PiTopStatusSegmentPorts;
|
||||
ui.setStatusSegment?.(key, text, { placement: "after-cost" });
|
||||
}
|
||||
|
||||
export function formatPollingStartBlockedByRunMode(ctx: unknown): string {
|
||||
const mode = getExtensionContextMode(ctx);
|
||||
return mode
|
||||
|
||||
+24
-5
@@ -232,6 +232,14 @@ export interface TelegramStatusBarState {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export function getTelegramTopStatusSegment(
|
||||
state: Pick<TelegramStatusBarState, "pollingActive">,
|
||||
): string {
|
||||
return state.pollingActive
|
||||
? "Telegram: conectado"
|
||||
: "Telegram: desconectado";
|
||||
}
|
||||
|
||||
export interface TelegramStatusRuntimeContext {
|
||||
ui: {
|
||||
theme: TelegramStatusBarTheme;
|
||||
@@ -245,6 +253,7 @@ export interface TelegramStatusRuntimeDeps<
|
||||
statusKey?: string;
|
||||
getStatusBarState: (ctx: TContext, error?: string) => TelegramStatusBarState;
|
||||
getBridgeStatusLineState: () => TelegramBridgeStatusLineState;
|
||||
setStatusSegment?: (ctx: TContext, key: string, text: string) => void;
|
||||
}
|
||||
|
||||
export interface TelegramBridgeStatusConfig {
|
||||
@@ -255,6 +264,7 @@ export interface TelegramBridgeStatusConfig {
|
||||
}
|
||||
|
||||
export interface TelegramBridgeStatusRuntimeDeps<
|
||||
TContext extends TelegramStatusRuntimeContext,
|
||||
TQueueItem extends { queueLane: TelegramStatusQueueLane },
|
||||
> {
|
||||
statusKey?: string;
|
||||
@@ -298,6 +308,11 @@ export interface TelegramBridgeStatusRuntimeDeps<
|
||||
getInstanceSlot?: () => string | undefined;
|
||||
getInstanceThreadName?: () => string | undefined;
|
||||
getNowMs?: () => number;
|
||||
setStatusSegment?: (
|
||||
ctx: TContext,
|
||||
key: string,
|
||||
text: string,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export interface TelegramBridgeStatusLineOptions {
|
||||
@@ -565,12 +580,15 @@ export function createTelegramStatusRuntime<
|
||||
const statusKey = deps.statusKey ?? "telegram";
|
||||
return {
|
||||
updateStatus: (ctx, error) => {
|
||||
const state = deps.getStatusBarState(ctx, error);
|
||||
ctx.ui.setStatus(
|
||||
statusKey,
|
||||
buildTelegramStatusBarText(
|
||||
ctx.ui.theme,
|
||||
deps.getStatusBarState(ctx, error),
|
||||
),
|
||||
buildTelegramStatusBarText(ctx.ui.theme, state),
|
||||
);
|
||||
deps.setStatusSegment?.(
|
||||
ctx,
|
||||
statusKey,
|
||||
getTelegramTopStatusSegment(state),
|
||||
);
|
||||
},
|
||||
getStatusLines: (options) =>
|
||||
@@ -583,10 +601,11 @@ export function createTelegramBridgeStatusRuntime<
|
||||
TContext extends TelegramStatusRuntimeContext,
|
||||
TQueueItem extends { queueLane: TelegramStatusQueueLane },
|
||||
>(
|
||||
deps: TelegramBridgeStatusRuntimeDeps<TQueueItem>,
|
||||
deps: TelegramBridgeStatusRuntimeDeps<TContext, TQueueItem>,
|
||||
): TelegramStatusRuntime<TContext> {
|
||||
return createTelegramStatusRuntime({
|
||||
statusKey: deps.statusKey,
|
||||
setStatusSegment: deps.setStatusSegment,
|
||||
getStatusBarState: (_ctx, error) => {
|
||||
const config = deps.getConfig();
|
||||
const queuedItems = deps.getQueuedItems();
|
||||
|
||||
Reference in new issue
Block a user