forked from oliverschwendener/ueli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b13a617
commit 115f27c
Showing
11 changed files
with
193 additions
and
121 deletions.
There are no files selected for viewing
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
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
60 changes: 60 additions & 0 deletions
60
src/main/search-plugins/application-search-plugin/application-icon-helpers.ts
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,60 @@ | ||
import { Application } from "./application"; | ||
import { join } from "path"; | ||
import { createHash } from "crypto"; | ||
import { homedir } from "os"; | ||
import { convert } from "app2png"; | ||
import { Icon, generateIcons } from "windows-system-icon"; | ||
import { ApplicationIcon } from "./application-icon"; | ||
|
||
export const applicationIconLocation = join(homedir(), ".ueli", "application-icons"); | ||
|
||
export function getApplicationIconFilePath(application: Application): string { | ||
const fileHashName = createHash("md5").update(`${application.filePath}`).digest("hex"); | ||
return `${join(applicationIconLocation, fileHashName)}.png`; | ||
} | ||
|
||
export function getMacAppIcons(applications: Application[]): Promise<ApplicationIcon[]> { | ||
return new Promise((resolve, reject) => { | ||
const promises = applications.map((application) => { | ||
return convert(application.filePath, getApplicationIconFilePath(application)); | ||
}); | ||
|
||
Promise.all(promises) | ||
.then(() => { | ||
resolve(applications.map((application): ApplicationIcon => { | ||
return { | ||
filePathToPng: getApplicationIconFilePath(application), | ||
name: application.name, | ||
}; | ||
})); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
export function getWindowsAppIcons(applications: Application[]): Promise<ApplicationIcon[]> { | ||
return new Promise((resolve, reject) => { | ||
const icons = applications.map((application): Icon => { | ||
return { | ||
inputFilePath: application.filePath, | ||
outputFilePath: getApplicationIconFilePath(application), | ||
outputFormat: "Png", | ||
}; | ||
}); | ||
|
||
generateIcons(icons) | ||
.then(() => { | ||
resolve(applications.map((application): ApplicationIcon => { | ||
return { | ||
filePathToPng: getApplicationIconFilePath(application), | ||
name: application.name, | ||
}; | ||
})); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} |
44 changes: 41 additions & 3 deletions
44
src/main/search-plugins/application-search-plugin/application-icon-service.ts
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 |
---|---|---|
@@ -1,6 +1,44 @@ | ||
import { Application } from "./application"; | ||
import { join } from "path"; | ||
import { applicationIconLocation } from "./application-icon-helpers"; | ||
import { FileHelpers } from "../../helpers/file-helpers"; | ||
import { ApplicationIcon } from "./application-icon"; | ||
|
||
export interface ApplicationIconService { | ||
getIcon(applicaton: Application): Promise<string>; | ||
clearCache(): Promise<void>; | ||
export class ApplicationIconService { | ||
private readonly getAppIcons: (applications: Application[]) => Promise<ApplicationIcon[]>; | ||
|
||
constructor(getAppIcons: (applications: Application[]) => Promise<ApplicationIcon[]>) { | ||
this.getAppIcons = getAppIcons; | ||
} | ||
|
||
public getIcons(applications: Application[]): Promise<ApplicationIcon[]> { | ||
return new Promise((resolve, reject) => { | ||
this.getAppIcons(applications) | ||
.then((appIcons) => { | ||
resolve(appIcons); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
public clearCache(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
FileHelpers.getFilesFromFolder(applicationIconLocation) | ||
.then((files) => { | ||
const deletionPromises = files.map((file) => FileHelpers.deleteFile(join(applicationIconLocation, file))); | ||
Promise.all(deletionPromises) | ||
.then(() => { | ||
resolve(); | ||
}) | ||
.catch((deletionError) => { | ||
reject(deletionError); | ||
}); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/search-plugins/application-search-plugin/application-icon.ts
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,4 @@ | ||
export interface ApplicationIcon { | ||
name: string; | ||
filePathToPng: string; | ||
} |
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
63 changes: 0 additions & 63 deletions
63
src/main/search-plugins/application-search-plugin/mac-os-application-icon-service.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.