Skip to content

Commit ff8df5e

Browse files
committed
Type setup permissions and extract deleteTrackLane
1 parent a49f2f8 commit ff8df5e

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

apps/desktop/src/routes/(window-chrome)/setup.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ function isPermitted(status?: OSPermissionStatus): boolean {
2929
return status === "granted" || status === "notNeeded";
3030
}
3131

32-
const permissions = [
32+
type SetupPermission = {
33+
name: string;
34+
key: OSPermission;
35+
description: string;
36+
requiresManualGrant: boolean;
37+
optional?: boolean;
38+
};
39+
40+
const permissions: readonly SetupPermission[] = [
3341
{
3442
name: "Screen Recording",
3543
key: "screenRecording" as const,
@@ -59,7 +67,7 @@ const permissions = [
5967
requiresManualGrant: false,
6068
optional: true,
6169
},
62-
] as const;
70+
];
6371

6472
export default function () {
6573
const [initialCheck, setInitialCheck] = createSignal(true);

apps/desktop/src/routes/editor/Timeline/index.tsx

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import "./styles.css";
2121
import Tooltip from "~/components/Tooltip";
2222
import { commands } from "~/utils/tauri";
2323
import { FPS, type TimelineTrackType, useEditorContext } from "../context";
24+
import type { MaskSegment } from "../masks";
25+
import type { TextSegment } from "../text";
2426
import { getTrackRowsWithCount, getUsedTrackCount } from "../timelineTracks";
2527
import { formatTime } from "../utils";
2628
import { ClipTrack } from "./ClipTrack";
@@ -83,6 +85,19 @@ const trackDefinitions: TrackDefinition[] = [
8385
},
8486
];
8587

88+
function deleteTrackLane<T extends { track?: number }>(
89+
segments: T[],
90+
laneIndex: number,
91+
) {
92+
return segments
93+
.filter((segment) => (segment.track ?? 0) !== laneIndex)
94+
.map<T>((segment) => {
95+
const track = segment.track ?? 0;
96+
if (track <= laneIndex) return segment;
97+
return { ...segment, track: track - 1 };
98+
});
99+
}
100+
86101
export function Timeline() {
87102
const {
88103
project,
@@ -190,19 +205,24 @@ export function Timeline() {
190205
function handleDeleteTrackLane(type: "text" | "mask", laneIndex: number) {
191206
const resumeHistory = projectHistory.pause();
192207
const currentTrackCount = trackState()[type];
193-
const sourceSegments =
208+
const nextTextSegments =
194209
type === "text"
195-
? (project.timeline?.textSegments ?? [])
196-
: (project.timeline?.maskSegments ?? []);
197-
const nextSegments = sourceSegments
198-
.filter((segment) => (segment.track ?? 0) !== laneIndex)
199-
.map((segment) => {
200-
const track = segment.track ?? 0;
201-
if (track <= laneIndex) return segment;
202-
return { ...segment, track: track - 1 };
203-
});
210+
? deleteTrackLane<TextSegment>(
211+
project.timeline?.textSegments ?? [],
212+
laneIndex,
213+
)
214+
: null;
215+
const nextMaskSegments =
216+
type === "mask"
217+
? deleteTrackLane<MaskSegment>(
218+
project.timeline?.maskSegments ?? [],
219+
laneIndex,
220+
)
221+
: null;
204222
const nextTrackCount = Math.max(
205-
getUsedTrackCount(nextSegments),
223+
type === "text"
224+
? getUsedTrackCount(nextTextSegments ?? [])
225+
: getUsedTrackCount(nextMaskSegments ?? []),
206226
currentTrackCount - 1,
207227
0,
208228
);
@@ -217,10 +237,10 @@ export function Timeline() {
217237
const timeline = project.timeline;
218238
if (!timeline) return;
219239

220-
if (type === "text") {
221-
timeline.textSegments = nextSegments;
222-
} else {
223-
timeline.maskSegments = nextSegments;
240+
if (type === "text" && nextTextSegments) {
241+
timeline.textSegments = nextTextSegments;
242+
} else if (nextMaskSegments) {
243+
timeline.maskSegments = nextMaskSegments;
224244
}
225245
}),
226246
);

0 commit comments

Comments
 (0)