-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
112 lines (97 loc) · 2.99 KB
/
index.js
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import {nativeTheme, app, Menu} from 'electron'
import {is} from 'electron-util'
import {CompositeDisposable, Disposable} from 'event-kit'
import {ipcMain as ipc} from 'electron-better-ipc'
import contextMenu from 'electron-context-menu'
import {pref} from './config-file'
import ProfileManager from './profile-manager'
import template from './app-menu'
import registerVisor from './windows/visor'
import ptyManager from './pty-manager'
import {argbBackground, makeWindow} from './utils'
if (!is.development) {
require('update-electron-app')()
}
let currentTerminalWindow = null
const windows = []
const subscriptions = new CompositeDisposable()
const profileManager = new ProfileManager(pref())
profileManager.validate()
subscriptions.add(new Disposable(() => profileManager.dispose()))
ptyManager(profileManager)
const resetApplicationMenu = () =>
Menu.setApplicationMenu(
Menu.buildFromTemplate(template(createWindow, profileManager))
)
const createWindow = () => {
const win = makeWindow(process.env.PAGE, {
width: 1000,
backgroundColor: argbBackground(profileManager, 'theme.background'),
vibrancy: profileManager.get('vibrancy')
})
contextMenu({
window: win,
shouldShowMenu: (event, params) => params.isEditable
})
win.on('focus', () => {
currentTerminalWindow = win
})
windows.push(win)
}
app.on('ready', () => {
registerVisor(profileManager)
createWindow()
resetApplicationMenu()
if (is.macos) {
app.dock.setMenu(Menu.buildFromTemplate([
{label: 'New Window', click: createWindow}
]))
}
})
app.on('window-all-closed', () => {
if (!is.macos) {
app.quit()
}
})
app.on('quit', () => subscriptions.dispose())
app.on('before-quit', () => {
windows.forEach(win => {
win.removeAllListeners('close')
})
})
app.on('activate', () => {
const activeWindow = windows.find(win => !win.isDestroyed())
if (!activeWindow) {
createWindow()
}
})
subscriptions.add(profileManager.onDidChange('vibrancy', value =>
windows.forEach(win => {
if (!win.isDestroyed()) {
win.setVibrancy(value)
}
})
))
subscriptions.add(profileManager.onDidChange('singleTabMode', resetApplicationMenu))
subscriptions.add(profileManager.onDidChange('name', resetApplicationMenu))
subscriptions.add(profileManager.onActiveProfileChange(resetApplicationMenu))
subscriptions.add(new Disposable(
ipc.answerRenderer('open-hamburger-menu', args => Menu.getApplicationMenu().popup(args))
))
subscriptions.add(new Disposable(
ipc.answerRenderer('search-next', ({query, options}) => {
ipc.callRenderer(currentTerminalWindow, 'search-next', {query, options})
})
))
subscriptions.add(new Disposable(
ipc.answerRenderer('search-previous', ({query, options}) => {
ipc.callRenderer(currentTerminalWindow, 'search-previous', {query, options})
})
))
const darkModeChange = () => {
ipc.sendToRenderers('dark-mode-changed')
}
nativeTheme.on('updated', darkModeChange)
subscriptions.add(new Disposable(() => {
nativeTheme.removeListener('updated', darkModeChange)
}))