forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.js
More file actions
86 lines (76 loc) · 2.22 KB
/
Copy pathbootstrap.js
File metadata and controls
86 lines (76 loc) · 2.22 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import path from 'path'
import { crashReporter, ipcRenderer } from 'electron'
import log from 'electron-log'
import RendererPaths from './node/paths'
let exceptionLogger = s => console.error(s)
const configureLogger = () => {
const { debug, paths, windowId } = global.marktext.env
log.transports.console.level = process.env.NODE_ENV === 'development' // mirror to window console
log.transports.mainConsole = null
log.transports.file.file = path.join(paths.logPath, `editor-${windowId}.log`)
log.transports.file.level = debug ? 'debug' : 'info'
log.transports.file.sync = false
log.transports.file.init()
exceptionLogger = log.error
}
const parseUrlArgs = () => {
const params = new URLSearchParams(window.location.search)
const codeFontFamily = params.get('cff')
const codeFontSize = params.get('cfs')
const debug = params.get('debug') === '1'
const hideScrollbar = params.get('hsb') === '1'
const theme = params.get('theme')
const titleBarStyle = params.get('tbs')
const userDataPath = params.get('udp')
const windowId = params.get('wid')
const type = params.get('type')
return {
type,
debug,
userDataPath,
windowId,
initialState: {
codeFontFamily,
codeFontSize,
hideScrollbar,
theme,
titleBarStyle
}
}
}
const bootstrapRenderer = () => {
// Start crash reporter to save core dumps for the renderer process
crashReporter.start({
companyName: 'marktext',
productName: 'marktext',
submitURL: 'http://0.0.0.0/',
uploadToServer: false
})
// Register renderer exception handler
window.addEventListener('error', event => {
const { message, name, stack } = event.error
const copy = {
message,
name,
stack
}
exceptionLogger(event.error)
// Pass exception to main process exception handler to show a error dialog.
ipcRenderer.send('AGANI::handle-renderer-error', copy)
})
const { debug, initialState, userDataPath, windowId, type } = parseUrlArgs()
const paths = new RendererPaths(userDataPath)
const marktext = {
initialState,
env: {
debug,
paths,
windowId,
type
},
paths
}
global.marktext = marktext
configureLogger()
}
export default bootstrapRenderer