forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
112 lines (89 loc) · 2.75 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
'use strict';
const {app} = require('electron');
const prepareNext = require('electron-next');
const {is, enforceMacOSAppLocation} = require('electron-util');
const log = require('electron-log');
const {autoUpdater} = require('electron-updater');
const toMilliseconds = require('@sindresorhus/to-milliseconds');
const {initializeTray} = require('./tray');
const plugins = require('./common/plugins');
const {initializeAnalytics} = require('./common/analytics');
const initializeExportList = require('./export-list');
const {openCropperWindow, isCropperOpen, closeAllCroppers} = require('./cropper');
const {track} = require('./common/analytics');
const {initializeGlobalAccelerators} = require('./global-accelerators');
const {setApplicationMenu} = require('./menus');
const openFiles = require('./utils/open-files');
const {initializeExportOptions} = require('./export-options');
const settings = require('./common/settings');
const {hasMicrophoneAccess} = require('./common/system-permissions');
require('./utils/sentry');
const filesToOpen = [];
app.commandLine.appendSwitch('--enable-features', 'OverlayScrollbar');
app.on('open-file', (event, path) => {
event.preventDefault();
if (app.isReady()) {
track('editor/opened/running');
openFiles(path);
} else {
filesToOpen.push(path);
}
});
const initializePlugins = async () => {
if (!is.development) {
try {
await plugins.prune();
await plugins.upgrade();
} catch (error) {
console.log(error);
}
}
};
const checkForUpdates = () => {
if (is.development) {
return false;
}
// For auto-update debugging in Console.app
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
setInterval(() => {
autoUpdater.checkForUpdates();
}, toMilliseconds({hours: 1}));
autoUpdater.checkForUpdates();
};
// Prepare the renderer once the app is ready
(async () => {
await app.whenReady();
app.dock.hide();
// Ensure the app is in the Applications folder
enforceMacOSAppLocation();
// Ensure all plugins are up to date
initializePlugins();
await prepareNext('./renderer');
initializeAnalytics();
initializeTray();
initializeExportList();
initializeGlobalAccelerators();
initializeExportOptions();
setApplicationMenu();
if (filesToOpen.length > 0) {
track('editor/opened/startup');
openFiles(...filesToOpen);
} else if (
!app.getLoginItemSettings().wasOpenedAtLogin &&
(!settings.get('recordAudio') || hasMicrophoneAccess())
) {
openCropperWindow();
}
checkForUpdates();
})();
app.on('before-quit', closeAllCroppers);
app.on('window-all-closed', event => {
app.dock.hide();
event.preventDefault();
});
app.on('browser-window-created', () => {
if (!isCropperOpen()) {
app.dock.show();
}
});