diff --git a/extensions/custom-folder/CHANGELOG.md b/extensions/custom-folder/CHANGELOG.md index 397857aad492..3c727a984840 100644 --- a/extensions/custom-folder/CHANGELOG.md +++ b/extensions/custom-folder/CHANGELOG.md @@ -1,5 +1,9 @@ # Custom folder Changelog +## [Fix First icon swap] - 2024-08-28 +- Fixed the issue with the first icon swap. +- Now handles spaces in paths. + ## [Feat Easily apply the custom icon] - 2024-08-25 - Added the ability to easily apply the new custom icon to a target folder. diff --git a/extensions/custom-folder/src/result.tsx b/extensions/custom-folder/src/result.tsx index 3800739ed7ba..d7c3ecb6c50e 100644 --- a/extensions/custom-folder/src/result.tsx +++ b/extensions/custom-folder/src/result.tsx @@ -5,7 +5,6 @@ import { useEffect, useState } from "react"; import { base64ToFile } from "./utils/saveFile"; import path from "path"; import { ReplaceAction } from "./replaceAction"; -import { sanitizePngFilePath } from "./utils/verifications"; export default function Result({ formValues }: { formValues: FolderForm }) { const [isLoading, setIsLoading] = useState(false); @@ -39,7 +38,7 @@ export default function Result({ formValues }: { formValues: FolderForm }) { }); return; } - base64ToFile(imageResult?.baseImage, sanitizePngFilePath(output))?.then(async (res) => { + base64ToFile(imageResult?.baseImage, output)?.then(async (res) => { if (res === "success") { await showToast({ style: Toast.Style.Success, @@ -98,7 +97,7 @@ export default function Result({ formValues }: { formValues: FolderForm }) { {formValues.targetFolderPath && formValues.targetFolderPath.length > 0 && ( saveFile(`${tmpDirectory}/${imageResult?.name}`, "applied")} /> diff --git a/extensions/custom-folder/src/utils/replaceIconScript.ts b/extensions/custom-folder/src/utils/replaceIconScript.ts index 1731f047e693..11027d9811bd 100644 --- a/extensions/custom-folder/src/utils/replaceIconScript.ts +++ b/extensions/custom-folder/src/utils/replaceIconScript.ts @@ -2,49 +2,41 @@ import { checkPathIsDirectory, sanitizeDirectoryPath } from "./verifications"; export const replaceIconScript = (sanitizedIconPath: string, targetPath: string) => { const sanitizedTargetPath = sanitizeDirectoryPath(targetPath); - const isDirValid = checkPathIsDirectory(sanitizedTargetPath); + const isDirValid = checkPathIsDirectory(targetPath); if (isDirValid) { return ` bash -c #!/bin/sh - # Sets a custom icon to a directory - # Usage setIcon.sh /path/to/iconImage /path/to/targetFolder - iconSource=${sanitizedIconPath} - iconDestination=${sanitizedTargetPath} - icon=/tmp/$(basename $iconSource) - rsrc=/tmp/icon.rsrc - echo $icon - echo $iconSource + iconDestination="${sanitizedTargetPath}" + iconSource="${sanitizedIconPath}" + icon="/tmp/$(basename "$iconSource")" + rsrc="/tmp/icon.rsrc" # Create icon from the iconSource - cp $iconSource $icon + cp "$iconSource" "$icon" # Add icon to image file, meaning use itself as the icon - sips -i $icon + sips -i "$icon" - if [ -d $iconDestination ]; then - # Destination is a directory - # If the Icon? file already exists - delete it by updating the item via applescript, a simple rm wouldn't trigger a render refresh - if [ -f $iconDestination/Icon? ]; then - rm $iconDestination/Icon? - osascript -e 'tell application "Finder" to update item POSIX file "'"$iconDestination"'"' + if [ -d "$iconDestination" ]; then + if [ -f "$iconDestination"/$'Icon\r' ]; then + rm "$iconDestination"/$'Icon\r' fi + osascript -e 'tell application "Finder" to update item POSIX file "'"$iconDestination"'"' # Take that icon and put it into a rsrc file - DeRez -only icns $icon >$rsrc + DeRez -only icns "$icon" >"$rsrc" - # Apply the rsrc file to - SetFile -a C $iconDestination + # Apply the rsrc file to the destination + SetFile -a C "$iconDestination" - touch $iconDestination/$'Icon\r' - Rez -append $rsrc -o $iconDestination/Icon? - SetFile -a V $iconDestination/Icon? + touch "$iconDestination"/$'Icon\r' + Rez -append "$rsrc" -o "$iconDestination"/$'Icon\r' + SetFile -a V "$iconDestination"/$'Icon\r' fi - echo $iconDestination - - rm $rsrc $icon + rm "$rsrc" "$icon" `; } return undefined; diff --git a/extensions/custom-folder/src/utils/verifications.tsx b/extensions/custom-folder/src/utils/verifications.tsx index 82c892869545..5c56876226dd 100644 --- a/extensions/custom-folder/src/utils/verifications.tsx +++ b/extensions/custom-folder/src/utils/verifications.tsx @@ -43,5 +43,5 @@ export const sanitizePngFilePath = (filePath: string): string => { }; export const sanitizeDirectoryPath = (directoryPath: string): string => { - return directoryPath.replace(/[^a-zA-Z0-9/_-]/g, ""); + return directoryPath.replace(/[^a-zA-Z0-9/_ -]/g, ""); };