Skip to content

Commit

Permalink
refactor: Improve logs "copy text" function to match log file
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed May 10, 2024
1 parent ef945dd commit a137e68
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/renderer/components/pages/LogsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ export class LogsPage extends React.Component<LogsPageProps, LogsPageState> {
}

onCopyClick = (): void => {
if (!navigator.clipboard) { throw new Error('Clipboard API is not available.'); }
const logData = this.getLogString();
navigator.clipboard.writeText(parseHtmlToText(logData));
if (!navigator.clipboard) {
alert("Clipboard not available, failed to copy logs to clipboard");
}
const logData = window.Shared.log.entries.filter(l => window.Shared.preferences.data.showLogLevel[l.logLevel])
.map(formedLog => {
return `[${LogLevel[formedLog.logLevel].padEnd(5)}] [${(new Date(formedLog.timestamp)).toLocaleString('en-GB')}]: (${formedLog.source}) - ${formedLog.content}`;
})
.join('\n');
navigator.clipboard.writeText(logData);
};

onClearClick = (): void => {
Expand Down

0 comments on commit a137e68

Please sign in to comment.