Skip to content

Commit f14e7cb

Browse files
Update custom-folder extension (raycast#17785)
* Update custom-folder extension * Update custom-folder extension * Update CHANGELOG.md and optimise images --------- Co-authored-by: raycastbot <[email protected]>
1 parent 1619d1d commit f14e7cb

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

extensions/custom-folder/CHANGELOG.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
# Custom folder Changelog
22

3+
## [Enhancement] - 2025-03-12
4+
5+
- Added the ability to retrieve the selected folder when Finder is the frontmost application.
6+
37
## [Feat Custom icon from custom image] - 2025-03-11
8+
49
- Added a new command to change the folder icon to a custom image.
510
- Added a new command to reset the folder icon to the default.
611

7-
812
## [Feat Create custom icons from emojis] - 2024-11-16
13+
914
- Added the ability to create custom icons from emojis.
1015
- Renamed `Output path` to `Download path`.
1116

1217
## [Fix First icon swap] - 2024-08-28
18+
1319
- Fixed the issue with the first icon swap.
1420
- Now handles spaces in paths.
1521

1622
## [Feat Easily apply the custom icon] - 2024-08-25
23+
1724
- Added the ability to easily apply the new custom icon to a target folder.
1825

19-
## [Feat Image shades ] - 2024-08-05
26+
## [Feat Image shades] - 2024-08-05
27+
2028
- Added optional toggle - shading effect on the image, switching between a filled mask and shaded tones.
2129

2230
## [Initial Version] - 2023-12-16
23-
- Custom folder extension
31+
32+
- Custom folder extension

extensions/custom-folder/src/replaceFolderIcon.tsx

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
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";
212
import fs from "fs";
313
import path from "path";
414
import { replaceFolderIcon } from "./utils/replaceFolderIcon";
515

616
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+
735
return (
836
<Form
37+
isLoading={isLoading}
938
actions={
1039
<ActionPanel>
1140
<Action.SubmitForm
@@ -30,12 +59,12 @@ export default function Command() {
3059
if (values.image.length === 0) {
3160
showToast({
3261
style: Toast.Style.Failure,
33-
title: "Please select an image file.",
62+
title: "Please select a PNG image file.",
3463
});
3564
return;
3665
}
3766
const file = values.image[0];
38-
const allowedExtensions = [".png", ".jpg", ".jpeg"];
67+
const allowedExtensions = [".png"];
3968

4069
if (!fs.existsSync(file) || fs.lstatSync(file).isDirectory()) {
4170
showToast({
@@ -49,7 +78,7 @@ export default function Command() {
4978
if (!allowedExtensions.includes(fileExtension)) {
5079
showToast({
5180
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.",
5382
});
5483
return;
5584
}
@@ -69,6 +98,8 @@ export default function Command() {
6998
<Form.FilePicker
7099
id="folder"
71100
title="Select a Folder"
101+
value={selectedFolder ? [selectedFolder] : []}
102+
onChange={(values) => setSelectedFolder(values[0] || "")}
72103
allowMultipleSelection={false}
73104
canChooseDirectories
74105
canChooseFiles={false}
@@ -78,7 +109,7 @@ export default function Command() {
78109
allowMultipleSelection={false}
79110
canChooseDirectories={false}
80111
canChooseFiles
81-
title="Select an Image"
112+
title="Select a PNG Image"
82113
/>
83114
</Form>
84115
);

extensions/custom-folder/src/resetFolderIcon.tsx

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
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";
211
import fs from "fs";
12+
import { useEffect, useState } from "react";
313
import { resetFolderIcon } from "./utils/resetFolderIcon";
414

515
export default function Command() {
16+
const [selectedFolder, setSelectedFolder] = useState<string>("");
17+
const [isLoading, setIsLoading] = useState<boolean>(true);
18+
useEffect(() => {
19+
async function getSelectedFolder() {
20+
try {
21+
const items = await getSelectedFinderItems();
22+
if (items.length === 1 && items[0].path && fs.lstatSync(items[0].path).isDirectory()) {
23+
setSelectedFolder(items[0].path);
24+
}
25+
} catch (error) {
26+
return;
27+
} finally {
28+
setIsLoading(false);
29+
}
30+
}
31+
getSelectedFolder();
32+
}, []);
33+
634
return (
735
<Form
36+
isLoading={isLoading}
837
actions={
938
<ActionPanel>
1039
<Action.SubmitForm
@@ -41,6 +70,8 @@ export default function Command() {
4170
<Form.FilePicker
4271
id="folder"
4372
title="Select a Folder"
73+
value={selectedFolder ? [selectedFolder] : []}
74+
onChange={(values) => setSelectedFolder(values[0] || "")}
4475
allowMultipleSelection={false}
4576
canChooseDirectories
4677
canChooseFiles={false}

0 commit comments

Comments
 (0)