mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-15 05:42:31 +00:00
Aligned to eslint rules and fixed following things:
This commit may contains behavioural changes. - Fix for the issue with corrupted log displays - Wrap the activeDocument - Reduced potential type errors and strengthened certain checks - Made error handling more robust (by rewriting the error class)
This commit is contained in:
+14
-7
@@ -4,7 +4,7 @@ import globals from "globals";
|
|||||||
import { defineConfig, globalIgnores } from "eslint/config";
|
import { defineConfig, globalIgnores } from "eslint/config";
|
||||||
import * as sveltePlugin from "eslint-plugin-svelte";
|
import * as sveltePlugin from "eslint-plugin-svelte";
|
||||||
import svelteParser from "svelte-eslint-parser";
|
import svelteParser from "svelte-eslint-parser";
|
||||||
|
const warnWhileDev = "off"; // Change to "warn" to enable warnings for rules that are currently disabled.
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
globalIgnores([
|
globalIgnores([
|
||||||
// Build outputs and legacy files
|
// Build outputs and legacy files
|
||||||
@@ -64,6 +64,9 @@ export default defineConfig([
|
|||||||
project: "./tsconfig.json",
|
project: "./tsconfig.json",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
linterOptions:{
|
||||||
|
reportUnusedDisableDirectives: false,
|
||||||
|
},
|
||||||
rules: {
|
rules: {
|
||||||
// -- Base rules (turned off in favour of TS specific versions or explicitly disabled).
|
// -- Base rules (turned off in favour of TS specific versions or explicitly disabled).
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
@@ -81,29 +84,33 @@ export default defineConfig([
|
|||||||
"@typescript-eslint/no-unsafe-return": "off",
|
"@typescript-eslint/no-unsafe-return": "off",
|
||||||
"@typescript-eslint/no-unsafe-assignment": "off",
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
||||||
// -- Reasonable rules.
|
// -- Reasonable rules.
|
||||||
"@typescript-eslint/no-deprecated": "warn",
|
"@typescript-eslint/no-deprecated": warnWhileDev,
|
||||||
"@typescript-eslint/no-unused-vars": ["error", { args: "none" }],
|
"@typescript-eslint/no-unused-vars": ["error", { args: "none" }],
|
||||||
"@typescript-eslint/ban-ts-comment": "off",
|
"@typescript-eslint/ban-ts-comment": "off",
|
||||||
"@typescript-eslint/no-empty-function": "off",
|
"@typescript-eslint/no-empty-function": "off",
|
||||||
"@typescript-eslint/require-await": "warn",
|
"@typescript-eslint/require-await": "error",
|
||||||
"@typescript-eslint/no-misused-promises": "error",
|
"@typescript-eslint/no-misused-promises": "error",
|
||||||
"@typescript-eslint/no-floating-promises": "error",
|
"@typescript-eslint/no-floating-promises": "error",
|
||||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||||
|
|
||||||
// -- Obsidian rules
|
// -- Obsidian rules
|
||||||
// obsidianmd/no-unsupported-api: usually this project checks for API support at runtime, so this rule is not critical but can be helpful to catch potential issues.
|
// obsidianmd/no-unsupported-api: usually this project checks for API support at runtime, so this rule is not critical but can be helpful to catch potential issues.
|
||||||
"obsidianmd/no-unsupported-api": "warn",
|
"obsidianmd/no-unsupported-api": warnWhileDev,
|
||||||
|
|
||||||
// -- General rules
|
// -- General rules
|
||||||
"no-async-promise-executor": "warn",
|
"no-async-promise-executor": warnWhileDev,
|
||||||
"no-constant-condition": ["error", { checkLoops: false }],
|
"no-constant-condition": ["error", { checkLoops: false }],
|
||||||
// -- Disabled rules (Pending review)
|
// -- Disabled rules
|
||||||
// no-undef: This option breaks the global declarations for the library files and is not worth the effort to fix at this time.
|
// no-undef: This option breaks the global declarations for the library files and is not worth the effort to fix at this time.
|
||||||
"no-undef": "off",
|
"no-undef": "off",
|
||||||
|
|
||||||
// -- Plugin specific overrides (Pending review)
|
// -- Plugin specific overrides
|
||||||
"obsidianmd/rule-custom-message": "off",
|
"obsidianmd/rule-custom-message": "off",
|
||||||
"obsidianmd/ui/sentence-case": "off",
|
"obsidianmd/ui/sentence-case": "off",
|
||||||
|
"obsidianmd/no-plugin-as-component": "off",
|
||||||
|
|
||||||
|
// -- Temporary overrides for migration
|
||||||
|
"obsidianmd/no-static-styles-assignment": "off",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Generated
+8
-8
@@ -15,6 +15,7 @@
|
|||||||
"@smithy/middleware-apply-body-checksum": "^4.3.9",
|
"@smithy/middleware-apply-body-checksum": "^4.3.9",
|
||||||
"@smithy/protocol-http": "^5.3.9",
|
"@smithy/protocol-http": "^5.3.9",
|
||||||
"@smithy/querystring-builder": "^4.2.9",
|
"@smithy/querystring-builder": "^4.2.9",
|
||||||
|
"@smithy/util-retry": "^4.4.5",
|
||||||
"@trystero-p2p/nostr": "^0.24.0",
|
"@trystero-p2p/nostr": "^0.24.0",
|
||||||
"chokidar": "^4.0.0",
|
"chokidar": "^4.0.0",
|
||||||
"commander": "^14.0.3",
|
"commander": "^14.0.3",
|
||||||
@@ -3546,9 +3547,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@smithy/core": {
|
"node_modules/@smithy/core": {
|
||||||
"version": "3.24.3",
|
"version": "3.24.5",
|
||||||
"resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.24.3.tgz",
|
"resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.24.5.tgz",
|
||||||
"integrity": "sha512-Ep/7tPamGY8mgESE3LyLKtxJyy6U52WWAqr/3wial47Sj4u3PiIF73AOGI27UyLy9duTkhZbgzodOfLV4TduZg==",
|
"integrity": "sha512-Kt8phUg45M15EjhYAbZ+fFikYneijLu9Liugz8ZsYz2i8j0hzGv27LWKpEHYRfvj+LyCOSijpcR/2i8RouV+cA==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-crypto/crc32": "5.2.0",
|
"@aws-crypto/crc32": "5.2.0",
|
||||||
@@ -4149,13 +4150,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@smithy/util-retry": {
|
"node_modules/@smithy/util-retry": {
|
||||||
"version": "4.2.12",
|
"version": "4.4.5",
|
||||||
"resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-4.2.12.tgz",
|
"resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-4.4.5.tgz",
|
||||||
"integrity": "sha512-1zopLDUEOwumjcHdJ1mwBHddubYF8GMQvstVCLC54Y46rqoHwlIU+8ZzUeaBcD+WCJHyDGSeZ2ml9YSe9aqcoQ==",
|
"integrity": "sha512-W9Ovy9i02yGqtLlpqZNQuXNxXc5OPfXujnembxN/FxyBtGjJd8vKY0PQYEJ8FNybTOcXG+ZxsSsX23HOb3zQzg==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@smithy/service-error-classification": "^4.2.12",
|
"@smithy/core": "^3.24.5",
|
||||||
"@smithy/types": "^4.13.1",
|
|
||||||
"tslib": "^2.6.2"
|
"tslib": "^2.6.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+2
-1
@@ -130,16 +130,17 @@
|
|||||||
"@smithy/middleware-apply-body-checksum": "^4.3.9",
|
"@smithy/middleware-apply-body-checksum": "^4.3.9",
|
||||||
"@smithy/protocol-http": "^5.3.9",
|
"@smithy/protocol-http": "^5.3.9",
|
||||||
"@smithy/querystring-builder": "^4.2.9",
|
"@smithy/querystring-builder": "^4.2.9",
|
||||||
|
"@smithy/util-retry": "^4.4.5",
|
||||||
"@trystero-p2p/nostr": "^0.24.0",
|
"@trystero-p2p/nostr": "^0.24.0",
|
||||||
"chokidar": "^4.0.0",
|
"chokidar": "^4.0.0",
|
||||||
"commander": "^14.0.3",
|
"commander": "^14.0.3",
|
||||||
"obsidian": "^1.12.3",
|
|
||||||
"diff-match-patch": "^1.0.5",
|
"diff-match-patch": "^1.0.5",
|
||||||
"fflate": "^0.8.2",
|
"fflate": "^0.8.2",
|
||||||
"idb": "^8.0.3",
|
"idb": "^8.0.3",
|
||||||
"markdown-it": "^14.1.1",
|
"markdown-it": "^14.1.1",
|
||||||
"micromatch": "^4.0.0",
|
"micromatch": "^4.0.0",
|
||||||
"minimatch": "^10.2.2",
|
"minimatch": "^10.2.2",
|
||||||
|
"obsidian": "^1.12.3",
|
||||||
"octagonal-wheels": "^0.1.46",
|
"octagonal-wheels": "^0.1.46",
|
||||||
"pouchdb-adapter-leveldb": "^9.0.0",
|
"pouchdb-adapter-leveldb": "^9.0.0",
|
||||||
"qrcode-generator": "^1.4.4",
|
"qrcode-generator": "^1.4.4",
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ import { PluginDialogModal } from "./PluginDialogModal.ts";
|
|||||||
import { $msg } from "@/lib/src/common/i18n.ts";
|
import { $msg } from "@/lib/src/common/i18n.ts";
|
||||||
import type { InjectableServiceHub } from "../../lib/src/services/InjectableServices.ts";
|
import type { InjectableServiceHub } from "../../lib/src/services/InjectableServices.ts";
|
||||||
import type { LiveSyncCore } from "../../main.ts";
|
import type { LiveSyncCore } from "../../main.ts";
|
||||||
|
import { LiveSyncError } from "@lib/common/LSError.ts";
|
||||||
|
|
||||||
const d = "\u200b";
|
const d = "\u200b";
|
||||||
const d2 = "\n";
|
const d2 = "\n";
|
||||||
@@ -1069,10 +1070,10 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
const baseDir = this.configDir;
|
const baseDir = this.configDir;
|
||||||
try {
|
try {
|
||||||
if (!data.documentPath) throw "InternalError: Document path not exist";
|
if (!data.documentPath) throw new LiveSyncError("InternalError: Document path not exist");
|
||||||
const dx = await this.localDatabase.getDBEntry(data.documentPath);
|
const dx = await this.localDatabase.getDBEntry(data.documentPath);
|
||||||
if (dx == false) {
|
if (dx == false) {
|
||||||
throw "Not found on database";
|
throw new LiveSyncError("Not found on database");
|
||||||
}
|
}
|
||||||
const loadedData = deserialize(getDocDataAsArray(dx.data), {}) as PluginDataEx;
|
const loadedData = deserialize(getDocDataAsArray(dx.data), {}) as PluginDataEx;
|
||||||
for (const f of loadedData.files) {
|
for (const f of loadedData.files) {
|
||||||
@@ -1317,7 +1318,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
const docXDoc = await this.localDatabase.getDBEntryFromMeta(old, false, false);
|
const docXDoc = await this.localDatabase.getDBEntryFromMeta(old, false, false);
|
||||||
if (docXDoc == false) {
|
if (docXDoc == false) {
|
||||||
throw "Could not load the document";
|
throw new LiveSyncError("Could not load the document");
|
||||||
}
|
}
|
||||||
const dataSrc = getDocData(docXDoc.data);
|
const dataSrc = getDocData(docXDoc.data);
|
||||||
const dataStart = dataSrc.indexOf(DUMMY_END);
|
const dataStart = dataSrc.indexOf(DUMMY_END);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import { hiddenFilesEventCount, hiddenFilesProcessingCount } from "../../lib/src
|
|||||||
import { EVENT_SETTING_SAVED, eventHub } from "../../common/events.ts";
|
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";
|
||||||
type SyncDirection = "push" | "pull" | "safe" | "pullForce" | "pushForce";
|
type SyncDirection = "push" | "pull" | "safe" | "pullForce" | "pushForce";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -1047,7 +1048,7 @@ Offline Changed files: ${processFiles.length}`;
|
|||||||
}
|
}
|
||||||
notifyProgress();
|
notifyProgress();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this._log(`Failed to process storage change file:${file}`, logLevel);
|
this._log(`Failed to process storage change file:${tryGetFilePath(file)}`, logLevel);
|
||||||
this._log(ex, LOG_LEVEL_VERBOSE);
|
this._log(ex, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1159,7 +1160,7 @@ Offline Changed files: ${files.length}`;
|
|||||||
await this.trackDatabaseFileModification(path, "[Scanning]", true, onlyNew, file);
|
await this.trackDatabaseFileModification(path, "[Scanning]", true, onlyNew, file);
|
||||||
notifyProgress();
|
notifyProgress();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this._log(`Failed to process database changes:${file}`);
|
this._log(`Failed to process database changes:${tryGetFilePath(file)}`);
|
||||||
this._log(ex, LOG_LEVEL_VERBOSE);
|
this._log(ex, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -16,9 +16,8 @@ import { serialized } from "octagonal-wheels/concurrency/lock_v2";
|
|||||||
import { arrayToChunkedArray } from "octagonal-wheels/collection";
|
import { arrayToChunkedArray } from "octagonal-wheels/collection";
|
||||||
import { EVENT_ANALYSE_DB_USAGE, EVENT_REQUEST_PERFORM_GC_V3, eventHub } from "@/common/events";
|
import { EVENT_ANALYSE_DB_USAGE, EVENT_REQUEST_PERFORM_GC_V3, eventHub } from "@/common/events";
|
||||||
import type { LiveSyncCouchDBReplicator } from "@/lib/src/replication/couchdb/LiveSyncReplicator";
|
import type { LiveSyncCouchDBReplicator } from "@/lib/src/replication/couchdb/LiveSyncReplicator";
|
||||||
import { delay, parseHeaderValues } from "@/lib/src/common/utils";
|
import { delay } from "@/lib/src/common/utils";
|
||||||
import { generateCredentialObject } from "@/lib/src/replication/httplib";
|
// import { _requestToCouchDB } from "@/common/utils";
|
||||||
import { _requestToCouchDB } from "@/common/utils";
|
|
||||||
const DB_KEY_SEQ = "gc-seq";
|
const DB_KEY_SEQ = "gc-seq";
|
||||||
const DB_KEY_CHUNK_SET = "chunk-set";
|
const DB_KEY_CHUNK_SET = "chunk-set";
|
||||||
const DB_KEY_DOC_USAGE_MAP = "doc-usage-map";
|
const DB_KEY_DOC_USAGE_MAP = "doc-usage-map";
|
||||||
@@ -533,7 +532,7 @@ Success: ${successCount}, Errored: ${errored}`;
|
|||||||
const docMap = new Map<DocumentID, Set<DocumentInfo>>();
|
const docMap = new Map<DocumentID, Set<DocumentInfo>>();
|
||||||
const info = await db.info();
|
const info = await db.info();
|
||||||
// Total number of revisions to process (approximate)
|
// Total number of revisions to process (approximate)
|
||||||
const maxSeq = new Number(info.update_seq);
|
const maxSeq = Number.parseInt(`${info.update_seq ?? 0}`, 10);
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
let read = 0;
|
let read = 0;
|
||||||
let errored = 0;
|
let errored = 0;
|
||||||
@@ -759,68 +758,68 @@ Success: ${successCount}, Errored: ${errored}`;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Compact the database by temporarily setting the revision limit to 1.
|
// * Compact the database by temporarily setting the revision limit to 1.
|
||||||
* @returns
|
// * @returns
|
||||||
*/
|
// */
|
||||||
async compactDatabaseWithRevLimit() {
|
// async compactDatabaseWithRevLimit() {
|
||||||
// Temporarily set revs_limit to 1, perform compaction, and restore the original revs_limit.
|
// // Temporarily set revs_limit to 1, perform compaction, and restore the original revs_limit.
|
||||||
// Very dangerous operation, so now suppressed.
|
// // Very dangerous operation, so now suppressed.
|
||||||
return false;
|
// return Promise.resolve(false);
|
||||||
const replicator = this.core.replicator as LiveSyncCouchDBReplicator;
|
// const replicator = this.core.replicator as LiveSyncCouchDBReplicator;
|
||||||
const remote = await replicator.connectRemoteCouchDBWithSetting(this.settings, false, false, true);
|
// const remote = await replicator.connectRemoteCouchDBWithSetting(this.settings, false, false, true);
|
||||||
if (!remote) {
|
// if (!remote) {
|
||||||
this._notice("Failed to connect to remote for compaction.");
|
// this._notice("Failed to connect to remote for compaction.");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (typeof remote == "string") {
|
// if (typeof remote == "string") {
|
||||||
this._notice(`Failed to connect to remote for compaction. ${remote}`);
|
// this._notice(`Failed to connect to remote for compaction. ${remote}`);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const customHeaders = parseHeaderValues(this.settings.couchDB_CustomHeaders);
|
// const customHeaders = parseHeaderValues(this.settings.couchDB_CustomHeaders);
|
||||||
const credential = generateCredentialObject(this.settings);
|
// const credential = generateCredentialObject(this.settings);
|
||||||
const request = async (path: string, method: string = "GET", body: any = undefined) => {
|
// const request = async (path: string, method: string = "GET", body: any = undefined) => {
|
||||||
const req = await _requestToCouchDB(
|
// const req = await _requestToCouchDB(
|
||||||
this.settings.couchDB_URI.replace(/\/+$/, "") +
|
// this.settings.couchDB_URI.replace(/\/+$/, "") +
|
||||||
(this.settings.couchDB_DBNAME ? `/${this.settings.couchDB_DBNAME}` : ""),
|
// (this.settings.couchDB_DBNAME ? `/${this.settings.couchDB_DBNAME}` : ""),
|
||||||
credential,
|
// credential,
|
||||||
window.origin,
|
// window.origin,
|
||||||
path,
|
// path,
|
||||||
body,
|
// body,
|
||||||
method,
|
// method,
|
||||||
customHeaders
|
// customHeaders
|
||||||
);
|
// );
|
||||||
return req;
|
// return req;
|
||||||
};
|
// };
|
||||||
let revsLimit = "";
|
// let revsLimit = "";
|
||||||
const req = await request(`_revs_limit`, "GET");
|
// const req = await request(`_revs_limit`, "GET");
|
||||||
if (req.status == 200) {
|
// if (req.status == 200) {
|
||||||
revsLimit = req.text.trim();
|
// revsLimit = req.text.trim();
|
||||||
this._info(`Remote database _revs_limit: ${revsLimit}`);
|
// this._info(`Remote database _revs_limit: ${revsLimit}`);
|
||||||
} else {
|
// } else {
|
||||||
this._notice(`Failed to get remote database _revs_limit. Status: ${req.status}`);
|
// this._notice(`Failed to get remote database _revs_limit. Status: ${req.status}`);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const req2 = await request(`_revs_limit`, "PUT", 1);
|
// const req2 = await request(`_revs_limit`, "PUT", 1);
|
||||||
if (req2.status == 200) {
|
// if (req2.status == 200) {
|
||||||
this._info(`Set remote database _revs_limit to 1 for compaction.`);
|
// this._info(`Set remote database _revs_limit to 1 for compaction.`);
|
||||||
}
|
// }
|
||||||
try {
|
// try {
|
||||||
await this.compactDatabase();
|
// await this.compactDatabase();
|
||||||
} finally {
|
// } finally {
|
||||||
// Restore revs_limit
|
// // Restore revs_limit
|
||||||
if (revsLimit) {
|
// if (revsLimit) {
|
||||||
const req3 = await request(`_revs_limit`, "PUT", parseInt(revsLimit));
|
// const req3 = await request(`_revs_limit`, "PUT", parseInt(revsLimit));
|
||||||
if (req3.status == 200) {
|
// if (req3.status == 200) {
|
||||||
this._info(`Restored remote database _revs_limit to ${revsLimit}.`);
|
// this._info(`Restored remote database _revs_limit to ${revsLimit}.`);
|
||||||
} else {
|
// } else {
|
||||||
this._notice(
|
// this._notice(
|
||||||
`Failed to restore remote database _revs_limit. Status: ${req3.status} / ${req3.text}`
|
// `Failed to restore remote database _revs_limit. Status: ${req3.status} / ${req3.text}`
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
async gcv3() {
|
async gcv3() {
|
||||||
if (!this.isAvailable()) return;
|
if (!this.isAvailable()) return;
|
||||||
const replicator = this.core.replicator as LiveSyncCouchDBReplicator;
|
const replicator = this.core.replicator as LiveSyncCouchDBReplicator;
|
||||||
|
|||||||
+1
-1
Submodule src/lib updated: af21598b78...2c6c1dfadb
@@ -1,10 +1,11 @@
|
|||||||
import { ButtonComponent } from "@/deps.ts";
|
import { ButtonComponent } from "@/deps.ts";
|
||||||
import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "../../../deps.ts";
|
import { App, FuzzySuggestModal, MarkdownRenderer, Modal, Plugin, Setting } from "../../../deps.ts";
|
||||||
import { EVENT_PLUGIN_UNLOADED, eventHub } from "../../../common/events.ts";
|
import { EVENT_PLUGIN_UNLOADED, eventHub } from "../../../common/events.ts";
|
||||||
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
import { compatGlobal, type CompatIntervalHandle } from "@lib/common/coreEnvFunctions.ts";
|
||||||
|
|
||||||
class AutoClosableModal extends Modal {
|
class AutoClosableModal extends Modal {
|
||||||
_closeByUnload() {
|
_closeByUnload() {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||||
eventHub.off(EVENT_PLUGIN_UNLOADED, this._closeByUnload);
|
eventHub.off(EVENT_PLUGIN_UNLOADED, this._closeByUnload);
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
@@ -12,9 +13,11 @@ class AutoClosableModal extends Modal {
|
|||||||
constructor(app: App) {
|
constructor(app: App) {
|
||||||
super(app);
|
super(app);
|
||||||
this._closeByUnload = this._closeByUnload.bind(this);
|
this._closeByUnload = this._closeByUnload.bind(this);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||||
eventHub.once(EVENT_PLUGIN_UNLOADED, this._closeByUnload);
|
eventHub.once(EVENT_PLUGIN_UNLOADED, this._closeByUnload);
|
||||||
}
|
}
|
||||||
override onClose() {
|
override onClose() {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||||
eventHub.off(EVENT_PLUGIN_UNLOADED, this._closeByUnload);
|
eventHub.off(EVENT_PLUGIN_UNLOADED, this._closeByUnload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +143,7 @@ export class MessageBox<T extends readonly string[]> extends AutoClosableModal {
|
|||||||
isManuallyClosed = false;
|
isManuallyClosed = false;
|
||||||
defaultAction: string | undefined;
|
defaultAction: string | undefined;
|
||||||
timeout: number | undefined;
|
timeout: number | undefined;
|
||||||
timer: ReturnType<typeof compatGlobal.setInterval> | undefined = undefined;
|
timer: CompatIntervalHandle | undefined = undefined;
|
||||||
defaultButtonComponent: ButtonComponent | undefined;
|
defaultButtonComponent: ButtonComponent | undefined;
|
||||||
wideButton: boolean;
|
wideButton: boolean;
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="path">
|
<td class="path">
|
||||||
<div class="filenames">
|
<div class="filenames">
|
||||||
<span class="path">/{entry.dirname.split("/").join(`/`)}</span>
|
<span class="path">/{entry.dirname.split("/").join(`\u200b/`)}</span>
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export class ModuleInteractiveConflictResolver extends AbstractObsidianModule {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this._log(`Merge: Something went wrong: ${filename}, (${toDelete})`, LOG_LEVEL_NOTICE);
|
this._log(`Merge: Something went wrong: ${filename}, (${toDelete as string})`, LOG_LEVEL_NOTICE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// In here, some merge has been processed.
|
// In here, some merge has been processed.
|
||||||
@@ -163,7 +163,7 @@ export class ModuleInteractiveConflictResolver extends AbstractObsidianModule {
|
|||||||
this._log(`There are no conflicting files`, LOG_LEVEL_VERBOSE);
|
this._log(`There are no conflicting files`, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._log(`Error while scanning conflicted files: ${e}`, LOG_LEVEL_NOTICE);
|
this._log(`Error while scanning conflicted files...`, LOG_LEVEL_NOTICE);
|
||||||
this._log(e, LOG_LEVEL_VERBOSE);
|
this._log(e, LOG_LEVEL_VERBOSE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
// if (runOnSaved) {
|
// if (runOnSaved) {
|
||||||
const handlers = this.onSavedHandlers
|
const handlers = this.onSavedHandlers
|
||||||
.filter((e) => appliedKeys.indexOf(e.key) !== -1)
|
.filter((e) => appliedKeys.indexOf(e.key) !== -1)
|
||||||
.map((e) => e.handler(this.editingSettings[e.key as AllSettingItemKey]));
|
.map((e) => Promise.resolve(e.handler(this.editingSettings[e.key as AllSettingItemKey])));
|
||||||
await Promise.all(handlers);
|
await Promise.all(handlers);
|
||||||
// }
|
// }
|
||||||
keys.forEach((e) => this.refreshSetting(e));
|
keys.forEach((e) => this.refreshSetting(e));
|
||||||
@@ -648,7 +648,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
this.editingSettings.passphrase = "";
|
this.editingSettings.passphrase = "";
|
||||||
}
|
}
|
||||||
await this.saveAllDirtySettings();
|
await this.saveAllDirtySettings();
|
||||||
await this.applyAllSettings();
|
await Promise.resolve(this.applyAllSettings());
|
||||||
if (result == OPTION_FETCH) {
|
if (result == OPTION_FETCH) {
|
||||||
await this.core.storageAccess.writeFileAuto(FLAGMD_REDFLAG3_HR, "");
|
await this.core.storageAccess.writeFileAuto(FLAGMD_REDFLAG3_HR, "");
|
||||||
this.services.appLifecycle.scheduleRestart();
|
this.services.appLifecycle.scheduleRestart();
|
||||||
@@ -739,6 +739,8 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
setLevelClass(el, level);
|
setLevelClass(el, level);
|
||||||
|
// TODO: Refactor to use Obsidian's recommended way to create heading.
|
||||||
|
// eslint-disable-next-line obsidianmd/settings-tab/no-manual-html-headings
|
||||||
el.createEl("h3", { text: title, cls: "sls-setting-pane-title" });
|
el.createEl("h3", { text: title, cls: "sls-setting-pane-title" });
|
||||||
if (this.menuEl) {
|
if (this.menuEl) {
|
||||||
this.menuEl.createEl(
|
this.menuEl.createEl(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
DEFAULT_SETTINGS,
|
DEFAULT_SETTINGS,
|
||||||
LOG_LEVEL_NOTICE,
|
LOG_LEVEL_NOTICE,
|
||||||
type ObsidianLiveSyncSettings,
|
type ObsidianLiveSyncSettings,
|
||||||
|
LOG_LEVEL_VERBOSE,
|
||||||
} from "../../../lib/src/common/types.ts";
|
} from "../../../lib/src/common/types.ts";
|
||||||
import { Menu } from "@/deps.ts";
|
import { Menu } from "@/deps.ts";
|
||||||
import { $msg } from "../../../lib/src/common/i18n.ts";
|
import { $msg } from "../../../lib/src/common/i18n.ts";
|
||||||
@@ -288,7 +289,8 @@ export function paneRemoteConfig(
|
|||||||
try {
|
try {
|
||||||
parsed = ConnectionStringParser.parse(trimmedURI);
|
parsed = ConnectionStringParser.parse(trimmedURI);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this.services.API.addLog(`Failed to import remote configuration: ${ex}`, LOG_LEVEL_NOTICE);
|
this.services.API.addLog(`Failed to import remote configuration!`, LOG_LEVEL_NOTICE);
|
||||||
|
this.services.API.addLog(ex, LOG_LEVEL_VERBOSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,9 +345,10 @@ export function paneRemoteConfig(
|
|||||||
parsed = ConnectionStringParser.parse(config.uri);
|
parsed = ConnectionStringParser.parse(config.uri);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this.services.API.addLog(
|
this.services.API.addLog(
|
||||||
`Failed to parse remote configuration '${config.id}' for editing: ${ex}`,
|
`Failed to parse remote configuration '${config.id}' for editing!`,
|
||||||
LOG_LEVEL_NOTICE
|
LOG_LEVEL_NOTICE
|
||||||
);
|
);
|
||||||
|
this.services.API.addLog(ex, LOG_LEVEL_VERBOSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const workSettings = createBaseRemoteSettings();
|
const workSettings = createBaseRemoteSettings();
|
||||||
@@ -452,9 +455,10 @@ export function paneRemoteConfig(
|
|||||||
parsed = ConnectionStringParser.parse(config.uri);
|
parsed = ConnectionStringParser.parse(config.uri);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this.services.API.addLog(
|
this.services.API.addLog(
|
||||||
`Failed to parse remote configuration '${config.id}': ${ex}`,
|
`Failed to parse remote configuration '${config.id}' for fetching settings!`,
|
||||||
LOG_LEVEL_NOTICE
|
LOG_LEVEL_NOTICE
|
||||||
);
|
);
|
||||||
|
this.services.API.addLog(ex, LOG_LEVEL_VERBOSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const workSettings = createBaseRemoteSettings();
|
const workSettings = createBaseRemoteSettings();
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ export class SetupManager extends AbstractModule {
|
|||||||
const e2eeConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteE2EE, currentSetting);
|
const e2eeConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteE2EE, currentSetting);
|
||||||
if (e2eeConf === "cancelled") {
|
if (e2eeConf === "cancelled") {
|
||||||
this._log("E2EE configuration cancelled.", LOG_LEVEL_NOTICE);
|
this._log("E2EE configuration cancelled.", LOG_LEVEL_NOTICE);
|
||||||
return await false;
|
return false;
|
||||||
}
|
}
|
||||||
const newSetting = {
|
const newSetting = {
|
||||||
...currentSetting,
|
...currentSetting,
|
||||||
@@ -367,7 +367,7 @@ export class SetupManager extends AbstractModule {
|
|||||||
const qrResult = await this.dialogManager.open(ScanQRCode);
|
const qrResult = await this.dialogManager.open(ScanQRCode);
|
||||||
this._log("QR Code dialog closed.", LOG_LEVEL_VERBOSE);
|
this._log("QR Code dialog closed.", LOG_LEVEL_VERBOSE);
|
||||||
// Result is not used, but log it for debugging.
|
// Result is not used, but log it for debugging.
|
||||||
this._log(`QR Code result: ${qrResult}`, LOG_LEVEL_VERBOSE);
|
this._log(qrResult, LOG_LEVEL_VERBOSE);
|
||||||
// QR Code instruction dialog never yields settings directly.
|
// QR Code instruction dialog never yields settings directly.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import type { InjectableServiceHub } from "@lib/services/implements/injectable/I
|
|||||||
import type { LiveSyncCore } from "../../main.ts";
|
import type { LiveSyncCore } from "../../main.ts";
|
||||||
import { initialiseWorkerModule } from "@lib/worker/bgWorker.ts";
|
import { initialiseWorkerModule } from "@lib/worker/bgWorker.ts";
|
||||||
import { manifestVersion, packageVersion } from "@lib/common/coreEnvVars.ts";
|
import { manifestVersion, packageVersion } from "@lib/common/coreEnvVars.ts";
|
||||||
|
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
|
||||||
|
|
||||||
export class ModuleLiveSyncMain extends AbstractModule {
|
export class ModuleLiveSyncMain extends AbstractModule {
|
||||||
async _onLiveSyncReady() {
|
async _onLiveSyncReady() {
|
||||||
@@ -97,7 +98,7 @@ export class ModuleLiveSyncMain extends AbstractModule {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const lsKey = "obsidian-live-sync-ver" + this.services.vault.getVaultName();
|
const lsKey = "obsidian-live-sync-ver" + this.services.vault.getVaultName();
|
||||||
const last_version = localStorage.getItem(lsKey);
|
const last_version = compatGlobal.localStorage.getItem(lsKey);
|
||||||
|
|
||||||
const lastVersion = ~~(versionNumberString2Number(manifestVersion) / 1000);
|
const lastVersion = ~~(versionNumberString2Number(manifestVersion) / 1000);
|
||||||
if (lastVersion > this.settings.lastReadUpdates && this.settings.isConfigured) {
|
if (lastVersion > this.settings.lastReadUpdates && this.settings.isConfigured) {
|
||||||
@@ -119,7 +120,7 @@ export class ModuleLiveSyncMain extends AbstractModule {
|
|||||||
this.settings.versionUpFlash = $msg("moduleLiveSyncMain.logVersionUpdate");
|
this.settings.versionUpFlash = $msg("moduleLiveSyncMain.logVersionUpdate");
|
||||||
await this.saveSettings();
|
await this.saveSettings();
|
||||||
}
|
}
|
||||||
localStorage.setItem(lsKey, `${VER}`);
|
compatGlobal.localStorage.setItem(lsKey, `${VER}`);
|
||||||
await this.services.database.openDatabase({
|
await this.services.database.openDatabase({
|
||||||
databaseEvents: this.services.databaseEvents,
|
databaseEvents: this.services.databaseEvents,
|
||||||
replicator: this.services.replicator,
|
replicator: this.services.replicator,
|
||||||
@@ -129,7 +130,7 @@ export class ModuleLiveSyncMain extends AbstractModule {
|
|||||||
// this.$$replicate = this.$$replicate.bind(this);
|
// this.$$replicate = this.$$replicate.bind(this);
|
||||||
// this.core.$$onLiveSyncReady = this.core.$$onLiveSyncReady.bind(this);
|
// this.core.$$onLiveSyncReady = this.core.$$onLiveSyncReady.bind(this);
|
||||||
await this.core.services.appLifecycle.onLoaded();
|
await this.core.services.appLifecycle.onLoaded();
|
||||||
await Promise.all(this.core.addOns.map((e) => e.onload()));
|
await Promise.all(this.core.addOns.map((e) => Promise.resolve(e.onload())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { compatGlobal } from "@/lib/src/common/coreEnvFunctions";
|
||||||
import { type ObsidianLiveSyncSettings } from "@lib/common/types";
|
import { type ObsidianLiveSyncSettings } from "@lib/common/types";
|
||||||
import { EVENT_REQUEST_RELOAD_SETTING_TAB, EVENT_SETTING_SAVED } from "@lib/events/coreEvents";
|
import { EVENT_REQUEST_RELOAD_SETTING_TAB, EVENT_SETTING_SAVED } from "@lib/events/coreEvents";
|
||||||
import { eventHub } from "@lib/hub/hub";
|
import { eventHub } from "@lib/hub/hub";
|
||||||
@@ -17,13 +18,16 @@ export class ObsidianSettingService<T extends ObsidianServiceContext> extends Se
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
protected setItem(key: string, value: string) {
|
protected setItem(key: string, value: string) {
|
||||||
return localStorage.setItem(key, value);
|
// TODO: Implement nativeLocalStorage.
|
||||||
|
return compatGlobal.localStorage.setItem(key, value);
|
||||||
}
|
}
|
||||||
protected getItem(key: string): string {
|
protected getItem(key: string): string {
|
||||||
return localStorage.getItem(key) ?? "";
|
// TODO: Implement nativeLocalStorage.
|
||||||
|
return compatGlobal.localStorage.getItem(key) ?? "";
|
||||||
}
|
}
|
||||||
protected deleteItem(key: string): void {
|
protected deleteItem(key: string): void {
|
||||||
localStorage.removeItem(key);
|
// TODO: Implement nativeLocalStorage.
|
||||||
|
compatGlobal.localStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async saveData(data: ObsidianLiveSyncSettings): Promise<void> {
|
protected override async saveData(data: ObsidianLiveSyncSettings): Promise<void> {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export function createFetchAllFlagHandler(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { vault, extra } = method;
|
const { vault, extra } = method;
|
||||||
const settings = await host.services.setting.currentSettings();
|
const settings = await Promise.resolve(host.services.setting.currentSettings());
|
||||||
// If remote is MinIO, makeLocalChunkBeforeSync is not available. (because no-deduplication on sending).
|
// If remote is MinIO, makeLocalChunkBeforeSync is not available. (because no-deduplication on sending).
|
||||||
const makeLocalChunkBeforeSyncAvailable = settings.remoteType !== REMOTE_MINIO;
|
const makeLocalChunkBeforeSyncAvailable = settings.remoteType !== REMOTE_MINIO;
|
||||||
const mapVaultStateToAction = {
|
const mapVaultStateToAction = {
|
||||||
|
|||||||
Reference in New Issue
Block a user