From d85f93fb16aa505499e4d9b0bef0936edb4b2970 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Tue, 10 May 2022 11:02:39 +0200 Subject: [PATCH] allow opening the logs straight in the log viewer from settings --- .../session/settings/SettingsViewModel.js | 7 ++++- .../web/ui/session/settings/SettingsView.js | 29 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/domain/session/settings/SettingsViewModel.js b/src/domain/session/settings/SettingsViewModel.js index e7990844..d0f2e91d 100644 --- a/src/domain/session/settings/SettingsViewModel.js +++ b/src/domain/session/settings/SettingsViewModel.js @@ -136,9 +136,14 @@ export class SettingsViewModel extends ViewModel { } async exportLogs() { + const logs = await this.exportLogsBlob(); + this.platform.saveFileAs(logs, `hydrogen-logs-${this.platform.clock.now()}.json`); + } + + async exportLogsBlob() { const persister = this.logger.reporters.find(r => typeof r.export === "function"); const logExport = await persister.export(); - this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`); + return logExport.asBlob(); } async togglePushNotifications() { diff --git a/src/platform/web/ui/session/settings/SettingsView.js b/src/platform/web/ui/session/settings/SettingsView.js index 93e44307..58992d9f 100644 --- a/src/platform/web/ui/session/settings/SettingsView.js +++ b/src/platform/web/ui/session/settings/SettingsView.js @@ -98,13 +98,18 @@ export class SettingsView extends TemplateView { t.h3("Preferences"), row(t, vm.i18n`Scale down images when sending`, this._imageCompressionRange(t, vm)), ); + const logButtons = [t.button({onClick: () => vm.exportLogs()}, "Export")]; + if (import.meta.env.DEV) { + logButtons.push(t.button({onClick: () => openLogs(vm)}, "Open logs")); + } settingNodes.push( t.h3("Application"), row(t, vm.i18n`Version`, version), row(t, vm.i18n`Storage usage`, vm => `${vm.storageUsage} / ${vm.storageQuota}`), - row(t, vm.i18n`Debug logs`, t.button({onClick: () => vm.exportLogs()}, "Export")), + row(t, vm.i18n`Debug logs`, logButtons), t.p(["Debug logs contain application usage data including your username, the IDs or aliases of the rooms or groups you have visited, the usernames of other users and the names of files you send. They do not contain messages. For more information, review our ", t.a({href: "https://element.io/privacy", target: "_blank", rel: "noopener"}, "privacy policy"), "."]), + t.p([]) ); return t.main({className: "Settings middle"}, [ @@ -136,3 +141,25 @@ export class SettingsView extends TemplateView { })]; } } + +async function openLogs(vm) { + const logviewerUrl = (await import("../../../../../../scripts/logviewer/index.html?url")).default; + const win = window.open(logviewerUrl); + await new Promise(async r => { + let receivedPong = false; + const waitForPong = event => { + if (event.data.type === "pong") { + window.removeEventListener("message", waitForPong); + receivedPong = true; + r(); + } + }; + window.addEventListener("message", waitForPong); + while (!receivedPong) { + win.postMessage({type: "ping"}); + await new Promise(rr => setTimeout(rr), 100); + } + }); + const logs = await vm.exportLogsBlob(); + win.postMessage({type: "open", logs: logs.nativeBlob}); +}