|
| 1 | +import type { OAuthAuthDetails } from "../types.js"; |
| 2 | + |
| 3 | +type LiveAccountSyncLike = { |
| 4 | + stop: () => void; |
| 5 | + syncToPath: (path: string) => Promise<void>; |
| 6 | +}; |
| 7 | + |
| 8 | +export async function ensureLiveAccountSyncEntry< |
| 9 | + TSync extends LiveAccountSyncLike, |
| 10 | +>(params: { |
| 11 | + pluginConfig: ReturnType<typeof import("../config.js").loadPluginConfig>; |
| 12 | + authFallback?: OAuthAuthDetails; |
| 13 | + currentSync: TSync | null; |
| 14 | + currentPath: string | null; |
| 15 | + getLiveAccountSync: ( |
| 16 | + config: ReturnType<typeof import("../config.js").loadPluginConfig>, |
| 17 | + ) => boolean; |
| 18 | + getStoragePath: () => string; |
| 19 | + createSync: (authFallback?: OAuthAuthDetails) => TSync; |
| 20 | + registerCleanup: (cleanup: () => void) => void; |
| 21 | + logWarn: (message: string) => void; |
| 22 | + pluginName: string; |
| 23 | + ensureLiveAccountSyncState: (args: { |
| 24 | + enabled: boolean; |
| 25 | + targetPath: string; |
| 26 | + currentSync: TSync | null; |
| 27 | + currentPath: string | null; |
| 28 | + authFallback?: OAuthAuthDetails; |
| 29 | + createSync: (authFallback?: OAuthAuthDetails) => TSync; |
| 30 | + registerCleanup: (cleanup: () => void) => void; |
| 31 | + logWarn: (message: string) => void; |
| 32 | + pluginName: string; |
| 33 | + }) => Promise<{ |
| 34 | + liveAccountSync: TSync | null; |
| 35 | + liveAccountSyncPath: string | null; |
| 36 | + }>; |
| 37 | +}): Promise<{ |
| 38 | + liveAccountSync: TSync | null; |
| 39 | + liveAccountSyncPath: string | null; |
| 40 | +}> { |
| 41 | + return params.ensureLiveAccountSyncState({ |
| 42 | + enabled: params.getLiveAccountSync(params.pluginConfig), |
| 43 | + targetPath: params.getStoragePath(), |
| 44 | + currentSync: params.currentSync, |
| 45 | + currentPath: params.currentPath, |
| 46 | + authFallback: params.authFallback, |
| 47 | + createSync: params.createSync, |
| 48 | + registerCleanup: params.registerCleanup, |
| 49 | + logWarn: params.logWarn, |
| 50 | + pluginName: params.pluginName, |
| 51 | + }); |
| 52 | +} |
0 commit comments