Skip to content

Commit

Permalink
wulkano#129 Allow pausing when recording
Browse files Browse the repository at this point in the history
  • Loading branch information
thethomasz committed Aug 29, 2022
1 parent 8298b6a commit cffa7b9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
42 changes: 40 additions & 2 deletions main/aperture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {windowManager} from './windows/manager';
import {setRecordingTray, disableTray, resetTray} from './tray';
import {setRecordingTray, setPausedTray, disableTray, resetTray} from './tray';
import {setCropperShortcutAction} from './global-accelerators';
import {settings} from './common/settings';
import {track} from './common/analytics';
Expand Down Expand Up @@ -162,7 +162,7 @@ export const startRecording = async (options: StartRecordingOptions) => {

console.log(`Started recording after ${startTime}s`);
windowManager.cropper?.setRecording();
setRecordingTray(stopRecording);
setRecordingTray(stopRecording, pauseRecording);
setCropperShortcutAction(stopRecording);
past = Date.now();

Expand Down Expand Up @@ -216,3 +216,41 @@ export const stopRecording = async () => {
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();
if (!past || isPaused) {
return;
}

try {
await aperture.pause();
setPausedTray(resumeRecording);
track('recording/paused');
console.log(`Paused recording after ${(Date.now() - past) / 1000}s`);
} catch (error) {
track('recording/paused/error');
showError(error as any, {title: 'Recording error', plugin: undefined});
cleanup();
}
};

export const resumeRecording = async () => {
// Ensure we only resume if there's a recording in progress and if it's currently paused
const isPaused = await aperture.isPaused();
if (!past || !isPaused) {
return;
}

try {
await aperture.resume();
setRecordingTray(stopRecording, pauseRecording);
track('recording/resumed');
console.log(`Resume recording after ${(Date.now() - past) / 1000}s`);
} catch (error) {
track('recording/resumed/error');
showError(error as any, {title: 'Recording error', plugin: undefined});
cleanup();
}
};
12 changes: 11 additions & 1 deletion main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ export const resetTray = () => {
tray.on('right-click', openContextMenu);
};

export const setRecordingTray = (stopRecording: () => void) => {
export const setRecordingTray = (stopRecording: () => void, pauseRecording: () => void) => {
animateIcon();

// TODO: figure out why this is marked as missing. It's defined properly in the electron.d.ts file
tray.once('click', stopRecording);
tray.once('right-click', pauseRecording);
};

export const setPausedTray = (resumeRecording: () => void) => {
if (trayAnimation) {
clearTimeout(trayAnimation);
}

tray.setImage(path.join(__dirname, '..', 'static', 'menubarDefaultTemplate.png'));
tray.once('right-click', resumeRecording);
};

const animateIcon = async () => new Promise<void>(resolve => {
Expand Down

0 comments on commit cffa7b9

Please sign in to comment.