MCPcopy
hub / github.com/marktext/marktext / createWindow

Method createWindow

packages/desktop/src/main/windows/setting.ts:24–114  ·  view source on GitHub ↗

* Creates a new setting window. * * @param category The settings category tab name.

(category: string | null = null)

Source from the content-addressed store, hash-verified

22 * @param category The settings category tab name.
23 */
24 createWindow(category: string | null = null): BrowserWindow {
25 // eslint-disable-next-line @typescript-eslint/no-explicit-any
26 const accessor = this._accessor as any
27 const { menu: appMenu, env, keybindings, preferences } = accessor
28 const winOptions: BrowserWindowConstructorOptions = Object.assign({}, preferencesWinOptions)
29 centerWindowOptions(
30 winOptions as BrowserWindowConstructorOptions & {
31 width: number
32 height: number
33 x?: number
34 y?: number
35 }
36 )
37 if (isLinux) {
38 winOptions.icon = path.join(
39 (global as unknown as { __static: string }).__static,
40 'logo-96px.png'
41 )
42 }
43
44 // WORKAROUND: Electron has issues with different DPI per monitor when
45 // setting a fixed window size.
46 winOptions.resizable = true
47
48 // Enable native or custom/frameless window and titlebar
49 const { titleBarStyle, theme } = preferences.getAll()
50 if (!isOsx) {
51 winOptions.titleBarStyle = 'default'
52 if (titleBarStyle === 'native') {
53 winOptions.frame = true
54 }
55 }
56
57 winOptions.backgroundColor = this._getPreferredBackgroundColor(theme)
58 let win: BrowserWindow | null = (this.browserWindow = new BrowserWindow(winOptions))
59
60 win.webContents.on('did-fail-load', (_event, code, desc, url) => {
61 log.error(`did-fail-load ${code} ${desc} @ ${url}`)
62 })
63 win.webContents.on('render-process-gone', (_event, details) => {
64 log.error(`render-process-gone: ${details.reason} (${details.exitCode})`)
65 })
66
67 this.id = win.id
68
69 // Create a menu for the current window
70 appMenu.addSettingMenu(win)
71
72 win.once('ready-to-show', () => {
73 this.lifecycle = WindowLifecycle.READY
74 this.emit('window-ready')
75 })
76
77 win.on('focus', () => {
78 this.emit('window-focus')
79 win!.webContents.send('mt::window-active-status', { status: true })
80 })
81

Callers 1

_createSettingWindowMethod · 0.95

Calls 12

_buildUrlStringMethod · 0.95
centerWindowOptionsFunction · 0.90
joinMethod · 0.80
addSettingMenuMethod · 0.80
emitMethod · 0.80
sendMethod · 0.80
getAcceleratorMethod · 0.80
registerMethod · 0.80
getAllMethod · 0.65
onMethod · 0.65
onceMethod · 0.65

Tested by

no test coverage detected