mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-17 04:51:17 +00:00
Compare commits
2 Commits
0.25.63
...
enhance_fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d9364af36 | ||
|
|
83228e2077 |
@@ -32,10 +32,15 @@ function validateP2PSettings(core: LiveSyncBaseCore<ServiceContext, any>) {
|
|||||||
settings.P2P_IsHeadless = true;
|
settings.P2P_IsHeadless = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createReplicator(core: LiveSyncBaseCore<ServiceContext, any>): LiveSyncTrysteroReplicator {
|
async function createReplicator(core: LiveSyncBaseCore<ServiceContext, any>): Promise<LiveSyncTrysteroReplicator> {
|
||||||
validateP2PSettings(core);
|
validateP2PSettings(core);
|
||||||
const replicator = new LiveSyncTrysteroReplicator({ services: core.services });
|
const replicator = await core.services.replicator.getNewReplicator();
|
||||||
addP2PEventHandlers(replicator);
|
if (!replicator) {
|
||||||
|
throw new Error("Failed to create replicator instance. Ensure P2P is enabled in settings.");
|
||||||
|
}
|
||||||
|
if (!(replicator instanceof LiveSyncTrysteroReplicator)) {
|
||||||
|
throw new Error("Unexpected replicator type. Expected LiveSyncTrysteroReplicator.");
|
||||||
|
}
|
||||||
return replicator;
|
return replicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +54,7 @@ export async function collectPeers(
|
|||||||
core: LiveSyncBaseCore<ServiceContext, any>,
|
core: LiveSyncBaseCore<ServiceContext, any>,
|
||||||
timeoutSec: number
|
timeoutSec: number
|
||||||
): Promise<CLIP2PPeer[]> {
|
): Promise<CLIP2PPeer[]> {
|
||||||
const replicator = createReplicator(core);
|
const replicator = await createReplicator(core);
|
||||||
await replicator.open();
|
await replicator.open();
|
||||||
try {
|
try {
|
||||||
await delay(timeoutSec * 1000);
|
await delay(timeoutSec * 1000);
|
||||||
@@ -79,7 +84,7 @@ export async function syncWithPeer(
|
|||||||
peerToken: string,
|
peerToken: string,
|
||||||
timeoutSec: number
|
timeoutSec: number
|
||||||
): Promise<CLIP2PPeer> {
|
): Promise<CLIP2PPeer> {
|
||||||
const replicator = createReplicator(core);
|
const replicator = await createReplicator(core);
|
||||||
await replicator.open();
|
await replicator.open();
|
||||||
try {
|
try {
|
||||||
const timeoutMs = timeoutSec * 1000;
|
const timeoutMs = timeoutSec * 1000;
|
||||||
@@ -115,7 +120,7 @@ export async function syncWithPeer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openP2PHost(core: LiveSyncBaseCore<ServiceContext, any>): Promise<LiveSyncTrysteroReplicator> {
|
export async function openP2PHost(core: LiveSyncBaseCore<ServiceContext, any>): Promise<LiveSyncTrysteroReplicator> {
|
||||||
const replicator = createReplicator(core);
|
const replicator = await createReplicator(core);
|
||||||
await replicator.open();
|
await replicator.open();
|
||||||
return replicator;
|
return replicator;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import * as path from "path";
|
|||||||
import { NodeServiceContext, NodeServiceHub } from "./services/NodeServiceHub";
|
import { NodeServiceContext, NodeServiceHub } from "./services/NodeServiceHub";
|
||||||
import { configureNodeLocalStorage, ensureGlobalNodeLocalStorage } from "./services/NodeLocalStorage";
|
import { configureNodeLocalStorage, ensureGlobalNodeLocalStorage } from "./services/NodeLocalStorage";
|
||||||
import { LiveSyncBaseCore } from "../../LiveSyncBaseCore";
|
import { LiveSyncBaseCore } from "../../LiveSyncBaseCore";
|
||||||
import { ModuleReplicatorP2P } from "../../modules/core/ModuleReplicatorP2P";
|
|
||||||
import { initialiseServiceModulesCLI } from "./serviceModules/CLIServiceModules";
|
import { initialiseServiceModulesCLI } from "./serviceModules/CLIServiceModules";
|
||||||
import { DEFAULT_SETTINGS, LOG_LEVEL_VERBOSE, type LOG_LEVEL, type ObsidianLiveSyncSettings } from "@lib/common/types";
|
import { DEFAULT_SETTINGS, LOG_LEVEL_VERBOSE, type LOG_LEVEL, type ObsidianLiveSyncSettings } from "@lib/common/types";
|
||||||
import type { InjectableServiceHub } from "@lib/services/implements/injectable/InjectableServiceHub";
|
import type { InjectableServiceHub } from "@lib/services/implements/injectable/InjectableServiceHub";
|
||||||
@@ -27,6 +26,7 @@ import type { CLICommand, CLIOptions } from "./commands/types";
|
|||||||
import { getPathFromUXFileInfo } from "@lib/common/typeUtils";
|
import { getPathFromUXFileInfo } from "@lib/common/typeUtils";
|
||||||
import { stripAllPrefixes } from "@lib/string_and_binary/path";
|
import { stripAllPrefixes } from "@lib/string_and_binary/path";
|
||||||
import { IgnoreRules } from "./serviceModules/IgnoreRules";
|
import { IgnoreRules } from "./serviceModules/IgnoreRules";
|
||||||
|
import { useP2PReplicatorFeature } from "@/lib/src/replication/trystero/useP2PReplicatorFeature";
|
||||||
|
|
||||||
const SETTINGS_FILE = ".livesync/settings.json";
|
const SETTINGS_FILE = ".livesync/settings.json";
|
||||||
ensureGlobalNodeLocalStorage();
|
ensureGlobalNodeLocalStorage();
|
||||||
@@ -368,12 +368,11 @@ export async function main() {
|
|||||||
(core: LiveSyncBaseCore<NodeServiceContext, any>, serviceHub: InjectableServiceHub<NodeServiceContext>) => {
|
(core: LiveSyncBaseCore<NodeServiceContext, any>, serviceHub: InjectableServiceHub<NodeServiceContext>) => {
|
||||||
return initialiseServiceModulesCLI(vaultPath, core, serviceHub, ignoreRules, watchEnabled);
|
return initialiseServiceModulesCLI(vaultPath, core, serviceHub, ignoreRules, watchEnabled);
|
||||||
},
|
},
|
||||||
(core) => [
|
(core) => [],
|
||||||
// No modules need to be registered for P2P replication in CLI. Directly using Replicators in p2p.ts
|
|
||||||
// new ModuleReplicatorP2P(core),
|
|
||||||
],
|
|
||||||
() => [], // No add-ons
|
() => [], // No add-ons
|
||||||
(core) => {
|
(core) => {
|
||||||
|
// Register P2P replicator feature.
|
||||||
|
const _replicator = useP2PReplicatorFeature(core);
|
||||||
// Add target filter to prevent internal files are handled
|
// Add target filter to prevent internal files are handled
|
||||||
core.services.vault.isTargetFile.addHandler(async (target) => {
|
core.services.vault.isTargetFile.addHandler(async (target) => {
|
||||||
const targetPath = stripAllPrefixes(getPathFromUXFileInfo(target));
|
const targetPath = stripAllPrefixes(getPathFromUXFileInfo(target));
|
||||||
@@ -424,7 +423,7 @@ export async function main() {
|
|||||||
// Save the settings file before any lifecycle events can mutate and persist them.
|
// Save the settings file before any lifecycle events can mutate and persist them.
|
||||||
// suspendAllSync and other lifecycle hooks clobber sync settings in memory, and
|
// suspendAllSync and other lifecycle hooks clobber sync settings in memory, and
|
||||||
// various code paths persist the clobbered state to disk. We restore on shutdown.
|
// various code paths persist the clobbered state to disk. We restore on shutdown.
|
||||||
const settingsBackup = await fs.readFile(settingsPath, "utf-8").catch(() => null);
|
const settingsBackup = await fs.readFile(settingsPath, "utf-8").catch(() => null!);
|
||||||
|
|
||||||
// Restore settings file on any exit to undo lifecycle mutations.
|
// Restore settings file on any exit to undo lifecycle mutations.
|
||||||
// Write to a temp path first so a crash mid-write doesn't leave a truncated file.
|
// Write to a temp path first so a crash mid-write doesn't leave a truncated file.
|
||||||
|
|||||||
@@ -17,12 +17,6 @@ The head note of 0.25 is now in [updates_old.md](https://github.com/vrtmrz/obsid
|
|||||||
- Now `Replicate` button or ribbon icon opens a redesigned interactive replication dialogue that performs smart bidirectional sync with a single click.
|
- Now `Replicate` button or ribbon icon opens a redesigned interactive replication dialogue that performs smart bidirectional sync with a single click.
|
||||||
- The vault rebuild flow (`replicateAllFromServer`) now opens the redesigned P2P Replication modal instead of a plain text selection dialogue, providing a consistent UI experience.
|
- The vault rebuild flow (`replicateAllFromServer`) now opens the redesigned P2P Replication modal instead of a plain text selection dialogue, providing a consistent UI experience.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
|
||||||
|
|
||||||
15th May, 2026
|
|
||||||
|
|
||||||
|
|
||||||
## 0.25.62
|
## 0.25.62
|
||||||
|
|
||||||
14th May, 2026
|
14th May, 2026
|
||||||
|
|||||||
Reference in New Issue
Block a user