-
-
Notifications
You must be signed in to change notification settings - Fork 610
Expand file tree
/
Copy pathipc_handler.ts
More file actions
37 lines (31 loc) · 1.2 KB
/
ipc_handler.ts
File metadata and controls
37 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { addListener, addHandler } from 'backend/ipc'
import { existsSync } from 'graceful-fs'
import { showItemInFolder } from '../utils'
import { logInfo, logError, LogPrefix } from '.'
import { getLogFilePath } from './paths'
import {
uploadLogFile,
deleteUploadedLogFile,
getUploadedLogFiles
} from './uploader'
import { readLastBytes } from 'backend/utils/filesystem/read_last_bytes'
import { decodeUTF8 } from 'backend/utils/strings'
addListener('logInfo', (e, message) => logInfo(message, LogPrefix.Frontend))
addListener('logError', (e, message) => logError(message, LogPrefix.Frontend))
addHandler('getLogContent', async (event, appNameOrRunner) => {
const logPath = getLogFilePath(appNameOrRunner)
const MAX_LOG_BYTES = 1024 * 1024 // 1 MB
if (existsSync(logPath)) {
const buffer = await readLastBytes(logPath, MAX_LOG_BYTES)
return decodeUTF8(buffer)
}
return ''
})
addListener('showLogFileInFolder', (e, args) =>
showItemInFolder(getLogFilePath(args))
)
addHandler('uploadLogFile', async (e, name, args) => uploadLogFile(name, args))
addHandler('deleteUploadedLogFile', async (e, url) =>
deleteUploadedLogFile(url)
)
addHandler('getUploadedLogFiles', async () => getUploadedLogFiles())