-
Notifications
You must be signed in to change notification settings - Fork 811
/
save-file-service.js
45 lines (38 loc) · 1012 Bytes
/
save-file-service.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
import fs from 'fs';
import {app, dialog} from 'electron';
import makeDir from 'make-dir';
const action = async context => {
const format = context.format;
let filters;
if (format === 'mp4') {
filters = [{name: 'Movies', extensions: ['mp4']}];
} else if (format === 'webm') {
filters = [{name: 'Movies', extensions: ['webm']}];
} else if (format === 'gif') {
filters = [{name: 'Images', extensions: ['gif']}];
} else {
filters = [{name: 'Images', extensions: ['apng']}];
}
const kapturesDir = app.kap.settings.get('kapturesDir');
await makeDir(kapturesDir);
const filePath = dialog.showSaveDialog(app.kap.editorWindow, {
title: context.defaultFileName,
defaultPath: `${kapturesDir}/${context.defaultFileName}`,
filters
});
if (!filePath) {
context.cancel();
return;
}
fs.renameSync(await context.filePath(), filePath);
};
module.exports = {
title: 'Save to Disk',
formats: [
'gif',
'mp4',
'webm',
'apng'
],
action
};