mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-12 17:25:56 +00:00
### Improved
- Now the plugin warns when we are on the several file-related situations that may cause unexpected behaviour (#300).
This commit is contained in:
@@ -35,6 +35,12 @@ import { $msg } from "src/lib/src/common/i18n.ts";
|
||||
import { P2PLogCollector } from "../../lib/src/replication/trystero/P2PReplicatorCore.ts";
|
||||
import type { LiveSyncCore } from "../../main.ts";
|
||||
import { LiveSyncError } from "@/lib/src/common/LSError.ts";
|
||||
import { isValidPath } from "@/common/utils.ts";
|
||||
import {
|
||||
isValidFilenameInAndroid,
|
||||
isValidFilenameInDarwin,
|
||||
isValidFilenameInWidows,
|
||||
} from "@/lib/src/string_and_binary/path.ts";
|
||||
|
||||
// This module cannot be a core module because it depends on the Obsidian UI.
|
||||
|
||||
@@ -229,19 +235,45 @@ export class ModuleLog extends AbstractObsidianModule {
|
||||
}
|
||||
|
||||
async getActiveFileStatus() {
|
||||
const reason = [] as string[];
|
||||
const reasonWarn = [] as string[];
|
||||
const thisFile = this.app.workspace.getActiveFile();
|
||||
if (!thisFile) return "";
|
||||
const validPath = isValidPath(thisFile.path);
|
||||
if (!validPath) {
|
||||
reason.push("This file has an invalid path under the current settings");
|
||||
} else {
|
||||
// The most narrow check: Filename validity on Windows
|
||||
const validOnWindows = isValidFilenameInWidows(thisFile.name);
|
||||
const validOnDarwin = isValidFilenameInDarwin(thisFile.name);
|
||||
const validOnAndroid = isValidFilenameInAndroid(thisFile.name);
|
||||
const labels = [];
|
||||
if (!validOnWindows) labels.push("🪟");
|
||||
if (!validOnDarwin) labels.push("🍎");
|
||||
if (!validOnAndroid) labels.push("🤖");
|
||||
if (labels.length > 0) {
|
||||
reasonWarn.push("Some platforms may be unable to process this file correctly: " + labels.join(" "));
|
||||
}
|
||||
}
|
||||
// Case Sensitivity
|
||||
if (this.services.setting.shouldCheckCaseInsensitively()) {
|
||||
const f = this.core.storageAccess
|
||||
.getFiles()
|
||||
.map((e) => e.path)
|
||||
.filter((e) => e.toLowerCase() == thisFile.path.toLowerCase());
|
||||
if (f.length > 1) return "Not synchronised: There are multiple files with the same name";
|
||||
if (f.length > 1) {
|
||||
reason.push("There are multiple files with the same name (case-insensitive match)");
|
||||
}
|
||||
}
|
||||
if (!(await this.services.vault.isTargetFile(thisFile.path))) return "Not synchronised: not a target file";
|
||||
if (this.services.vault.isFileSizeTooLarge(thisFile.stat.size)) return "Not synchronised: File size exceeded";
|
||||
return "";
|
||||
if (!(await this.services.vault.isTargetFile(thisFile.path))) {
|
||||
reason.push("This file is ignored by the ignore rules");
|
||||
}
|
||||
if (this.services.vault.isFileSizeTooLarge(thisFile.stat.size)) {
|
||||
reason.push("This file size exceeds the configured limit");
|
||||
}
|
||||
const result = reason.length > 0 ? "Not synchronised: " + reason.join(", ") : "";
|
||||
const warnResult = reasonWarn.length > 0 ? "Warning: " + reasonWarn.join(", ") : "";
|
||||
return [result, warnResult].filter((e) => e).join("\n");
|
||||
}
|
||||
async setFileStatus() {
|
||||
const fileStatus = await this.getActiveFileStatus();
|
||||
|
||||
Reference in New Issue
Block a user