Add copy to clipboard button
This commit is contained in:
parent
2ac5060315
commit
4288b47ace
2 changed files with 53 additions and 4 deletions
|
|
@ -14,10 +14,24 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logs-controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--size-4-2);
|
||||||
|
|
||||||
|
button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--size-2-1);
|
||||||
|
padding: var(--size-2-2) var(--size-4-2);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.logs-container {
|
.logs-container {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import "./logs-view.scss";
|
import "./logs-view.scss";
|
||||||
|
|
||||||
import type { WorkspaceLeaf } from "obsidian";
|
import type { WorkspaceLeaf } from "obsidian";
|
||||||
import { ItemView } from "obsidian";
|
import { ItemView, Notice, setIcon } from "obsidian";
|
||||||
import type { LogLine } from "sync-client";
|
import type { LogLine } from "sync-client";
|
||||||
import { LogLevel, type SyncClient } from "sync-client";
|
import { LogLevel, type SyncClient } from "sync-client";
|
||||||
|
|
||||||
|
|
@ -78,7 +78,16 @@ export class LogsView extends ItemView {
|
||||||
text: "VaultLink logs"
|
text: "VaultLink logs"
|
||||||
});
|
});
|
||||||
|
|
||||||
verbositySection.createEl("select", {}, (dropdown) => {
|
const controls = verbositySection.createDiv({ cls: "logs-controls" });
|
||||||
|
|
||||||
|
const copyButton = controls.createEl("button", {
|
||||||
|
text: "Copy logs",
|
||||||
|
cls: "clickable-icon"
|
||||||
|
});
|
||||||
|
setIcon(copyButton, "clipboard-copy");
|
||||||
|
copyButton.addEventListener("click", () => this.copyLogsToClipboard());
|
||||||
|
|
||||||
|
controls.createEl("select", {}, (dropdown) => {
|
||||||
logLevels.forEach(({ label, value }) =>
|
logLevels.forEach(({ label, value }) =>
|
||||||
dropdown.createEl("option", { text: label, value })
|
dropdown.createEl("option", { text: label, value })
|
||||||
);
|
);
|
||||||
|
|
@ -102,6 +111,32 @@ export class LogsView extends ItemView {
|
||||||
this.updateView();
|
this.updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private copyLogsToClipboard(): void {
|
||||||
|
const logs = this.client.logger.getMessages(this.minLogLevel);
|
||||||
|
|
||||||
|
if (logs.length === 0) {
|
||||||
|
new Notice("No logs to copy");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedLogs = logs
|
||||||
|
.map((logLine) => {
|
||||||
|
const timestamp = logLine.timestamp.toLocaleString();
|
||||||
|
const level = logLine.level.toUpperCase();
|
||||||
|
return `[${timestamp}] ${level}: ${logLine.message}`;
|
||||||
|
})
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
navigator.clipboard.writeText(formattedLogs)
|
||||||
|
.then(() => {
|
||||||
|
new Notice(`Copied ${logs.length} log entries to clipboard`);
|
||||||
|
})
|
||||||
|
.catch((error: unknown) => {
|
||||||
|
this.client.logger.error(`Failed to copy logs to clipboard: ${error}`);
|
||||||
|
new Notice("Failed to copy logs to clipboard");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private updateView(): void {
|
private updateView(): void {
|
||||||
const container = this.logsContainer;
|
const container = this.logsContainer;
|
||||||
if (container === undefined) {
|
if (container === undefined) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue