UNPKG

4.68 kBJavaScriptView Raw
1const electron = require('electron')
2const {app, BrowserWindow, Menu} = electron
3
4// Keep a global reference of the window object, if you don't, the window will
5// be closed automatically when the JavaScript object is garbage collected.
6let mainWindow
7
8let createWindow = () => {
9 // Create the browser window.
10 mainWindow = new BrowserWindow({
11 width: 999,
12 height: 777,
13 // resizable: false,
14 // fullscreen: false,
15 titleBarStyle: 'hidden',
16 title: 'Entu SSG',
17 backgroundColor: '#ffffff'
18 })
19
20 // and load the index.html of the app.
21 mainWindow.loadURL(`file://${__dirname}/index.html`)
22
23 // Open the DevTools.
24 // mainWindow.webContents.openDevTools()
25
26 // Emitted when the window is closed.
27 mainWindow.on('closed', () => {
28 // Dereference the window object, usually you would store windows
29 // in an array if your app supports multi windows, this is the time
30 // when you should delete the corresponding element.
31 mainWindow = null
32 })
33}
34
35// This method will be called when Electron has finished
36// initialization and is ready to create browser windows.
37// Some APIs can only be used after this event occurs.
38app.on('ready', createWindow)
39
40// Quit when all windows are closed.
41app.on('window-all-closed', () => {
42 app.quit()
43 // On OS X it is common for applications and their menu bar
44 // to stay active until the user quits explicitly with Cmd + Q
45 // if (process.platform !== 'darwin') {
46 // app.quit()
47 // }
48})
49
50app.on('activate', () => {
51 // On OS X it's common to re-create a window in the app when the
52 // dock icon is clicked and there are no other windows open.
53 if (mainWindow === null) {
54 createWindow()
55 }
56})
57
58let template = [{
59 label: 'View',
60 submenu: [{
61 label: 'Reload',
62 accelerator: 'CmdOrCtrl+R',
63 click: (item, focusedWindow) => {
64 if (focusedWindow) {
65 // on reload, start fresh and close any old
66 // open secondary windows
67 if (focusedWindow.id === 1) {
68 BrowserWindow.getAllWindows().forEach(win => {
69 if (win.id > 1) {
70 win.close()
71 }
72 })
73 }
74 focusedWindow.reload()
75 }
76 }
77 }, {
78 label: 'Toggle Full Screen',
79 accelerator: (() => {
80 if (process.platform === 'darwin') {
81 return 'Ctrl+Command+F'
82 } else {
83 return 'F11'
84 }
85 })(),
86 click: (item, focusedWindow) => {
87 if (focusedWindow) {
88 focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
89 }
90 }
91 }, {
92 label: 'Toggle Developer Tools',
93 accelerator: (() => {
94 if (process.platform === 'darwin') {
95 return 'Alt+Command+I'
96 } else {
97 return 'Ctrl+Shift+I'
98 }
99 })(),
100 click: (item, focusedWindow) => {
101 if (focusedWindow) {
102 focusedWindow.toggleDevTools()
103 }
104 }
105 }]
106}, {
107 label: 'Window',
108 role: 'window',
109 submenu: [{
110 label: 'Minimize',
111 accelerator: 'CmdOrCtrl+M',
112 role: 'minimize'
113 }]
114}, {
115 label: 'Help',
116 role: 'help',
117 submenu: [{
118 label: 'Learn More',
119 click: () => {
120 electron.shell.openExternal('http://ssg.entu.eu')
121 }
122 }]
123}]
124
125if (process.platform === 'darwin') {
126 const name = electron.app.getName()
127 template.unshift({
128 label: name,
129 submenu: [{
130 label: `About ${name}`,
131 role: 'about'
132 }, {
133 type: 'separator'
134 }, {
135 label: 'Services',
136 role: 'services',
137 submenu: []
138 }, {
139 type: 'separator'
140 }, {
141 label: `Hide ${name}`,
142 accelerator: 'Command+H',
143 role: 'hide'
144 }, {
145 label: 'Hide Others',
146 accelerator: 'Command+Alt+H',
147 role: 'hideothers'
148 }, {
149 label: 'Show All',
150 role: 'unhide'
151 }, {
152 type: 'separator'
153 }, {
154 label: 'Quit',
155 accelerator: 'Command+Q',
156 click: () => {
157 app.quit()
158 }
159 }]
160 })
161} else if (process.platform === 'win32') {
162 const helpMenu = template[template.length - 1].submenu
163}
164
165app.on('ready', () => {
166 const menu = Menu.buildFromTemplate(template)
167 Menu.setApplicationMenu(menu)
168})