1
- import { ActionPanel , Form , Action , showToast , Toast , popToRoot , closeMainWindow } from "@raycast/api" ;
1
+ import {
2
+ ActionPanel ,
3
+ Form ,
4
+ Action ,
5
+ showToast ,
6
+ Toast ,
7
+ popToRoot ,
8
+ closeMainWindow ,
9
+ getSelectedFinderItems ,
10
+ } from "@raycast/api" ;
11
+ import { useEffect , useState } from "react" ;
2
12
import fs from "fs" ;
3
13
import path from "path" ;
4
14
import { replaceFolderIcon } from "./utils/replaceFolderIcon" ;
5
15
6
16
export default function Command ( ) {
17
+ const [ selectedFolder , setSelectedFolder ] = useState < string > ( "" ) ;
18
+ const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
19
+ useEffect ( ( ) => {
20
+ async function getSelectedFolder ( ) {
21
+ try {
22
+ const items = await getSelectedFinderItems ( ) ;
23
+ if ( items . length === 1 && items [ 0 ] . path && fs . lstatSync ( items [ 0 ] . path ) . isDirectory ( ) ) {
24
+ setSelectedFolder ( items [ 0 ] . path ) ;
25
+ }
26
+ } catch ( error ) {
27
+ return ;
28
+ } finally {
29
+ setIsLoading ( false ) ;
30
+ }
31
+ }
32
+ getSelectedFolder ( ) ;
33
+ } , [ ] ) ;
34
+
7
35
return (
8
36
< Form
37
+ isLoading = { isLoading }
9
38
actions = {
10
39
< ActionPanel >
11
40
< Action . SubmitForm
@@ -30,12 +59,12 @@ export default function Command() {
30
59
if ( values . image . length === 0 ) {
31
60
showToast ( {
32
61
style : Toast . Style . Failure ,
33
- title : "Please select an image file." ,
62
+ title : "Please select a PNG image file." ,
34
63
} ) ;
35
64
return ;
36
65
}
37
66
const file = values . image [ 0 ] ;
38
- const allowedExtensions = [ ".png" , ".jpg" , ".jpeg" ] ;
67
+ const allowedExtensions = [ ".png" ] ;
39
68
40
69
if ( ! fs . existsSync ( file ) || fs . lstatSync ( file ) . isDirectory ( ) ) {
41
70
showToast ( {
@@ -49,7 +78,7 @@ export default function Command() {
49
78
if ( ! allowedExtensions . includes ( fileExtension ) ) {
50
79
showToast ( {
51
80
style : Toast . Style . Failure ,
52
- title : "Images must be in one of the following formats: .png, .jpg, .jpeg " ,
81
+ title : "Images must be in PNG format. " ,
53
82
} ) ;
54
83
return ;
55
84
}
@@ -69,6 +98,8 @@ export default function Command() {
69
98
< Form . FilePicker
70
99
id = "folder"
71
100
title = "Select a Folder"
101
+ value = { selectedFolder ? [ selectedFolder ] : [ ] }
102
+ onChange = { ( values ) => setSelectedFolder ( values [ 0 ] || "" ) }
72
103
allowMultipleSelection = { false }
73
104
canChooseDirectories
74
105
canChooseFiles = { false }
@@ -78,7 +109,7 @@ export default function Command() {
78
109
allowMultipleSelection = { false }
79
110
canChooseDirectories = { false }
80
111
canChooseFiles
81
- title = "Select an Image"
112
+ title = "Select a PNG Image"
82
113
/>
83
114
</ Form >
84
115
) ;
0 commit comments