mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-17 10:06:00 +00:00
feat: distinguish remote operation and request activity
This commit is contained in:
@@ -1,4 +1,27 @@
|
||||
/** Returns whether the status UI should report HTTP traffic or a finite remote operation in progress. */
|
||||
export function hasRemoteActivity(requestCount: number, responseCount: number, boundedRemoteActivityCount: number) {
|
||||
return requestCount - responseCount !== 0 || boundedRemoteActivityCount !== 0;
|
||||
/** Status icon for a finite remote operation whose lifetime is known. */
|
||||
export const REMOTE_OPERATION_ACTIVITY_ICON = "📲";
|
||||
|
||||
/** Status icon for approximate physical remote-request activity. */
|
||||
export const REMOTE_REQUEST_ACTIVITY_ICON = "🌐";
|
||||
|
||||
/** Avoids hiding very short remote requests before the status bar can render them. */
|
||||
export const REMOTE_REQUEST_ACTIVITY_MINIMUM_VISIBLE_MS = 150;
|
||||
|
||||
export type RemoteActivityStatus = {
|
||||
remoteOperationCount: number;
|
||||
trackedRequestCount: number;
|
||||
};
|
||||
|
||||
/** Returns the non-negative difference between tracked request starts and completions. */
|
||||
export function getTrackedRequestCount(requestCount: number, responseCount: number): number {
|
||||
return Math.max(0, requestCount - responseCount);
|
||||
}
|
||||
|
||||
/** Formats the compact prefix shown before the replication status. */
|
||||
export function formatRemoteActivityStatusLabel(status: RemoteActivityStatus): string {
|
||||
const labels = [
|
||||
status.remoteOperationCount > 0 ? REMOTE_OPERATION_ACTIVITY_ICON : "",
|
||||
status.trackedRequestCount > 0 ? `${REMOTE_REQUEST_ACTIVITY_ICON}${status.trackedRequestCount}` : "",
|
||||
].filter((label) => label !== "");
|
||||
return labels.length > 0 ? `${labels.join(" ")} ` : "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user