forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetting.js
More file actions
98 lines (81 loc) · 2.83 KB
/
setting.js
File metadata and controls
98 lines (81 loc) · 2.83 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
93
94
95
96
97
98
import path from 'path'
import { BrowserWindow, ipcMain } from 'electron'
import { enable as remoteEnable } from '@electron/remote/main'
import { electronLocalshortcut } from '@hfelix/electron-localshortcut'
import BaseWindow, { WindowLifecycle, WindowType } from './base'
import { centerWindowOptions } from './utils'
import { TITLE_BAR_HEIGHT, preferencesWinOptions, isLinux, isOsx } from '../config'
class SettingWindow extends BaseWindow {
/**
* @param {Accessor} accessor The application accessor for application instances.
*/
constructor (accessor) {
super(accessor)
this.type = WindowType.SETTINGS
}
/**
* Creates a new setting window.
*
* @param {*} [options] BrowserWindow options.
*/
createWindow (options = {}) {
const { menu: appMenu, env, keybindings, preferences } = this._accessor
const winOptions = Object.assign({}, preferencesWinOptions, options)
centerWindowOptions(winOptions)
if (isLinux) {
winOptions.icon = path.join(__static, 'logo-96px.png')
}
// WORKAROUND: Electron has issues with different DPI per monitor when
// setting a fixed window size.
winOptions.resizable = true
// Enable native or custom/frameless window and titlebar
const { titleBarStyle, theme } = preferences.getAll()
if (!isOsx) {
winOptions.titleBarStyle = 'default'
if (titleBarStyle === 'native') {
winOptions.frame = true
}
}
winOptions.backgroundColor = this._getPreferredBackgroundColor(theme)
let win = this.browserWindow = new BrowserWindow(winOptions)
remoteEnable(win.webContents)
this.id = win.id
// Create a menu for the current window
appMenu.addSettingMenu(win)
win.once('ready-to-show', () => {
this.lifecycle = WindowLifecycle.READY
this.emit('window-ready')
})
win.on('focus', () => {
this.emit('window-focus')
win.webContents.send('mt::window-active-status', { status: true })
})
// Lost focus
win.on('blur', () => {
this.emit('window-blur')
win.webContents.send('mt::window-active-status', { status: false })
})
win.on('close', event => {
this.emit('window-close')
event.preventDefault()
ipcMain.emit('window-close-by-id', win.id)
})
// The window is now destroyed.
win.on('closed', () => {
this.emit('window-closed')
// Free window reference
win = null
})
this.lifecycle = WindowLifecycle.LOADING
win.loadURL(this._buildUrlString(this.id, env, preferences))
win.setSheetOffset(TITLE_BAR_HEIGHT)
const devToolsAccelerator = keybindings.getAccelerator('view.toggle-dev-tools')
if (env.debug && devToolsAccelerator) {
electronLocalshortcut.register(win, devToolsAccelerator, () => {
win.webContents.toggleDevTools()
})
}
return win
}
}
export default SettingWindow