-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FileImageGenerator): added generic app icon and folder icon extr…
…actor on macos
- Loading branch information
1 parent
c73138a
commit 5883511
Showing
18 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { AssetPathResolver } from "@Core/AssetPathResolver"; | ||
import type { FileSystemUtility } from "@Core/FileSystemUtility"; | ||
import type { App } from "electron"; | ||
import { join } from "path"; | ||
import type { FileIconExtractor } from "./FileIconExtractor"; | ||
|
||
export class MacOsFolderIconExtractor implements FileIconExtractor { | ||
private readonly folderPaths: Record<string, string>; | ||
|
||
public constructor( | ||
private readonly assetPathResolver: AssetPathResolver, | ||
private readonly fileSystemUtility: FileSystemUtility, | ||
app: App, | ||
) { | ||
const homeFolderPath = app.getPath("home"); | ||
|
||
this.folderPaths = { | ||
[homeFolderPath]: "HomeFolderIcon.png", | ||
[join(homeFolderPath, "Applications")]: "ApplicationsFolderIcon.png", | ||
[join(homeFolderPath, "Desktop")]: "DesktopFolderIcon.png", | ||
[join(homeFolderPath, "Documents")]: "DocumentsFolderIcon.png", | ||
[join(homeFolderPath, "Downloads")]: "DownloadsFolderIcon.png", | ||
[join(homeFolderPath, "Library")]: "LibraryFolderIcon.png", | ||
[join(homeFolderPath, "Movies")]: "MovieFolderIcon.png", | ||
[join(homeFolderPath, "Music")]: "MusicFolderIcon.png", | ||
[join(homeFolderPath, "Pictures")]: "PicturesFolderIcon.png", | ||
[join(homeFolderPath, "Public")]: "PublicFolderIcon.png", | ||
[join("/", "Applications")]: "ApplicationsFolderIcon.png", | ||
[join("/", "Library")]: "LibraryFolderIcon.png", | ||
[join("/", "System", "Applications")]: "ApplicationsFolderIcon.png", | ||
["/Users"]: "UsersFolderIcon.png", | ||
["/System"]: "SystemFolderIcon.png", | ||
["/System/Library"]: "LibraryFolderIcon.png", | ||
}; | ||
} | ||
|
||
public machtes(filePath: string) { | ||
return ( | ||
Object.keys(this.folderPaths).some((f) => f === filePath) || | ||
(this.fileSystemUtility.isDirectory(filePath) && !filePath.endsWith(".app")) | ||
); | ||
} | ||
|
||
public async extractFileIcon(filePath: string) { | ||
const assetFileName = Object.keys(this.folderPaths).includes(filePath) | ||
? this.folderPaths[filePath] | ||
: "GenericFolderIcon.png"; | ||
|
||
return { | ||
url: `file://${this.assetPathResolver.getModuleAssetPath("FileImageGenerator", assetFileName)}`, | ||
}; | ||
} | ||
} |