11"use client" ;
22
33import { useEffect , useRef , useState } from "react" ;
4- import { Folder } from "@/lib/types" ;
4+ import {
5+ OpenFileDialogConfig ,
6+ Folder ,
7+ SaveFileDialogConfig ,
8+ } from "@/lib/types" ;
59import { getPlatform } from "../platform-api/platform-checker" ;
610import { PlatformEnum } from "../platform-api/available-platforms" ;
711import { CapacitorAPI } from "../platform-api/capacitor/capacitor-api" ;
@@ -30,12 +34,32 @@ export function useFileSystem() {
3034 }
3135 } , [ ] ) ;
3236
33- async function openFolder ( ) : Promise < Folder | undefined > {
37+ async function showOpenFileDialog (
38+ config ?: OpenFileDialogConfig ,
39+ ) : Promise < File [ ] > {
3440 if ( platformApi . current === undefined ) {
3541 throw new Error ( "Platform API not initialized" ) ;
3642 }
3743
38- return await platformApi . current . openFolder ( ) ;
44+ return await platformApi . current . showOpenFileDialog ( config ) ;
45+ }
46+
47+ async function showSaveFileDialog (
48+ config ?: SaveFileDialogConfig ,
49+ ) : Promise < string | undefined > {
50+ if ( platformApi . current === undefined ) {
51+ throw new Error ( "Platform API not initialized" ) ;
52+ }
53+
54+ return await platformApi . current . showSaveFileDialog ( config ) ;
55+ }
56+
57+ async function openFolder ( uri : string ) : Promise < Folder | undefined > {
58+ if ( platformApi . current === undefined ) {
59+ throw new Error ( "Platform API not initialized" ) ;
60+ }
61+
62+ return await platformApi . current . openFolder ( uri ) ;
3963 }
4064
4165 async function saveFolder ( folder : Folder , uriPrefix : string ) {
@@ -46,12 +70,12 @@ export function useFileSystem() {
4670 platformApi . current . saveFolder ( folder , uriPrefix ) ;
4771 }
4872
49- async function openFile ( ) : Promise < File | undefined > {
73+ async function openFile ( uri : string ) : Promise < File | undefined > {
5074 if ( platformApi . current === undefined ) {
5175 throw new Error ( "Platform API not initialized" ) ;
5276 }
5377
54- return platformApi . current . openFile ( ) ;
78+ return platformApi . current . openFile ( uri ) ;
5579 }
5680
5781 async function writeFile ( file : File , uri : string ) {
@@ -64,6 +88,8 @@ export function useFileSystem() {
6488
6589 return {
6690 projectPath,
91+ showOpenFileDialog,
92+ showSaveFileDialog,
6793 openFolder,
6894 saveFolder,
6995 openFile,
0 commit comments