This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
/
window-manager.js
81 lines (68 loc) · 1.79 KB
/
window-manager.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
const gui = require('gui')
const AppMenu = require('../view/app-menu')
class WindowManager {
constructor() {
this.windows = []
this.config = {}
if (process.platform === 'darwin') {
this.appMenu = new AppMenu()
gui.app.setApplicationMenu(this.appMenu.menu)
gui.lifetime.onActivate = () => {
const MainWindow = require('../view/main-window')
new MainWindow()
}
} else {
this.menubars = []
}
}
initWithConfig(config) {
this.config = config
}
getConfig() {
for (const win of this.windows)
Object.assign(this.config, win.getConfig())
return this.config
}
addWindow(win) {
if (this.windows.includes(win))
throw new Error('Can not add existing window')
this.windows.push(win)
if (process.platform !== 'darwin') {
const menubar = new AppMenu(win)
this.menubars.push(menubar)
win.window.setMenuBar(menubar.menu)
}
win.initWithConfig(this.config)
win.window.onClose = () => this.removeWindow(win)
}
removeWindow(win) {
const i = this.windows.indexOf(win)
if (i === -1)
throw new Error('Removing unknown window')
this.windows.splice(i, 1)
win.unload()
if (process.platform !== 'darwin') {
this.menubars[i].unload()
this.menubars.splice(i, 1)
}
process.gc(true, 2)
}
getCurrentWindow() {
for (const win of this.windows) {
if (win.window.isActive())
return win
}
return null
}
quit() {
for (const win of this.windows)
win.window.close()
require('../view/notification-center').unload()
require('../controller/config-store').serialize()
gui.MessageLoop.quit()
process.gc(true, 2)
// Ignore pending Node.js works.
process.exit(0)
}
}
module.exports = new WindowManager