forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenus.js
200 lines (171 loc) · 4.36 KB
/
menus.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
'use strict';
const os = require('os');
const {Menu, app, dialog, BrowserWindow} = require('electron');
const {openNewGitHubIssue, appMenu} = require('electron-util');
const {ipcMain: ipc} = require('electron-better-ipc');
const {supportedVideoExtensions} = require('./common/constants');
const {openPrefsWindow} = require('./preferences');
const {openExportsWindow} = require('./exports');
const {openAboutWindow} = require('./about');
const {closeAllCroppers} = require('./cropper');
const {editorEmitter} = require('./editor');
const openFiles = require('./utils/open-files');
const issueBody = `
<!--
Thank you for helping us test Kap. Your feedback helps us make Kap better for everyone!
Before you continue; please make sure you've searched our existing issues to avoid duplicates. When you're ready to open a new issue, include as much information as possible. You can use the handy template below for bug reports.
Step to reproduce: If applicable, provide steps to reproduce the issue you're having.
Current behavior: A description of how Kap is currently behaving.
Expected behavior: How you expected Kap to behave.
Workaround: A workaround for the issue if you've found on. (this will help others experiencing the same issue!)
-->
**macOS version:** ${os.release()} (darwin)
**Kap version:** ${app.getVersion()}
#### Steps to reproduce
#### Current behavior
#### Expected behavior
#### Workaround
<!-- If you have additional information, enter it below. -->
`;
const openFileItem = {
label: 'Open Video…',
accelerator: 'Command+O',
click: async () => {
closeAllCroppers();
const {canceled, filePaths} = await dialog.showOpenDialog({
filters: [{name: 'Videos', extensions: supportedVideoExtensions}],
properties: ['openFile', 'multiSelections']
});
if (!canceled && filePaths) {
openFiles(...filePaths);
}
}
};
const sendFeedbackItem = {
label: 'Send Feedback…',
click() {
openNewGitHubIssue({
user: 'wulkano',
repo: 'kap',
body: issueBody
});
}
};
const aboutItem = {
label: `About ${app.getName()}`,
click: openAboutWindow
};
const exportHistoryItem = {
label: 'Export History',
click: openExportsWindow,
enabled: false,
id: 'exports'
};
const preferencesItem = {
label: 'Preferences…',
accelerator: 'Command+,',
click: () => openPrefsWindow()
};
const cogMenuTemplate = [
aboutItem,
{
type: 'separator'
},
sendFeedbackItem,
{
type: 'separator'
},
openFileItem,
exportHistoryItem,
{
type: 'separator'
},
preferencesItem,
{
type: 'separator'
},
{
role: 'quit',
accelerator: 'Command+Q'
}
];
const appMenuItem = appMenu([preferencesItem]);
appMenuItem.submenu[0] = aboutItem;
const applicationMenuTemplate = [
appMenuItem,
{
role: 'fileMenu',
submenu: [
openFileItem,
{
type: 'separator'
},
{
label: 'Save Original…',
id: 'saveOriginal',
accelerator: 'Command+S',
click: () => {
ipc.callRenderer(BrowserWindow.getFocusedWindow(), 'save-original');
}
},
{
type: 'separator'
},
{
role: 'close'
}
]
},
{
role: 'editMenu'
},
{
role: 'windowMenu',
submenu: [
{
role: 'minimize'
},
{
role: 'zoom'
},
{
type: 'separator'
},
exportHistoryItem,
{
type: 'separator'
},
{
role: 'front'
}
]
},
{
label: 'Help',
role: 'help',
submenu: [sendFeedbackItem]
}
];
const cogMenu = Menu.buildFromTemplate(cogMenuTemplate);
const cogExportsItem = cogMenu.getMenuItemById('exports');
const applicationMenu = Menu.buildFromTemplate(applicationMenuTemplate);
const applicationExportsItem = applicationMenu.getMenuItemById('exports');
const applicationSaveOriginalItem = applicationMenu.getMenuItemById('saveOriginal');
const toggleExportMenuItem = enabled => {
cogExportsItem.enabled = enabled;
applicationExportsItem.enabled = enabled;
};
const setApplicationMenu = () => {
Menu.setApplicationMenu(applicationMenu);
};
editorEmitter.on('blur', () => {
applicationSaveOriginalItem.visible = false;
});
editorEmitter.on('focus', () => {
applicationSaveOriginalItem.visible = true;
});
module.exports = {
cogMenu,
toggleExportMenuItem,
setApplicationMenu
};