Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Type setup permissions and extract deleteTrackLane

Richie McIlroyff8df5e1a842
diff --git a/apps/desktop/src/routes/(window-chrome)/setup.tsx b/apps/desktop/src/routes/(window-chrome)/setup.tsx
index 121735857..8570df084 100644
--- a/apps/desktop/src/routes/(window-chrome)/setup.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/setup.tsx
@@ -29,7 +29,15 @@ function isPermitted(status?: OSPermissionStatus): boolean {
return status === "granted" || status === "notNeeded";
}
-const permissions = [
+type SetupPermission = {
+ name: string;
+ key: OSPermission;
+ description: string;
+ requiresManualGrant: boolean;
+ optional?: boolean;
+};
+
+const permissions: readonly SetupPermission[] = [
{
name: "Screen Recording",
key: "screenRecording" as const,
@@ -59,7 +67,7 @@ const permissions = [
requiresManualGrant: false,
optional: true,
},
-] as const;
+];
export default function () {
const [initialCheck, setInitialCheck] = createSignal(true);
diff --git a/apps/desktop/src/routes/editor/Timeline/index.tsx b/apps/desktop/src/routes/editor/Timeline/index.tsx
index 063e9b2a1..904ca1a02 100644
--- a/apps/desktop/src/routes/editor/Timeline/index.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/index.tsx
@@ -21,6 +21,8 @@ import "./styles.css";
import Tooltip from "~/components/Tooltip";
import { commands } from "~/utils/tauri";
import { FPS, type TimelineTrackType, useEditorContext } from "../context";
+import type { MaskSegment } from "../masks";
+import type { TextSegment } from "../text";
import { getTrackRowsWithCount, getUsedTrackCount } from "../timelineTracks";
import { formatTime } from "../utils";
import { ClipTrack } from "./ClipTrack";
@@ -83,6 +85,19 @@ const trackDefinitions: TrackDefinition[] = [
},
];
+function deleteTrackLane<T extends { track?: number }>(
+ segments: T[],
+ laneIndex: number,
+) {
+ return segments
+ .filter((segment) => (segment.track ?? 0) !== laneIndex)
+ .map<T>((segment) => {
+ const track = segment.track ?? 0;
+ if (track <= laneIndex) return segment;
+ return { ...segment, track: track - 1 };
+ });
+}
+
export function Timeline() {
const {
project,
@@ -190,19 +205,24 @@ export function Timeline() {
function handleDeleteTrackLane(type: "text" | "mask", laneIndex: number) {
const resumeHistory = projectHistory.pause();
const currentTrackCount = trackState()[type];
- const sourceSegments =
+ const nextTextSegments =
type === "text"
- ? (project.timeline?.textSegments ?? [])
- : (project.timeline?.maskSegments ?? []);
- const nextSegments = sourceSegments
- .filter((segment) => (segment.track ?? 0) !== laneIndex)
- .map((segment) => {
- const track = segment.track ?? 0;
- if (track <= laneIndex) return segment;
- return { ...segment, track: track - 1 };
- });
+ ? deleteTrackLane<TextSegment>(
+ project.timeline?.textSegments ?? [],
+ laneIndex,
+ )
+ : null;
+ const nextMaskSegments =
+ type === "mask"
+ ? deleteTrackLane<MaskSegment>(
+ project.timeline?.maskSegments ?? [],
+ laneIndex,
+ )
+ : null;
const nextTrackCount = Math.max(
- getUsedTrackCount(nextSegments),
+ type === "text"
+ ? getUsedTrackCount(nextTextSegments ?? [])
+ : getUsedTrackCount(nextMaskSegments ?? []),
currentTrackCount - 1,
0,
);
@@ -217,10 +237,10 @@ export function Timeline() {
const timeline = project.timeline;
if (!timeline) return;
- if (type === "text") {
- timeline.textSegments = nextSegments;
- } else {
- timeline.maskSegments = nextSegments;
+ if (type === "text" && nextTextSegments) {
+ timeline.textSegments = nextTextSegments;
+ } else if (nextMaskSegments) {
+ timeline.maskSegments = nextMaskSegments;
}
}),
);