|
1 |
| -import './index.css' |
| 1 | +import ContentCopyIcon from '@mui/icons-material/ContentCopy' |
| 2 | +import FolderOpenIcon from '@mui/icons-material/FolderOpen' |
2 | 3 | import React, { useEffect, useState } from 'react'
|
3 | 4 | import { useTranslation } from 'react-i18next'
|
4 |
| -import FolderOpenIcon from '@mui/icons-material/FolderOpen' |
5 |
| -import ContentCopyIcon from '@mui/icons-material/ContentCopy' |
6 |
| -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' |
7 |
| -import { faSyncAlt } from '@fortawesome/free-solid-svg-icons' |
| 5 | +import { UpdateComponent } from '../../../../components/UI' |
| 6 | +import './index.css' |
8 | 7 |
|
9 | 8 | const { ipcRenderer } = window.require('electron')
|
10 | 9 |
|
11 |
| -interface Props { |
| 10 | +interface LogBoxProps { |
| 11 | + logFileContent: string |
| 12 | +} |
| 13 | + |
| 14 | +const LogBox: React.FC<LogBoxProps> = ({ logFileContent }) => { |
| 15 | + const { t } = useTranslation() |
| 16 | + const maxLines = 1000 |
| 17 | + let sliced = false |
| 18 | + let lines = logFileContent.split('\n') |
| 19 | + if (lines.length > maxLines) { |
| 20 | + lines = ['...', ...lines.slice(-maxLines)] |
| 21 | + sliced = true |
| 22 | + } |
| 23 | + |
| 24 | + return ( |
| 25 | + <> |
| 26 | + {sliced && ( |
| 27 | + <span className="setting long-log-hint"> |
| 28 | + {t( |
| 29 | + 'settings.log.long-log-hint', |
| 30 | + 'Log truncated, last 1000 lines are shown!' |
| 31 | + )} |
| 32 | + </span> |
| 33 | + )} |
| 34 | + <span className="setting log-box"> |
| 35 | + {lines.map((line, key) => { |
| 36 | + if (line.toLowerCase().includes(' err')) { |
| 37 | + return ( |
| 38 | + <p key={key} className="log-error"> |
| 39 | + {line} |
| 40 | + </p> |
| 41 | + ) |
| 42 | + } else if (line.toLowerCase().includes(' warn')) { |
| 43 | + return ( |
| 44 | + <p key={key} className="log-warning"> |
| 45 | + {line} |
| 46 | + </p> |
| 47 | + ) |
| 48 | + } else { |
| 49 | + return ( |
| 50 | + <p key={key} className="log-info"> |
| 51 | + {line} |
| 52 | + </p> |
| 53 | + ) |
| 54 | + } |
| 55 | + })} |
| 56 | + </span> |
| 57 | + </> |
| 58 | + ) |
| 59 | +} |
| 60 | + |
| 61 | +export interface LogSettingsProps { |
12 | 62 | isDefault: boolean
|
13 | 63 | appName: string
|
14 | 64 | }
|
15 | 65 |
|
16 |
| -export default function LogSettings({ isDefault, appName }: Props) { |
| 66 | +export default function LogSettings({ isDefault, appName }: LogSettingsProps) { |
17 | 67 | const { t } = useTranslation()
|
18 | 68 | const [logFileContent, setLogFileContent] = useState<string>('')
|
19 | 69 | const [logFileExist, setLogFileExist] = useState<boolean>(false)
|
@@ -46,7 +96,7 @@ export default function LogSettings({ isDefault, appName }: Props) {
|
46 | 96 | }, 1000)
|
47 | 97 | return () => clearInterval(interval)
|
48 | 98 | }
|
49 |
| - }, [defaultLast]) |
| 99 | + }, [isDefault, defaultLast]) |
50 | 100 |
|
51 | 101 | function showLogFileInFolder() {
|
52 | 102 | ipcRenderer.send('showLogFileInFolder', { isDefault, appName })
|
@@ -79,11 +129,11 @@ export default function LogSettings({ isDefault, appName }: Props) {
|
79 | 129 | </span>
|
80 | 130 | )}
|
81 | 131 | {refreshing ? (
|
82 |
| - <span className="setting"> |
83 |
| - <FontAwesomeIcon className="icon" icon={faSyncAlt} /> |
| 132 | + <span className="setting log-box"> |
| 133 | + <UpdateComponent inline message={t('loading.default')} /> |
84 | 134 | </span>
|
85 | 135 | ) : (
|
86 |
| - formatLogBox() |
| 136 | + <LogBox logFileContent={logFileContent} /> |
87 | 137 | )}
|
88 | 138 | {logFileExist && (
|
89 | 139 | <span className="footerFlex">
|
@@ -127,50 +177,4 @@ export default function LogSettings({ isDefault, appName }: Props) {
|
127 | 177 | )}
|
128 | 178 | </>
|
129 | 179 | )
|
130 |
| - |
131 |
| - function formatLogBox() { |
132 |
| - const maxLines = 1000 |
133 |
| - let sliced = false |
134 |
| - let lines = logFileContent.split('\n') |
135 |
| - if (lines.length > maxLines) { |
136 |
| - lines = ['...', ...lines.slice(-maxLines)] |
137 |
| - sliced = true |
138 |
| - } |
139 |
| - |
140 |
| - return ( |
141 |
| - <> |
142 |
| - {sliced && ( |
143 |
| - <span className="setting long-log-hint"> |
144 |
| - {t( |
145 |
| - 'settings.log.long-log-hint', |
146 |
| - 'Log truncated, last 1000 lines are shown!' |
147 |
| - )} |
148 |
| - </span> |
149 |
| - )} |
150 |
| - <span className="setting log-box"> |
151 |
| - {lines.map((line, key) => { |
152 |
| - if (line.toLowerCase().includes(' err')) { |
153 |
| - return ( |
154 |
| - <p key={key} className="log-error"> |
155 |
| - {line} |
156 |
| - </p> |
157 |
| - ) |
158 |
| - } else if (line.toLowerCase().includes(' warn')) { |
159 |
| - return ( |
160 |
| - <p key={key} className="log-warning"> |
161 |
| - {line} |
162 |
| - </p> |
163 |
| - ) |
164 |
| - } else { |
165 |
| - return ( |
166 |
| - <p key={key} className="log-info"> |
167 |
| - {line} |
168 |
| - </p> |
169 |
| - ) |
170 |
| - } |
171 |
| - })} |
172 |
| - </span> |
173 |
| - </> |
174 |
| - ) |
175 |
| - } |
176 | 180 | }
|
0 commit comments