Fix env save dialog fallback
Some checks failed
Build Windows App / build-windows (push) Has been cancelled
Some checks failed
Build Windows App / build-windows (push) Has been cancelled
This commit is contained in:
25
src/App.tsx
25
src/App.tsx
@@ -473,6 +473,20 @@ function openFileWithBrowserPicker(): Promise<{ name: string; content: string }
|
||||
});
|
||||
}
|
||||
|
||||
function saveFileWithBrowserDownload(content: string) {
|
||||
const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = url;
|
||||
anchor.download = ".env";
|
||||
anchor.style.display = "none";
|
||||
|
||||
document.body.append(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [input, setInput] = useState("");
|
||||
const [loadedPath, setLoadedPath] = useState<string | null>(null);
|
||||
@@ -534,7 +548,16 @@ export default function App() {
|
||||
}
|
||||
|
||||
async function saveFile() {
|
||||
await window.envHelper?.saveFile(result.output);
|
||||
try {
|
||||
if (window.envHelper?.saveFile) {
|
||||
await window.envHelper.saveFile(result.output);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Native save dialog failed, falling back to browser download.", error);
|
||||
}
|
||||
|
||||
saveFileWithBrowserDownload(result.output);
|
||||
}
|
||||
|
||||
async function copyOutput() {
|
||||
|
||||
Reference in New Issue
Block a user