From e22d044913abbc3847d3d5b126ba02422375b94b Mon Sep 17 00:00:00 2001 From: yougotwill Date: Wed, 21 Aug 2024 18:09:52 +1000 Subject: [PATCH] feat: added new save logs to desktop use instead of showing the debug window --- preload.js | 4 ++++ .../message/message-content/MessageStatus.tsx | 10 ++++------ .../overlay/message-info/components/MessageInfo.tsx | 10 ++++------ ts/components/settings/section/CategoryHelp.tsx | 5 ++--- ts/util/logging.ts | 8 ++++++++ ts/window.d.ts | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/preload.js b/preload.js index 9ee45d477..662f35269 100644 --- a/preload.js +++ b/preload.js @@ -4,6 +4,7 @@ const { Storage } = require('./ts/util/storage'); const { isTestNet, isTestIntegration } = require('./ts/shared/env_vars'); +const os = require('os'); const url = require('url'); const _ = require('lodash'); @@ -26,6 +27,9 @@ window.getAppInstance = () => configAny.appInstance; window.getVersion = () => configAny.version; window.getCommitHash = () => configAny.commitHash; window.getNodeVersion = () => configAny.node_version; +window.getOSRelease = () => + `${os.type()} ${os.release()}, Node.js ${config.node_version} ${os.platform()} ${os.arch()}`; +window.saveLog = logText => ipcRenderer.send('save-debug-log', logText); window.sessionFeatureFlags = { useOnionRequests: true, diff --git a/ts/components/conversation/message/message-content/MessageStatus.tsx b/ts/components/conversation/message/message-content/MessageStatus.tsx index 307e2cb4d..5d3e72b58 100644 --- a/ts/components/conversation/message/message-content/MessageStatus.tsx +++ b/ts/components/conversation/message/message-content/MessageStatus.tsx @@ -1,5 +1,3 @@ -import { ipcRenderer } from 'electron'; -import { useCallback } from 'react'; import { useSelector } from 'react-redux'; import styled from 'styled-components'; import { useMessageExpirationPropsById } from '../../../../hooks/useParamSelector'; @@ -11,6 +9,7 @@ import { useSelectedIsGroupOrCommunity } from '../../../../state/selectors/selec import { SpacerXS } from '../../../basic/Text'; import { SessionIcon, SessionIconType } from '../../../icon'; import { ExpireTimer } from '../../ExpireTimer'; +import { saveLogToDesktop } from '../../../../util/logging'; type Props = { messageId: string; @@ -228,9 +227,6 @@ const MessageStatusRead = ({ }; const MessageStatusError = ({ dataTestId }: Omit) => { - const showDebugLog = useCallback(() => { - ipcRenderer.send('show-debug-log'); - }, []); // when on error, we do not display the expire timer at all. const isGroup = useSelectedIsGroupOrCommunity(); @@ -238,7 +234,9 @@ const MessageStatusError = ({ dataTestId }: Omit) => { { + void saveLogToDesktop(); + }} title={window.i18n('sendFailed')} isIncoming={false} isGroup={isGroup} diff --git a/ts/components/conversation/right-panel/overlay/message-info/components/MessageInfo.tsx b/ts/components/conversation/right-panel/overlay/message-info/components/MessageInfo.tsx index d977ea8b8..2a00ae548 100644 --- a/ts/components/conversation/right-panel/overlay/message-info/components/MessageInfo.tsx +++ b/ts/components/conversation/right-panel/overlay/message-info/components/MessageInfo.tsx @@ -1,5 +1,4 @@ import { format, formatDistanceStrict } from 'date-fns'; -import { ipcRenderer } from 'electron'; import { isEmpty } from 'lodash'; import moment from 'moment'; @@ -24,6 +23,7 @@ import { useSelectedConversationKey } from '../../../../../../state/selectors/se import { Flex } from '../../../../../basic/Flex'; import { SpacerSM } from '../../../../../basic/Text'; import { CopyToClipboardIcon } from '../../../../../buttons'; +import { saveLogToDesktop } from '../../../../../../util/logging'; export const MessageInfoLabel = styled.label<{ color?: string }>` font-size: var(--font-size-lg); @@ -74,10 +74,6 @@ export const LabelWithInfo = (props: LabelWithInfoProps) => { // Message timestamp format: "06:02 PM Tue, 15/11/2022" const formatTimestamps = 'hh:mm A ddd, D/M/Y'; -const showDebugLog = () => { - ipcRenderer.send('show-debug-log'); -}; - const DebugMessageInfo = ({ messageId }: { messageId: string }) => { const convoId = useSelectedConversationKey(); const messageHash = useMessageHash(messageId); @@ -164,7 +160,9 @@ export const MessageInfo = ({ messageId, errors }: { messageId: string; errors: label={`${window.i18n('error')}:`} info={errorString || window.i18n('unknownError')} dataColor={'var(--danger-color)'} - onClick={showDebugLog} + onClick={() => { + void saveLogToDesktop(); + }} /> )} diff --git a/ts/components/settings/section/CategoryHelp.tsx b/ts/components/settings/section/CategoryHelp.tsx index 35f3e5e57..0b02407c1 100644 --- a/ts/components/settings/section/CategoryHelp.tsx +++ b/ts/components/settings/section/CategoryHelp.tsx @@ -1,15 +1,14 @@ -import { ipcRenderer } from 'electron'; - import { SessionButtonShape, SessionButtonType } from '../../basic/SessionButton'; import { SessionSettingButtonItem, SessionSettingsTitleWithLink } from '../SessionSettingListItem'; +import { saveLogToDesktop } from '../../../util/logging'; export const SettingsCategoryHelp = () => { return ( <> { - ipcRenderer.send('show-debug-log'); + void saveLogToDesktop(); }} buttonShape={SessionButtonShape.Square} buttonType={SessionButtonType.Solid} diff --git a/ts/util/logging.ts b/ts/util/logging.ts index b82cfd826..b8e25940a 100644 --- a/ts/util/logging.ts +++ b/ts/util/logging.ts @@ -148,3 +148,11 @@ window.addEventListener('unhandledrejection', rejectionEvent => { const errorInfo = error && error.stack ? error.stack : error; window.log.error('Top-level unhandled promise rejection:', errorInfo); }); + +export async function saveLogToDesktop() { + const operatingSystemInfo = `Operating System ${window.getOSRelease()}`; + const commitHashInfo = window.getCommitHash() ? `Commit ${window.getCommitHash()}` : ''; + const text = await fetchNodeLog(); + const debugLogWithSystemInfo = `${operatingSystemInfo} ${commitHashInfo} ${text}`; + window.saveLog(debugLogWithSystemInfo); +} diff --git a/ts/window.d.ts b/ts/window.d.ts index e7f973264..dbefbba98 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -82,6 +82,7 @@ declare global { getCommitHash: () => string | undefined; getVersion: () => string; getOSRelease: () => string; + saveLog: (text: string) => void; setAutoHideMenuBar: (val: boolean) => void; setMenuBarVisibility: (val: boolean) => void; contextMenuShown: boolean; @@ -98,7 +99,6 @@ declare global { getOpengroupPruning: () => Promise; setOpengroupPruning: (val: boolean) => Promise; closeAbout: () => void; - closeDebugLog: () => void; getAutoUpdateEnabled: () => boolean; setAutoUpdateEnabled: (enabled: boolean) => void; setZoomFactor: (newZoom: number) => void;