Skip to content

Commit

Permalink
wulkano#129 cleanup before quitting while recording
Browse files Browse the repository at this point in the history
  • Loading branch information
thethomasz committed Sep 5, 2022
1 parent 2095f7a commit 52bb766
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
26 changes: 26 additions & 0 deletions main/aperture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,32 @@ export const stopRecording = async () => {
}
};

export const stopRecordingWithNoEdit = async () => {
// Ensure we only stop recording once
if (!past) {
return;
}

console.log(`Stopped recording after ${(Date.now() - past) / 1000}s`);
past = undefined;

try {
await aperture.stopRecording();
} catch (error) {
track('recording/quit/error');
showError(error as any, {title: 'Recording error', plugin: undefined});
cleanup();
return;
}

try {
cleanup();
} finally {
track('recording/quit');
stopCurrentRecording(recordingName);
}
};

export const pauseRecording = async () => {
// Ensure we only pause if there's a recording in progress and if it's currently not paused
const isPaused = await aperture.isPaused();
Expand Down
13 changes: 11 additions & 2 deletions main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import {setupRemoteStates} from './remote-states';
import {setUpExportsListeners} from './export';
import {windowManager} from './windows/manager';
import {setupProtocol} from './utils/protocol';
import {stopRecordingWithNoEdit} from './aperture';

const prepareNext = require('electron-next');

const filesToOpen: string[] = [];

let onExitCleanupComplete = false;

app.commandLine.appendSwitch('--enable-features', 'OverlayScrollbar');

app.on('open-file', (event, path) => {
Expand Down Expand Up @@ -133,6 +136,12 @@ app.on('will-finish-launching', () => {
});
});

app.on('quit', () => {
cleanPastRecordings();
app.on('before-quit', async (event: any) => {
if (!onExitCleanupComplete) {
event.preventDefault();
await stopRecordingWithNoEdit();
cleanPastRecordings();
onExitCleanupComplete = true;
app.quit();
}
});

0 comments on commit 52bb766

Please sign in to comment.