Stop Logger being a singleton
This commit is contained in:
parent
d965265709
commit
3471a9c498
12 changed files with 147 additions and 138 deletions
|
|
@ -2,7 +2,7 @@ import type { IconName, WorkspaceLeaf } from "obsidian";
|
|||
import { ItemView, setIcon } from "obsidian";
|
||||
|
||||
import { intlFormatDistance } from "date-fns";
|
||||
import type { SyncHistory, HistoryEntry, Settings } from "sync-client";
|
||||
import type { HistoryEntry, SyncClient } from "sync-client";
|
||||
import { SyncType, SyncSource, SyncStatus, Logger } from "sync-client";
|
||||
|
||||
export class HistoryView extends ItemView {
|
||||
|
|
@ -12,15 +12,14 @@ export class HistoryView extends ItemView {
|
|||
|
||||
public constructor(
|
||||
leaf: WorkspaceLeaf,
|
||||
private readonly settings: Settings,
|
||||
private readonly history: SyncHistory
|
||||
private readonly client: SyncClient
|
||||
) {
|
||||
super(leaf);
|
||||
this.icon = HistoryView.ICON;
|
||||
|
||||
history.addSyncHistoryUpdateListener(() => {
|
||||
this.client.history.addSyncHistoryUpdateListener(() => {
|
||||
this.updateView().catch((_error: unknown) => {
|
||||
Logger.getInstance().error("Failed to update history view");
|
||||
this.client.logger.error("Failed to update history view");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -94,13 +93,13 @@ export class HistoryView extends ItemView {
|
|||
container.empty();
|
||||
container.createEl("h4", { text: "VaultLink History" });
|
||||
|
||||
const entries = this.history
|
||||
const entries = this.client.history
|
||||
.getEntries()
|
||||
.reverse()
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.status !== SyncStatus.NO_OP ||
|
||||
this.settings.getSettings().displayNoopSyncEvents
|
||||
this.client.settings.getSettings().displayNoopSyncEvents
|
||||
);
|
||||
|
||||
entries.forEach((entry) => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import type { WorkspaceLeaf } from "obsidian";
|
||||
import { ItemView } from "obsidian";
|
||||
import type VaultLinkPlugin from "src/vault-link-plugin";
|
||||
import type { Settings } from "sync-client";
|
||||
import { Logger } from "sync-client";
|
||||
import type { SyncClient } from "sync-client";
|
||||
|
||||
export class LogsView extends ItemView {
|
||||
public static readonly TYPE = "logs-view";
|
||||
|
|
@ -10,20 +9,24 @@ export class LogsView extends ItemView {
|
|||
|
||||
public constructor(
|
||||
private readonly plugin: VaultLinkPlugin,
|
||||
private readonly settings: Settings,
|
||||
private readonly client: SyncClient,
|
||||
leaf: WorkspaceLeaf
|
||||
) {
|
||||
super(leaf);
|
||||
this.icon = LogsView.ICON;
|
||||
Logger.getInstance().addOnMessageListener(() => {
|
||||
this.client.logger.addOnMessageListener(() => {
|
||||
this.updateView();
|
||||
});
|
||||
|
||||
settings.addOnSettingsChangeHandlers((newSettings, oldSettings) => {
|
||||
if (newSettings.minimumLogLevel !== oldSettings.minimumLogLevel) {
|
||||
this.updateView();
|
||||
this.client.settings.addOnSettingsChangeHandlers(
|
||||
(newSettings, oldSettings) => {
|
||||
if (
|
||||
newSettings.minimumLogLevel !== oldSettings.minimumLogLevel
|
||||
) {
|
||||
this.updateView();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
private static formatTimestamp(timestamp: Date): string {
|
||||
|
|
@ -78,8 +81,8 @@ export class LogsView extends ItemView {
|
|||
}
|
||||
);
|
||||
|
||||
const logs = Logger.getInstance().getMessages(
|
||||
this.settings.getSettings().minimumLogLevel
|
||||
const logs = this.client.logger.getMessages(
|
||||
this.client.settings.getSettings().minimumLogLevel
|
||||
);
|
||||
|
||||
if (logs.length === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue