unsaved changes warning and loading project in hud
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { BsRecordCircle } from "react-icons/bs";
|
||||
import { FaRegStopCircle } from "react-icons/fa";
|
||||
import { FaFolderMinus } from "react-icons/fa6";
|
||||
import { FaFolderOpen } from "react-icons/fa6";
|
||||
import { FiMinus, FiX } from "react-icons/fi";
|
||||
import { MdMic, MdMicOff, MdMonitor, MdVolumeOff, MdVolumeUp } from "react-icons/md";
|
||||
import { MdMic, MdMicOff, MdMonitor, MdVideoFile, MdVolumeOff, MdVolumeUp } from "react-icons/md";
|
||||
import { RxDragHandleDots2 } from "react-icons/rx";
|
||||
import { useAudioLevelMeter } from "../../hooks/useAudioLevelMeter";
|
||||
import { useMicrophoneDevices } from "../../hooks/useMicrophoneDevices";
|
||||
@@ -107,6 +107,12 @@ export function LaunchWindow() {
|
||||
}
|
||||
};
|
||||
|
||||
const openProjectFile = async () => {
|
||||
const result = await window.electronAPI.loadProjectFile();
|
||||
if (result.canceled || !result.success) return;
|
||||
await window.electronAPI.switchToEditor();
|
||||
};
|
||||
|
||||
const sendHudOverlayHide = () => {
|
||||
if (window.electronAPI && window.electronAPI.hudOverlayHide) {
|
||||
window.electronAPI.hudOverlayHide();
|
||||
@@ -230,14 +236,24 @@ export function LaunchWindow() {
|
||||
)}
|
||||
</button>
|
||||
|
||||
{/* Open file */}
|
||||
{/* Open video file */}
|
||||
<button
|
||||
className={`${styles.hudIconBtn} ${styles.electronNoDrag}`}
|
||||
onClick={openVideoFile}
|
||||
disabled={recording}
|
||||
title="Open video file"
|
||||
>
|
||||
<FaFolderMinus size={14} className="text-white/60" />
|
||||
<MdVideoFile size={14} className="text-white/60" />
|
||||
</button>
|
||||
|
||||
{/* Open project */}
|
||||
<button
|
||||
className={`${styles.hudIconBtn} ${styles.electronNoDrag}`}
|
||||
onClick={openProjectFile}
|
||||
disabled={recording}
|
||||
title="Open project"
|
||||
>
|
||||
<FaFolderOpen size={14} className="text-white/60" />
|
||||
</button>
|
||||
|
||||
{/* Window controls */}
|
||||
|
||||
@@ -346,20 +346,19 @@ export default function VideoEditor() {
|
||||
],
|
||||
);
|
||||
|
||||
// Sync unsaved changes state to main process for close dialog
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
if (!hasUnsavedChanges) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.returnValue = "";
|
||||
};
|
||||
|
||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
window.electronAPI.setHasUnsavedChanges(hasUnsavedChanges);
|
||||
}, [hasUnsavedChanges]);
|
||||
|
||||
// Handle save request from main process before close
|
||||
useEffect(() => {
|
||||
const cleanup = window.electronAPI.onRequestSaveBeforeClose(async () => {
|
||||
await saveProject(false);
|
||||
});
|
||||
return () => cleanup();
|
||||
}, [saveProject]);
|
||||
|
||||
const handleSaveProject = useCallback(async () => {
|
||||
await saveProject(false);
|
||||
}, [saveProject]);
|
||||
|
||||
Reference in New Issue
Block a user