Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// apertureOpts.videoCodec = 'hevc';
// }
console.log(`Collected settings after ${(Date.now() - past) / 1000}s`);
if (hideDesktopIcons) {
await desktopIcons.hide();
}
console.log(`Hide desktop icons after ${(Date.now() - past) / 1000}s`);
if (doNotDisturb) {
wasDoNotDisturbAlreadyEnabled = await dnd.isEnabled();
if (!wasDoNotDisturbAlreadyEnabled) {
dnd.enable();
}
}
console.log(`Took care of DND after ${(Date.now() - past) / 1000}s`);
try {
await aperture.startRecording(apertureOpts);
} catch (error) {
track('recording/stopped/error');
dialog.showErrorBox('Recording error', error.message);
past = null;
return;
}
const startTime = (Date.now() - past) / 1000;
if (startTime > 3) {
// TODO: figure out how to correctly process hevc videos with ffmpeg
// if (recordHevc) {
// apertureOpts.videoCodec = 'hevc';
// }
console.log(`Collected settings after ${(Date.now() - past) / 1000}s`);
if (hideDesktopIcons) {
await desktopIcons.hide();
}
console.log(`Hide desktop icons after ${(Date.now() - past) / 1000}s`);
if (doNotDisturb) {
wasDoNotDisturbAlreadyEnabled = await dnd.isEnabled();
if (!wasDoNotDisturbAlreadyEnabled) {
dnd.enable();
}
}
console.log(`Took care of DND after ${(Date.now() - past) / 1000}s`);
try {
await aperture.startRecording(apertureOpts);
} catch (error) {
track('recording/stopped/error');
dialog.showErrorBox('Recording error', error.message);
past = null;
return;
}
apertureOpts.audioDeviceId = audioInputDeviceId;
} else {
const [defaultAudioDevice] = await audioDevices();
apertureOpts.audioDeviceId = defaultAudioDevice && defaultAudioDevice.id;
}
}
if (app.kap.settings.get('hideDesktopIcons')) {
await desktopIcons.hide();
}
if (app.kap.settings.get('doNotDisturb')) {
wasDoNotDisturbAlreadyEnabled = await doNotDisturb.isEnabled();
if (!wasDoNotDisturbAlreadyEnabled) {
doNotDisturb.enable();
}
}
try {
await aperture.startRecording(apertureOpts);
ipcRenderer.send('did-start-recording');
log(`Started recording after ${(Date.now() - past) / 1000}s`);
} catch (err) {
// This prevents the button from being reset, since the recording has not yet started
// This delay is due to internal framework delays in aperture native code
if (err.message.includes('stopRecording')) {
log(`Recording not yet started, can't stop recording before it actually started`);
return;
}
ipcRenderer.send('will-stop-recording');
// In case for some reason the default audio device is not set
// use the first available device for recording
if (audioInputDeviceId) {
apertureOpts.audioDeviceId = audioInputDeviceId;
} else {
const [defaultAudioDevice] = await audioDevices();
apertureOpts.audioDeviceId = defaultAudioDevice && defaultAudioDevice.id;
}
}
if (app.kap.settings.get('hideDesktopIcons')) {
await desktopIcons.hide();
}
if (app.kap.settings.get('doNotDisturb')) {
wasDoNotDisturbAlreadyEnabled = await doNotDisturb.isEnabled();
if (!wasDoNotDisturbAlreadyEnabled) {
doNotDisturb.enable();
}
}
try {
await aperture.startRecording(apertureOpts);
ipcRenderer.send('did-start-recording');
log(`Started recording after ${(Date.now() - past) / 1000}s`);
} catch (err) {
// This prevents the button from being reset, since the recording has not yet started
// This delay is due to internal framework delays in aperture native code
if (err.message.includes('stopRecording')) {
log(`Recording not yet started, can't stop recording before it actually started`);
return;
(async () => {
switch (command) {
case 'on':
await doNotDisturb.enable();
break;
case 'off':
await doNotDisturb.disable();
break;
case 'toggle':
await doNotDisturb.toggle();
break;
case 'status':
console.log(await doNotDisturb.isEnabled() ? 'on' : 'off');
break;
default:
cli.showHelp();
}
})();
(async () => {
switch (command) {
case 'on':
await doNotDisturb.enable();
break;
case 'off':
await doNotDisturb.disable();
break;
case 'toggle':
await doNotDisturb.toggle();
break;
case 'status':
console.log(await doNotDisturb.isEnabled() ? 'on' : 'off');
break;
default:
cli.showHelp();
}
})();
(async () => {
switch (command) {
case 'on':
await doNotDisturb.enable();
break;
case 'off':
await doNotDisturb.disable();
break;
case 'toggle':
await doNotDisturb.toggle();
break;
case 'status':
console.log(await doNotDisturb.isEnabled() ? 'on' : 'off');
break;
default:
cli.showHelp();
}
})();
(async () => {
switch (command) {
case 'on':
await doNotDisturb.enable();
break;
case 'off':
await doNotDisturb.disable();
break;
case 'toggle':
await doNotDisturb.toggle();
break;
case 'status':
console.log(await doNotDisturb.isEnabled() ? 'on' : 'off');
break;
default:
cli.showHelp();
}
})();
const cleanup = () => {
const {
hideDesktopIcons,
doNotDisturb
} = lastUsedSettings;
closeAllCroppers();
resetTray();
if (hideDesktopIcons) {
desktopIcons.show();
}
if (doNotDisturb && !wasDoNotDisturbAlreadyEnabled) {
dnd.disable();
}
setCropperShortcutAction();
};
const stopRecording = async () => {
ipcRenderer.send('will-stop-recording');
const filePath = await aperture.stopRecording();
if (app.kap.settings.get('hideDesktopIcons')) {
desktopIcons.show();
}
if (app.kap.settings.get('doNotDisturb') && !wasDoNotDisturbAlreadyEnabled) {
doNotDisturb.disable();
}
ipcRenderer.send('stopped-recording');
ipcRenderer.send('open-editor-window', {filePath});
setMainWindowSize();
};