mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-03 19:35:20 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 801bac9e09 |
@@ -51,7 +51,6 @@ import { EVENT_SETTING_SAVED, eventHub } from "@/common/events.ts";
|
|||||||
import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
|
import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
|
||||||
import type { LiveSyncCore } from "@/main.ts";
|
import type { LiveSyncCore } from "@/main.ts";
|
||||||
import { tryGetFilePath } from "@lib/common/utils.doc.ts";
|
import { tryGetFilePath } from "@lib/common/utils.doc.ts";
|
||||||
import { configureHiddenFileSyncMode } from "./configureHiddenFileSyncMode.ts";
|
|
||||||
type SyncDirection = "push" | "pull" | "safe" | "pullForce" | "pushForce";
|
type SyncDirection = "push" | "pull" | "safe" | "pullForce" | "pushForce";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -1833,35 +1832,43 @@ ${messageFetch}${messageOverwrite}${messageMerge}
|
|||||||
}
|
}
|
||||||
|
|
||||||
async configureHiddenFileSync(mode: keyof OPTIONAL_SYNC_FEATURES) {
|
async configureHiddenFileSync(mode: keyof OPTIONAL_SYNC_FEATURES) {
|
||||||
const result = await configureHiddenFileSyncMode(mode, {
|
if (
|
||||||
disable: async () => {
|
mode != "FETCH" &&
|
||||||
// await this.core.$allSuspendExtraSync();
|
mode != "OVERWRITE" &&
|
||||||
await this.core.services.setting.applyPartial(
|
mode != "MERGE" &&
|
||||||
{
|
mode != "DISABLE" &&
|
||||||
syncInternalFiles: false,
|
mode != "DISABLE_HIDDEN"
|
||||||
},
|
) {
|
||||||
true
|
|
||||||
);
|
|
||||||
// this.core.settings.syncInternalFiles = false;
|
|
||||||
// await this.core.saveSettings();
|
|
||||||
},
|
|
||||||
enable: async () => {
|
|
||||||
this._log("Gathering files for enabling Hidden File Sync", LOG_LEVEL_NOTICE);
|
|
||||||
await this.core.services.setting.applyPartial(
|
|
||||||
{
|
|
||||||
useAdvancedMode: true,
|
|
||||||
syncInternalFiles: true,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
},
|
|
||||||
initialise: async (direction) => {
|
|
||||||
await this.initialiseInternalFileSync(direction, true);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (result == "ignored" || result == "disabled") {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode == "DISABLE" || mode == "DISABLE_HIDDEN") {
|
||||||
|
// await this.core.$allSuspendExtraSync();
|
||||||
|
await this.core.services.setting.applyPartial(
|
||||||
|
{
|
||||||
|
syncInternalFiles: false,
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
// this.core.settings.syncInternalFiles = false;
|
||||||
|
// await this.core.saveSettings();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._log("Gathering files for enabling Hidden File Sync", LOG_LEVEL_NOTICE);
|
||||||
|
if (mode == "FETCH") {
|
||||||
|
await this.initialiseInternalFileSync("pullForce", true);
|
||||||
|
} else if (mode == "OVERWRITE") {
|
||||||
|
await this.initialiseInternalFileSync("pushForce", true);
|
||||||
|
} else if (mode == "MERGE") {
|
||||||
|
await this.initialiseInternalFileSync("safe", true);
|
||||||
|
}
|
||||||
|
await this.core.services.setting.applyPartial(
|
||||||
|
{
|
||||||
|
useAdvancedMode: true,
|
||||||
|
syncInternalFiles: true,
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
// this.plugin.settings.useAdvancedMode = true;
|
// this.plugin.settings.useAdvancedMode = true;
|
||||||
// this.plugin.settings.syncInternalFiles = true;
|
// this.plugin.settings.syncInternalFiles = true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
type HiddenFileSyncMode = "FETCH" | "OVERWRITE" | "MERGE" | "DISABLE" | "DISABLE_HIDDEN";
|
|
||||||
type HiddenFileSyncDirection = "pullForce" | "pushForce" | "safe";
|
|
||||||
|
|
||||||
type ConfigureHiddenFileSyncHandlers = {
|
|
||||||
disable: () => Promise<void>;
|
|
||||||
enable: () => Promise<void>;
|
|
||||||
initialise: (direction: HiddenFileSyncDirection) => Promise<void>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ConfigureHiddenFileSyncResult = "ignored" | "disabled" | "enabled";
|
|
||||||
|
|
||||||
function getInitialiseDirection(mode: keyof OPTIONAL_SYNC_FEATURES): HiddenFileSyncDirection | false {
|
|
||||||
if (mode == "FETCH") return "pullForce";
|
|
||||||
if (mode == "OVERWRITE") return "pushForce";
|
|
||||||
if (mode == "MERGE") return "safe";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isDisableMode(mode: keyof OPTIONAL_SYNC_FEATURES): boolean {
|
|
||||||
return mode == "DISABLE" || mode == "DISABLE_HIDDEN";
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHiddenFileSyncMode(mode: keyof OPTIONAL_SYNC_FEATURES): mode is HiddenFileSyncMode {
|
|
||||||
return mode == "FETCH" || mode == "OVERWRITE" || mode == "MERGE" || isDisableMode(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function configureHiddenFileSyncMode(
|
|
||||||
mode: keyof OPTIONAL_SYNC_FEATURES,
|
|
||||||
handlers: ConfigureHiddenFileSyncHandlers
|
|
||||||
): Promise<ConfigureHiddenFileSyncResult> {
|
|
||||||
if (!isHiddenFileSyncMode(mode)) {
|
|
||||||
return "ignored";
|
|
||||||
}
|
|
||||||
if (isDisableMode(mode)) {
|
|
||||||
await handlers.disable();
|
|
||||||
return "disabled";
|
|
||||||
}
|
|
||||||
const direction = getInitialiseDirection(mode);
|
|
||||||
if (direction === false) {
|
|
||||||
return "ignored";
|
|
||||||
}
|
|
||||||
await handlers.enable();
|
|
||||||
await handlers.initialise(direction);
|
|
||||||
return "enabled";
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
import { configureHiddenFileSyncMode } from "./configureHiddenFileSyncMode.ts";
|
|
||||||
|
|
||||||
describe("configureHiddenFileSyncMode", () => {
|
|
||||||
it.each([
|
|
||||||
["FETCH", "pullForce"],
|
|
||||||
["OVERWRITE", "pushForce"],
|
|
||||||
["MERGE", "safe"],
|
|
||||||
] as const)("enables hidden file sync before initialising %s", async (mode, direction) => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
const result = await configureHiddenFileSyncMode(mode, {
|
|
||||||
disable: vi.fn(async () => {
|
|
||||||
calls.push("disable");
|
|
||||||
}),
|
|
||||||
enable: vi.fn(async () => {
|
|
||||||
calls.push("enable");
|
|
||||||
}),
|
|
||||||
initialise: vi.fn(async (actualDirection) => {
|
|
||||||
calls.push(`init:${actualDirection}`);
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBe("enabled");
|
|
||||||
expect(calls).toEqual(["enable", `init:${direction}`]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each(["DISABLE", "DISABLE_HIDDEN"] as const)("disables hidden file sync immediately for %s", async (mode) => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
const result = await configureHiddenFileSyncMode(mode, {
|
|
||||||
disable: vi.fn(async () => {
|
|
||||||
calls.push("disable");
|
|
||||||
}),
|
|
||||||
enable: vi.fn(async () => {
|
|
||||||
calls.push("enable");
|
|
||||||
}),
|
|
||||||
initialise: vi.fn(async (direction) => {
|
|
||||||
calls.push(`init:${direction}`);
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBe("disabled");
|
|
||||||
expect(calls).toEqual(["disable"]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
+1
-1
Submodule src/lib updated: 87dc724c9d...5c1033485e
Reference in New Issue
Block a user