mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-22 02:27:07 +00:00
Adopt focused P2P service views
This commit is contained in:
@@ -96,10 +96,10 @@ export function useP2PReplicatorUI(
|
||||
};
|
||||
|
||||
const statusFactory = (leaf: WorkspaceLeaf) => {
|
||||
return new P2PServerStatusPaneView(leaf, core, p2pParams);
|
||||
return new P2PServerStatusPaneView(leaf, core, replicator);
|
||||
};
|
||||
const legacyStatusFactory = (leaf: WorkspaceLeaf) => {
|
||||
return new LegacyP2PStatusPaneView(leaf, core, p2pParams);
|
||||
return new LegacyP2PStatusPaneView(leaf, core, replicator);
|
||||
};
|
||||
const openStatusPane = () => {
|
||||
if (api.showWindowOnRight) {
|
||||
@@ -167,7 +167,7 @@ export function useP2PReplicatorUI(
|
||||
const isAvailable =
|
||||
hasP2PConfiguration(settings) &&
|
||||
settings.remoteType !== REMOTE_P2P &&
|
||||
(replicator.replicator?.server?.isServing ?? false);
|
||||
replicator.transportLifecycle.isConnected;
|
||||
if (!isAvailable) return false;
|
||||
if (!isChecking) {
|
||||
runOpenReplication();
|
||||
@@ -183,7 +183,7 @@ export function useP2PReplicatorUI(
|
||||
const isAvailable =
|
||||
hasP2PConfiguration(settings) &&
|
||||
settings.remoteType !== REMOTE_P2P &&
|
||||
(replicator.replicator?.server?.isServing ?? false);
|
||||
replicator.transportLifecycle.isConnected;
|
||||
if (!isAvailable) return false;
|
||||
if (!isChecking) {
|
||||
runOpenReplication();
|
||||
@@ -198,10 +198,13 @@ export function useP2PReplicatorUI(
|
||||
checkCallback: (isChecking: boolean) => {
|
||||
const isAvailable =
|
||||
hasP2PConfiguration(host.services.setting.currentSettings()) &&
|
||||
(replicator.replicator?.server?.isServing ?? false);
|
||||
replicator.transportLifecycle.isConnected;
|
||||
if (!isAvailable) return false;
|
||||
if (!isChecking) {
|
||||
void replicator.replicator?.replicateFromCommand(true);
|
||||
void host.services.replicator.runFiniteReplicationActivity(
|
||||
() => replicator.targetedTransfer.synchroniseConfiguredTargets(),
|
||||
{ label: "replication" }
|
||||
);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -95,6 +95,7 @@ describe("useP2PReplicatorUI commands", () => {
|
||||
},
|
||||
} as any;
|
||||
const p2p = {
|
||||
transportLifecycle: { isConnected: true },
|
||||
replicator: {
|
||||
server: { isServing: true },
|
||||
openReplication,
|
||||
@@ -209,6 +210,7 @@ describe("useP2PReplicatorUI commands", () => {
|
||||
remoteType: "COUCHDB",
|
||||
remoteConfigurations: {},
|
||||
};
|
||||
const runFiniteReplicationActivity = vi.fn(async (task: () => unknown) => await task());
|
||||
const host = {
|
||||
services: {
|
||||
context: createServiceContext(),
|
||||
@@ -232,14 +234,18 @@ describe("useP2PReplicatorUI commands", () => {
|
||||
currentSettings: vi.fn(() => settings),
|
||||
onSettingSaved: { addHandler: vi.fn() },
|
||||
},
|
||||
replicator: { runFiniteReplicationActivity: vi.fn() },
|
||||
replicator: { runFiniteReplicationActivity },
|
||||
},
|
||||
} as any;
|
||||
const replicateFromCommand = vi.fn();
|
||||
const synchroniseConfiguredTargets = vi.fn(async () => ({ status: "completed" }));
|
||||
const p2p = {
|
||||
transportLifecycle: { isConnected: true },
|
||||
targetedTransfer: { synchroniseConfiguredTargets },
|
||||
replicator: {
|
||||
server: { isServing: true },
|
||||
openReplication: vi.fn(),
|
||||
replicateFromCommand: vi.fn(),
|
||||
replicateFromCommand,
|
||||
},
|
||||
} as any;
|
||||
|
||||
@@ -274,6 +280,13 @@ describe("useP2PReplicatorUI commands", () => {
|
||||
]) {
|
||||
expect(commands.find(({ id }) => id === commandId)?.checkCallback?.(true)).toBe(true);
|
||||
}
|
||||
|
||||
commands.find(({ id }) => id === "p2p-sync-targets")?.checkCallback?.(false);
|
||||
await vi.waitFor(() => expect(synchroniseConfiguredTargets).toHaveBeenCalledOnce());
|
||||
expect(replicateFromCommand).not.toHaveBeenCalled();
|
||||
expect(runFiniteReplicationActivity).toHaveBeenCalledWith(expect.any(Function), {
|
||||
label: "replication",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not open the P2P status pane automatically when the workspace becomes ready", async () => {
|
||||
|
||||
Reference in New Issue
Block a user