import { addIcon } from "@/deps.ts"; import { $msg } from "@/common/translation"; import type { NecessaryServices } from "@vrtmrz/livesync-commonlib/compat/interfaces/ServiceModule"; import { REPLICATION_PROGRESS_PRESENTATIONS, USER_INITIATED_REPLICATION_AUTHORITY, } from "@vrtmrz/livesync-commonlib/replication"; export type ObsidianReplicationRibbonHost = NecessaryServices<"API" | "appLifecycle" | "replication", never>; /** The established SVG used by the Obsidian replication ribbon action. */ const REPLICATE_ICON_SVG = ` `; /** * Register the Obsidian-only replication ribbon action. * * The icon and ribbon element are intentionally kept out of the generic Basic * commands feature; other hosts can compose the latter without Obsidian UI. */ export function useObsidianReplicationRibbonFeature(host: ObsidianReplicationRibbonHost): void { const { services } = host; services.appLifecycle.onInitialise.addHandler(() => { addIcon("replicate", REPLICATE_ICON_SVG); services.API.addRibbonIcon("replicate", $msg("moduleObsidianMenu.replicate"), async () => { await services.replication.replicateUserInitiated({ trigger: "manual", progressPresentation: REPLICATION_PROGRESS_PRESENTATIONS.NOTICE, interaction: USER_INITIATED_REPLICATION_AUTHORITY, }); }).addClass("livesync-ribbon-replicate"); return Promise.resolve(true); }); }