mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-24 11:37:07 +00:00
Tagged downstream network errors to respect networkWarningStyle setting
This commit is contained in:
+1
-1
Submodule src/lib updated: 4ff3cad80b...c228285c53
@@ -116,7 +116,8 @@ export class ModuleReplicator extends AbstractModule {
|
|||||||
}
|
}
|
||||||
// Showing message is false: that because be shown here. (And it is a fatal error, no way to hide it).
|
// Showing message is false: that because be shown here. (And it is a fatal error, no way to hide it).
|
||||||
if (!(await this.ensureReplicatorPBKDF2Salt(false))) {
|
if (!(await this.ensureReplicatorPBKDF2Salt(false))) {
|
||||||
this.showError("Failed to initialise the encryption key, preventing replication.");
|
//tagged as network error at beginning for error filtering with NetworkWarningStyles
|
||||||
|
this.showError("\u{200b}Failed to initialise the encryption key, preventing replication.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await this.processor.restoreFromSnapshotOnce();
|
await this.processor.restoreFromSnapshotOnce();
|
||||||
@@ -218,7 +219,11 @@ Even if you choose to clean up, you will see this option again if you exit Obsid
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(await this.services.replication.onBeforeReplicate(showMessage))) {
|
if (!(await this.services.replication.onBeforeReplicate(showMessage))) {
|
||||||
this.showError($msg("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE);
|
// check for tagged network errors for filtering by NetworkWarningStyles
|
||||||
|
const hasNetworkError = [...this._previousErrors].some(e => e.startsWith("\u{200b}"));
|
||||||
|
if (!hasNetworkError) {
|
||||||
|
this.showError($msg("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.clearErrors();
|
this.clearErrors();
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ export class ModuleObsidianAPI extends AbstractObsidianModule {
|
|||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
this._log(`HTTP:${method}${size} to:${localURL} -> failed`, LOG_LEVEL_VERBOSE);
|
this._log(`HTTP:${method}${size} to:${localURL} -> failed`, LOG_LEVEL_VERBOSE);
|
||||||
const msg = ex instanceof Error ? `${ex?.name}:${ex?.message}` : ex?.toString();
|
const msg = ex instanceof Error ? `${ex?.name}:${ex?.message}` : ex?.toString();
|
||||||
this.showError(`Failed to fetch: ${msg}`); // Do not show notice, due to throwing below
|
this.showError(`\u{200b}Network Error: Failed to fetch: ${msg}`); // Do not show notice, due to throwing below
|
||||||
this._log(ex, LOG_LEVEL_VERBOSE);
|
this._log(ex, LOG_LEVEL_VERBOSE);
|
||||||
// limit only in bulk_docs.
|
// limit only in bulk_docs.
|
||||||
if (url.toString().indexOf("_bulk_docs") !== -1) {
|
if (url.toString().indexOf("_bulk_docs") !== -1) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import {
|
|||||||
isValidFilenameInDarwin,
|
isValidFilenameInDarwin,
|
||||||
isValidFilenameInWidows,
|
isValidFilenameInWidows,
|
||||||
} from "@/lib/src/string_and_binary/path.ts";
|
} from "@/lib/src/string_and_binary/path.ts";
|
||||||
|
import { NetworkWarningStyles } from "@lib/common/models/setting.const.ts"
|
||||||
|
|
||||||
// This module cannot be a core module because it depends on the Obsidian UI.
|
// This module cannot be a core module because it depends on the Obsidian UI.
|
||||||
|
|
||||||
@@ -155,14 +156,14 @@ export class ModuleLog extends AbstractObsidianModule {
|
|||||||
lastSyncPushSeq == 0
|
lastSyncPushSeq == 0
|
||||||
? ""
|
? ""
|
||||||
: lastSyncPushSeq >= maxPushSeq
|
: lastSyncPushSeq >= maxPushSeq
|
||||||
? " (LIVE)"
|
? " (LIVE)"
|
||||||
: ` (${maxPushSeq - lastSyncPushSeq})`;
|
: ` (${maxPushSeq - lastSyncPushSeq})`;
|
||||||
pullLast =
|
pullLast =
|
||||||
lastSyncPullSeq == 0
|
lastSyncPullSeq == 0
|
||||||
? ""
|
? ""
|
||||||
: lastSyncPullSeq >= maxPullSeq
|
: lastSyncPullSeq >= maxPullSeq
|
||||||
? " (LIVE)"
|
? " (LIVE)"
|
||||||
: ` (${maxPullSeq - lastSyncPullSeq})`;
|
: ` (${maxPullSeq - lastSyncPullSeq})`;
|
||||||
break;
|
break;
|
||||||
case "ERRORED":
|
case "ERRORED":
|
||||||
w = "⚠";
|
w = "⚠";
|
||||||
@@ -281,10 +282,19 @@ export class ModuleLog extends AbstractObsidianModule {
|
|||||||
const fileStatus = this.activeFileStatus.value;
|
const fileStatus = this.activeFileStatus.value;
|
||||||
if (fileStatus && !this.settings.hideFileWarningNotice) messageLines.push(fileStatus);
|
if (fileStatus && !this.settings.hideFileWarningNotice) messageLines.push(fileStatus);
|
||||||
const messages = (await this.services.appLifecycle.getUnresolvedMessages()).flat().filter((e) => e);
|
const messages = (await this.services.appLifecycle.getUnresolvedMessages()).flat().filter((e) => e);
|
||||||
if (this.settings.connectionWarningStyle === "banner") {
|
const stringMessages = messages.filter((m): m is string => typeof m === "string"); // for 'startsWith'
|
||||||
messageLines.push(...messages);
|
const networkMessages = stringMessages.filter(m => m.startsWith("\u{200b}"));
|
||||||
} else if (this.settings.connectionWarningStyle === "icon") {
|
const otherMessages = stringMessages.filter(m => !m.startsWith("\u{200b}"));
|
||||||
if (messages.length > 0) messageLines.push("🔗❌");
|
|
||||||
|
messageLines.push(...otherMessages);
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.settings.networkWarningStyle !== NetworkWarningStyles.ICON &&
|
||||||
|
this.settings.networkWarningStyle !== NetworkWarningStyles.HIDDEN
|
||||||
|
) {
|
||||||
|
messageLines.push(...networkMessages);
|
||||||
|
} else if (this.settings.networkWarningStyle === NetworkWarningStyles.ICON) {
|
||||||
|
if (networkMessages.length > 0) messageLines.push("🔗❌");
|
||||||
}
|
}
|
||||||
this.messageArea.innerText = messageLines.map((e) => `⚠️ ${e}`).join("\n");
|
this.messageArea.innerText = messageLines.map((e) => `⚠️ ${e}`).join("\n");
|
||||||
}
|
}
|
||||||
@@ -443,8 +453,8 @@ export class ModuleLog extends AbstractObsidianModule {
|
|||||||
typeof message == "string"
|
typeof message == "string"
|
||||||
? message
|
? message
|
||||||
: message instanceof Error
|
: message instanceof Error
|
||||||
? `${errorInfo}`
|
? `${errorInfo}`
|
||||||
: JSON.stringify(message, null, 2);
|
: JSON.stringify(message, null, 2);
|
||||||
const newMessage = timestamp + "->" + messageContent;
|
const newMessage = timestamp + "->" + messageContent;
|
||||||
if (message instanceof Error) {
|
if (message instanceof Error) {
|
||||||
console.error(vaultName + ":" + newMessage);
|
console.error(vaultName + ":" + newMessage);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab.ts
|
|||||||
import type { PageFunctions } from "./SettingPane.ts";
|
import type { PageFunctions } from "./SettingPane.ts";
|
||||||
import { visibleOnly } from "./SettingPane.ts";
|
import { visibleOnly } from "./SettingPane.ts";
|
||||||
import { EVENT_ON_UNRESOLVED_ERROR, eventHub } from "@/common/events.ts";
|
import { EVENT_ON_UNRESOLVED_ERROR, eventHub } from "@/common/events.ts";
|
||||||
|
import { NetworkWarningStyles } from "@lib/common/models/setting.const.ts";
|
||||||
export function paneGeneral(
|
export function paneGeneral(
|
||||||
this: ObsidianLiveSyncSettingTab,
|
this: ObsidianLiveSyncSettingTab,
|
||||||
paneEl: HTMLElement,
|
paneEl: HTMLElement,
|
||||||
@@ -25,14 +26,14 @@ export function paneGeneral(
|
|||||||
});
|
});
|
||||||
new Setting(paneEl).autoWireToggle("showStatusOnStatusbar");
|
new Setting(paneEl).autoWireToggle("showStatusOnStatusbar");
|
||||||
new Setting(paneEl).autoWireToggle("hideFileWarningNotice");
|
new Setting(paneEl).autoWireToggle("hideFileWarningNotice");
|
||||||
new Setting(paneEl).autoWireDropDown("connectionWarningStyle", {
|
new Setting(paneEl).autoWireDropDown("networkWarningStyle", {
|
||||||
options: {
|
options: {
|
||||||
banner: "Show full banner",
|
[NetworkWarningStyles.BANNER]: "Show full banner",
|
||||||
icon: "Show icon only",
|
[NetworkWarningStyles.ICON]: "Show icon only",
|
||||||
hidden: "Hide completely",
|
[NetworkWarningStyles.HIDDEN]: "Hide completely",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.addOnSaved("connectionWarningStyle", () => {
|
this.addOnSaved("networkWarningStyle", () => {
|
||||||
eventHub.emitEvent(EVENT_ON_UNRESOLVED_ERROR);
|
eventHub.emitEvent(EVENT_ON_UNRESOLVED_ERROR);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user