Skip to content

Commit

Permalink
keybind for adding bookmarks to current recording
Browse files Browse the repository at this point in the history
F2 by default, idk if thats a good bind, wuteva u can change it yaself bud
  • Loading branch information
IRHM committed Dec 18, 2023
1 parent 855dc0e commit 26552b1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const DEFAULT_SETTINGS = {
},
key: {
startStopRecording: "F9",
startStopRecordingRegion: "F10"
startStopRecordingRegion: "F10",
addBookmark: "F2"
}
} as Settings;
10 changes: 9 additions & 1 deletion src/libs/recorder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ArgumentBuilder, { type CustomRegion, type Arguments } from "./argumentBu
import RecordingsManager from "./recordingsManager";
import Notifications from "./../helpers/notifications";
import { store } from "@/app/store";
import { isRecording } from "./recorderSlice";
import { addBookmarkToRecording, isRecording } from "./recorderSlice";
import { ipcRenderer } from "electron";
import { logger } from "../logger";

Expand All @@ -17,6 +17,14 @@ ipcRenderer.on("startStopRecordingRegion-pressed", async () => {
await Recorder.auto(b);
});

ipcRenderer.on("addBookmark-pressed", async () => {
if (!store.getState().recorder.isRecording) {
console.log("can't add bookmark when not recording");
return;
}
store.dispatch(addBookmarkToRecording());
});

export default class Recorder {
private static readonly ffmpeg = new FFmpeg();
private static args: Arguments;
Expand Down
21 changes: 19 additions & 2 deletions src/libs/recorder/recorderSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ interface RecordingState {
* Recording time elapsed in seconds.
*/
timeElapsed: number;

/**
* Bookmarks added whilst recording,
* added to final video object before adding
* to appropriate video json file on stop.
*/
bookmarks: number[];
}

const recorderSlice = createSlice({
name: "recorder",
initialState: { isRecording: false, timeElapsed: 0 } as RecordingState,
initialState: { isRecording: false, timeElapsed: 0, bookmarks: [] } as RecordingState,
reducers: {
isRecording(state, action: PayloadAction<boolean>) {
// Reset bookmarks when starting new recording.
if (action.payload) {
state.bookmarks = [];
}
state.isRecording = action.payload;
},
/**
Expand All @@ -27,10 +38,16 @@ const recorderSlice = createSlice({
*/
resetElapsed(state) {
state.timeElapsed = 0;
},
/**
* Add bookmark to the currently recording video (at current `timeElapsed`).
*/
addBookmarkToRecording(state) {
state.bookmarks.push(state.timeElapsed);
}
}
});

export const { isRecording, incrementElapsed, resetElapsed } = recorderSlice.actions;
export const { isRecording, incrementElapsed, resetElapsed, addBookmarkToRecording } = recorderSlice.actions;

export default recorderSlice.reducer;
1 change: 1 addition & 0 deletions src/libs/recorder/recordingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class RecordingsManager {
recording.fileSize = fs.statSync(videoPath).size;
recording.time = Date.now();
recording.isClip = isClip;
recording.bookmarks = store.getState().recorder?.bookmarks;

// Get video info from ffprobe
ffprobe
Expand Down
11 changes: 10 additions & 1 deletion src/settings/keybind/KeyBindings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type RootState } from "@/app/store";
import { useDispatch, useSelector } from "react-redux";
import NamedContainer from "../../common/NamedContainer";
import { setStartStopRecording, setStartStopRecordingRegion } from "../settingsSlice";
import { setAddBookmark, setStartStopRecording, setStartStopRecordingRegion } from "../settingsSlice";
import KeyBindButton from "./KeyBindButton";

export default function KeyBindings() {
Expand All @@ -28,6 +28,15 @@ export default function KeyBindings() {
}}
/>
</NamedContainer>
<NamedContainer title="Add Bookmark To Recording">
<KeyBindButton
name="addBookmark"
bind={state.addBookmark}
onUpdate={(newBind) => {
dispatch(setAddBookmark(newBind));
}}
/>
</NamedContainer>
</>
);
}
6 changes: 5 additions & 1 deletion src/settings/settingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ const settingsSlice = createSlice({
},
setStartStopRecordingRegion(state, action: PayloadAction<string>) {
state.key.startStopRecordingRegion = action.payload;
},
setAddBookmark(state, action: PayloadAction<string>) {
state.key.addBookmark = action.payload;
}
}
});
Expand All @@ -104,7 +107,8 @@ export const {
setSeperateAudioTracks,

setStartStopRecording,
setStartStopRecordingRegion
setStartStopRecordingRegion,
setAddBookmark
} = settingsSlice.actions;

export default settingsSlice.reducer;
1 change: 1 addition & 0 deletions src/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface RecordingSettings {
export interface KeyBindingSettings {
startStopRecording: string;
startStopRecordingRegion: string;
addBookmark: string;
}

export interface MonitorToRecord {
Expand Down

0 comments on commit 26552b1

Please sign in to comment.