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
92 lines (81 loc) · 2.21 KB
/
bootstrap.js
File metadata and controls
92 lines (81 loc) · 2.21 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
87
88
89
90
91
92
import path from 'path'
import { 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' ? 'info' : false // mirror to window console
log.transports.mainConsole = null
log.transports.file.resolvePath = () => path.join(paths.logPath, `editor-${windowId}.log`)
log.transports.file.level = debug ? 'debug' : 'info'
log.transports.file.sync = false
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 = Number(params.get('wid'))
const type = params.get('type')
if (Number.isNaN(windowId)) {
throw new Error('Error while parsing URL arguments: windowId!')
}
return {
type,
debug,
userDataPath,
windowId,
initialState: {
codeFontFamily,
codeFontSize,
hideScrollbar,
theme,
titleBarStyle
}
}
}
const bootstrapRenderer = () => {
// Register renderer exception handler
window.addEventListener('error', event => {
if (event.error) {
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('mt::handle-renderer-error', copy)
} else {
console.error(event)
}
})
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